> For the complete documentation index, see [llms.txt](https://faction-os.gitbook.io/faction-os-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase17-session05-cli-notice-commands/implementation-notes.md).

# Implementation Notes

**Session ID**: `phase17-session05-cli-notice-commands` **Package**: apps/cli **Started**: 2026-06-05 21:38 **Last Updated**: 2026-06-05 21:48

***

## Session Progress

| Metric              | Value     |
| ------------------- | --------- |
| Tasks Completed     | 21 / 21   |
| Estimated Remaining | 0 minutes |
| Blockers            | 0         |

***

## Task Log

### 2026-06-05 - Session Start

**Environment verified**:

* [x] Prerequisites confirmed
* [x] Tools available
* [x] Directory structure ready
* [x] Package context resolved: apps/cli

***

### Task T001 - Review CLI command dispatch

**Started**: 2026-06-05 21:36 **Completed**: 2026-06-05 21:38 **Duration**: 2 minutes

**Notes**:

* `apps/cli/src/index.js` uses a top-level switch with `parseFlags` preserving positional args in `flags._`.
* Help text is a single template string with command and examples sections suitable for adding `notice`.

**Files Changed**:

* `.spec_system/specs/phase17-session05-cli-notice-commands/tasks.md` - marked setup review progress.
* `.spec_system/specs/phase17-session05-cli-notice-commands/implementation-notes.md` - initialized session notes.

***

### Task T002 - Audit CLI env and local helper patterns

**Started**: 2026-06-05 21:36 **Completed**: 2026-06-05 21:38 **Duration**: 2 minutes

**Notes**:

* `readServerUrl` already resolves `FACTIONOS_SERVER_URL`, lifecycle settings, local settings, and fallback `http://localhost:2468`.
* Existing helpers provide JSON settings reads and the default server port; auth token handling is implemented locally in request helpers.
* Local settings can provide safe display metadata when present, with fallback behavior owned by the notice client.

**Files Changed**:

* `.spec_system/specs/phase17-session05-cli-notice-commands/tasks.md` - marked setup review progress.
* `.spec_system/specs/phase17-session05-cli-notice-commands/implementation-notes.md` - logged setup findings.

***

### Task T003 - Audit CLI fake-server and captured-console test patterns

**Started**: 2026-06-05 21:36 **Completed**: 2026-06-05 21:38 **Duration**: 2 minutes

**Notes**:

* Existing tests use Vitest, local `http` fake servers, temporary `FACTIONOS_HOME`, explicit env restoration, and captured console helpers.
* Client helper tests assert method, URL, headers, retry/timeout behavior, compact errors, and redaction boundaries without requiring live services.

**Files Changed**:

* `.spec_system/specs/phase17-session05-cli-notice-commands/tasks.md` - marked setup review progress.
* `.spec_system/specs/phase17-session05-cli-notice-commands/implementation-notes.md` - logged setup findings.

***

### Task T004 - Create Notice Board HTTP client helper

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:43 **Duration**: 5 minutes

**Notes**:

* Added `noticeRequest` with normalized server URL resolution, bearer auth header injection, JSON request handling, bounded timeout, one retry with backoff for transient failures, and compact failure results.
* Added in-flight request keys for mutating calls so matching post/resolve operations cannot be double-submitted in the same CLI process.

**Files Changed**:

* `apps/cli/src/lib/noticeClient.js` - added Notice Board HTTP client helper and failure mapping.

**BQC Fixes**:

* Resource cleanup: request timeout destroys the request and resolves once.
* Duplicate action prevention: matching post and resolve requests use in-flight keys.
* Failure path completeness: invalid URL, unreachable, timeout, invalid JSON, large response, and non-2xx failures produce explicit compact errors.

***

### Task T005 - Define validators and error codes

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:43 **Duration**: 5 minutes

**Notes**:

* Added recovered notice type validation for `status`, `question`, `review`, `announcement`, `conflict`, `completion`, and `human`.
* Added command argument parsing for post, list filters, resolve ids, and context session ids with safe-id and length checks.
* Added user-facing error formatting that maps invalid input, auth, timeout, malformed response, and server reachability without raw payload output.

**Files Changed**:

* `apps/cli/src/lib/noticeClient.js` - added validators and compact error formatting.

**BQC Fixes**:

* Trust boundary enforcement: CLI inputs are checked before request construction.
* Error information boundaries: error formatter redacts URLs, paths, bearer tokens, and secret-like values.

***

### Task T006 - Implement session and author resolution

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:43 **Duration**: 5 minutes

**Notes**:

* Added metadata resolution from `FACTIONOS_SESSION_ID`, provider session env values, local settings, and privacy-safe `unknown` fallback.
* Added author display fallback from local/env display settings with `Agent-<session-prefix>` fallback.

**Files Changed**:

* `apps/cli/src/lib/noticeClient.js` - added notice metadata resolution helpers.

**BQC Fixes**:

* Error information boundaries: fallback author labels are deterministic and do not expose broad local machine details.
* Contract alignment: `authorSessionId` and `authorName` match the server route contract.

***

### Task T007 - Create notice command scaffold

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:43 **Duration**: 5 minutes

**Notes**:

* Added `runNotice` with `post`, `list`, `resolve`, `context`, and `help` subcommand routing.
* Added subcommand help text and centralized failure printing that sets `process.exitCode`.

**Files Changed**:

* `apps/cli/src/commands/notice.js` - added notice command group scaffold.

**BQC Fixes**:

* Failure path completeness: unknown and invalid subcommands return clear CLI errors.

***

### Task T009 - Wire notice command dispatch

**Started**: 2026-06-05 21:42 **Completed**: 2026-06-05 21:43 **Duration**: 1 minute

**Notes**:

* Added the `notice` command to the root CLI switch.
* Added top-level help command and example entries.

**Files Changed**:

* `apps/cli/src/index.js` - imported and dispatched `runNotice`, updated help text.

**BQC Fixes**:

* Contract alignment: dispatcher passes parsed flags and positional args through the existing `parseFlags` contract.

***

### Task T008 - Create Notice Board CLI test scaffold

**Started**: 2026-06-05 21:43 **Completed**: 2026-06-05 21:46 **Duration**: 3 minutes

**Notes**:

* Added isolated Vitest setup with temporary `FACTIONOS_HOME`, env restoration, captured console output, fake HTTP server, request recorder, JSON reader, and Notice Board fixtures.

**Files Changed**:

* `apps/cli/tests/noticeCommands.test.js` - added fake-server command test scaffold.

***

### Task T010 - Implement notice post

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Implemented `notice post <type> <message>` using canonical `POST /notice-board` body with `type`, `content`, `authorType: "agent"`, `authorSessionId`, and `authorName`.
* Auth header propagation is handled by the client helper and verified by fake-server tests.

**Files Changed**:

* `apps/cli/src/commands/notice.js` - added post subcommand behavior.
* `apps/cli/src/lib/noticeClient.js` - added `postNotice` request helper.
* `apps/cli/tests/noticeCommands.test.js` - covered post body and auth header.

**BQC Fixes**:

* Duplicate action prevention: matching post requests are blocked while in flight.
* Contract alignment: request body uses canonical Notice Board fields.

***

### Task T011 - Implement notice list

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Implemented `notice list` using `GET /notice-board?limit=20`.
* Added `forSession` only when a usable session id is available.
* Client formatting sorts returned messages deterministically by newest timestamp.

**Files Changed**:

* `apps/cli/src/commands/notice.js` - added list subcommand behavior.
* `apps/cli/src/lib/noticeClient.js` - added `listNotices` and list response formatting.
* `apps/cli/tests/noticeCommands.test.js` - covered list request and ordering.

**BQC Fixes**:

* State freshness on re-entry: each list call fetches fresh server state.
* Contract alignment: query construction matches the canonical route.

***

### Task T012 - Implement notice list type filter

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Implemented `notice list --type <type>` with recovered type validation before network calls.
* Invalid and missing type failures are mapped to concise CLI errors.

**Files Changed**:

* `apps/cli/src/commands/notice.js` - wired list filter handling.
* `apps/cli/src/lib/noticeClient.js` - added type-filter parser.
* `apps/cli/tests/noticeCommands.test.js` - covered type-filtered list requests.

**BQC Fixes**:

* Trust boundary enforcement: filter values are validated locally before request construction.

***

### Task T013 - Implement notice resolve

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Implemented `notice resolve <noticeId>` with safe-id validation and `POST /notice-board/:id/resolve`.
* Adds `authorSessionId` to resolve body when available.

**Files Changed**:

* `apps/cli/src/commands/notice.js` - added resolve subcommand behavior.
* `apps/cli/src/lib/noticeClient.js` - added `resolveNotice` helper.
* `apps/cli/tests/noticeCommands.test.js` - covered resolve route and body.

**BQC Fixes**:

* Duplicate action prevention: matching resolve requests are blocked while in flight.
* Trust boundary enforcement: notice id is validated before request construction.

***

### Task T014 - Implement notice context

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Implemented `notice context --session <sessionId>` with required safe session id validation.
* Added malformed context response handling.

**Files Changed**:

* `apps/cli/src/commands/notice.js` - added context subcommand behavior.
* `apps/cli/src/lib/noticeClient.js` - added context request and response formatting.
* `apps/cli/tests/noticeCommands.test.js` - covered context query and output.

**BQC Fixes**:

* Trust boundary enforcement: session id is validated locally.
* Failure path completeness: malformed context responses become explicit CLI errors.

***

### Task T015 - Implement list and context output formatting

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Added compact list/context formatting with timestamp, type, author, content, priority, and first three related files.
* Empty lists and empty contexts print `No active notices on the board.`

**Files Changed**:

* `apps/cli/src/lib/noticeClient.js` - added Notice Board formatters.
* `apps/cli/tests/noticeCommands.test.js` - covered empty output and related-file truncation.

**BQC Fixes**:

* Error information boundaries: output sanitizer redacts URLs, absolute paths, bearer tokens, and secret-like values.

***

### Task T016 - Implement privacy-safe error formatting

**Started**: 2026-06-05 21:38 **Completed**: 2026-06-05 21:46 **Duration**: 8 minutes

**Notes**:

* Added compact user-facing errors for invalid input, unreachable server, unauthorized server, timeout, invalid JSON, and malformed responses.
* Server error bodies are not printed to the terminal.

**Files Changed**:

* `apps/cli/src/lib/noticeClient.js` - added failure formatter and sanitization.
* `apps/cli/tests/noticeCommands.test.js` - covered unauthorized, unreachable, timeout, invalid JSON, and malformed response errors.

**BQC Fixes**:

* Failure path completeness: network and malformed response failures are deterministic.
* Error information boundaries: raw tokens and sensitive server payload text are not printed.

***

### Task T018 - Add post command tests

**Started**: 2026-06-05 21:43 **Completed**: 2026-06-05 21:46 **Duration**: 3 minutes

**Notes**:

* Covered canonical post body, auth header propagation, invalid type, and missing message.

**Files Changed**:

* `apps/cli/tests/noticeCommands.test.js` - added post and validation tests.

***

### Task T019 - Add list command tests

**Started**: 2026-06-05 21:43 **Completed**: 2026-06-05 21:46 **Duration**: 3 minutes

**Notes**:

* Covered default list query, session filtering, type-filtered list query, empty board output, deterministic ordering, and related-file truncation.

**Files Changed**:

* `apps/cli/tests/noticeCommands.test.js` - added list coverage.

***

### Task T020 - Add resolve, context, and error tests

**Started**: 2026-06-05 21:43 **Completed**: 2026-06-05 21:46 **Duration**: 3 minutes

**Notes**:

* Covered resolve route/body, context query/output, duplicate post protection, unauthorized, unreachable, timeout, invalid JSON, and malformed response errors.

**Files Changed**:

* `apps/cli/tests/noticeCommands.test.js` - added resolve, context, and failure-path coverage.

***

### Task T017 - Document Notice Board CLI commands

**Started**: 2026-06-05 21:47 **Completed**: 2026-06-05 21:48 **Duration**: 1 minute

**Notes**:

* Documented notice commands, supported types, server URL fallback, auth token header behavior, session/author metadata fallbacks, output shape, and privacy boundaries.
* Biome ignores Markdown files in this repo configuration, so no Markdown formatting command was applied.

**Files Changed**:

* `apps/cli/README_cli.md` - added Notice Board command documentation.

***

### Task T021 - Run focused tests and ASCII/LF validation

**Started**: 2026-06-05 21:48 **Completed**: 2026-06-05 21:48 **Duration**: 1 minute

**Notes**:

* `npx vitest run apps/cli/tests/noticeCommands.test.js` passed with 7 tests.
* `npx biome check apps/cli/src/lib/noticeClient.js apps/cli/src/commands/notice.js apps/cli/src/index.js apps/cli/tests/noticeCommands.test.js` passed.
* ASCII and LF validation passed for the session files and touched CLI files.

**Files Changed**:

* `.spec_system/specs/phase17-session05-cli-notice-commands/tasks.md` - marked final task and completion checklist complete.
* `.spec_system/specs/phase17-session05-cli-notice-commands/implementation-notes.md` - recorded final validation evidence.

***

## Test Results

| Command                                                                                                                                        | Result          |
| ---------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| `node --check apps/cli/src/lib/noticeClient.js`                                                                                                | Passed          |
| `node --check apps/cli/src/commands/notice.js`                                                                                                 | Passed          |
| `node --check apps/cli/tests/noticeCommands.test.js`                                                                                           | Passed          |
| `npx biome check apps/cli/src/lib/noticeClient.js apps/cli/src/commands/notice.js apps/cli/src/index.js apps/cli/tests/noticeCommands.test.js` | Passed          |
| `npx vitest run apps/cli/tests/noticeCommands.test.js`                                                                                         | Passed, 7 tests |
| ASCII/LF validation for session and touched CLI files                                                                                          | Passed          |

***

## Design Decisions

### Decision 1: Keep command routing thin

**Context**: Notice commands need HTTP behavior, validation, formatting, and privacy-safe error mapping. **Options Considered**:

1. Put logic in `commands/notice.js` - simpler file count but harder to test.
2. Put logic in `lib/noticeClient.js` - clearer fake-server testing and smaller command module.

**Chosen**: Option 2. **Rationale**: The CLI dispatcher stays aligned with existing command modules while request and formatting behavior remains testable without running the full CLI entry point.

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase17-session05-cli-notice-commands/implementation-notes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
