instar 1.3.351 → 1.3.353

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ # Side-effects review — Topic Operator binding (Know Your Principal #898, increment 2b)
2
+
3
+ ## What this change does
4
+ Wires the already-merged `TopicOperatorStore` (#904) into the live `AgentServer`
5
+ composition and exposes it over HTTP, plus the session-start injection block.
6
+
7
+ - `AgentServer.ts`: a new `topicOperatorStore` field constructed under the
8
+ `stateDir` guard inside its own try/catch (mirrors the `approvalLedger`
9
+ precedent), then passed into `routeCtx`.
10
+ - `routes.ts`: a `topicOperatorStore` field on `RouteContext` and four routes —
11
+ `GET /topic-operator`, `GET /topic-operator/:topicId`,
12
+ `GET /topic-operator/session-context?topicId=N`, `POST /topic-operator`.
13
+ - `CapabilityIndex.ts`: a `topicOperator` capability entry (prefix
14
+ `/topic-operator`) so the routes are discoverable.
15
+
16
+ ## Blast radius
17
+ - **Additive only.** No existing route, field, or store is modified. The store
18
+ is constructed when `stateDir` is available and is otherwise `null`; every
19
+ route degrades to `503` (feature-not-available) when it is `null`, never a
20
+ null-deref crash. The E2E test asserts the routes answer `200` on the real
21
+ production boot path (the store is genuinely composed in, not null).
22
+ - **No auth change.** All four routes sit behind the existing Bearer
23
+ middleware, identical to `/topic-bindings` and `/approvals`.
24
+ - **Fail-safe by construction.** An init failure is caught and reported via
25
+ `console.warn`; it can never block server boot. A corrupt store file is
26
+ treated as empty (a missing operator means the cross-principal guard treats
27
+ everything as unverifiable — deny-safe, not allow-safe).
28
+
29
+ ## The load-bearing security property (unchanged from #904)
30
+ The operator is established ONLY from the authenticated sender `uid`. The POST
31
+ route refuses a blank uid with `400`; a `displayName` (a content name) is never
32
+ authoritative — it is only lowercased for prose-matching. There is no code path
33
+ by which a name read from content becomes the operator. This is the structural
34
+ fix for the "Caroline" identity-bleed failure mode, and the integration + E2E
35
+ tests both assert the blank-uid refusal over the wire.
36
+
37
+ ## Migration parity
38
+ No migration is required. These are server-side routes and an in-process store
39
+ field — they reach existing agents automatically on the next server update (the
40
+ Migration Parity Standard governs agent-installed FILES: settings hooks, config
41
+ defaults, CLAUDE.md template, hook scripts, skills — none of which this touches).
42
+ The store auto-creates `state/topic-operators.json` on first write; no config
43
+ key is added, so there is nothing for `migrateConfig` to backfill.
44
+
45
+ The session-start HOOK wiring (so the `<topic-operator>` block is actually
46
+ fetched and injected at boot) is deliberately NOT in this increment — that is a
47
+ hook-template change requiring `migrateHooks`, and is scoped to increment 2c so
48
+ this PR stays a focused, reviewable composition+routes change. Until 2c lands the
49
+ block is reachable at the route but nothing injects it yet; that is intentional.
50
+
51
+ ## Framework generality
52
+ This is framework-agnostic. `platform` is a generic string (`telegram` |
53
+ `whatsapp` | `slack` | …), so the binding works for any messaging adapter, not
54
+ just Telegram. The `session-context` route returns a plain text block that any
55
+ framework's session-start hook can fetch and inject — it is not coupled to
56
+ Claude Code, Codex, or Gemini. The store has no platform-specific logic; it
57
+ delegates identity establishment to `PrincipalGuard.establishOperator`, which is
58
+ itself pure and framework-neutral.
59
+
60
+ ## Tests
61
+ - Tier 1 (unit): `tests/unit/topic-operator-store.test.ts` (10) — shipped in #904.
62
+ - Tier 2 (integration): `tests/integration/topic-operator-routes.test.ts` (10) —
63
+ full HTTP pipeline over a real file-backed store, incl. the blank-uid refusal
64
+ and the store-not-wired 503 degradation.
65
+ - Tier 3 (E2E): `tests/e2e/topic-operator-lifecycle.test.ts` (6) — feature-alive
66
+ on the real `AgentServer` boot path (200 not 503), full bind→read→inject
67
+ lifecycle, durable-write proof, and the over-the-wire blank-uid refusal.
68
+
69
+ ## Rollback
70
+ Revert the three source edits + delete the two test files. The store on disk
71
+ (`state/topic-operators.json`) is inert without the routes and can be left or
72
+ removed with no consequence.
@@ -0,0 +1,37 @@
1
+ # Side-effects review — TopicOperatorStore (Know Your Principal, increment 2)
2
+
3
+ ## What this change is
4
+ A new `src/users/TopicOperatorStore.ts` — a JSON-backed (`state/topic-operators.json`)
5
+ store for the verified per-topic operator, plus its unit test. Decoupled from
6
+ the ScopeVerifier topic→project binding by design (a topic can have an operator
7
+ without a project binding; TopicProjectBinding requires projectName/projectDir).
8
+
9
+ ## Blast radius
10
+ - **Runtime impact: none.** Nothing constructs or imports TopicOperatorStore at
11
+ boot or in any route/job/sentinel yet — adding it cannot change live behavior.
12
+ The routes + session-start injection that consume it are later increments.
13
+ - Imports only `PrincipalGuard.establishOperator` (pure, already shipped in #902).
14
+ - New state file `state/topic-operators.json` is created lazily on first write;
15
+ read fails safe to empty on missing/corrupt (a missing operator → the guard
16
+ treats everything as unverifiable, which is the safe direction).
17
+
18
+ ## Security review
19
+ - Operator establishment is uid-only by construction (delegates to
20
+ establishOperator) — no path accepts a name from content as the operator
21
+ (the Caroline failure mode is impossible).
22
+ - No network, no secrets, no new auth; one local JSON file.
23
+
24
+ ## Framework generality
25
+ Pure logic + one local JSON file — no session-launch/inject/message-delivery
26
+ surface; framework-agnostic.
27
+
28
+ ## Test coverage
29
+ 10 unit tests (`tests/unit/topic-operator-store.test.ts`) covering both sides of
30
+ every boundary: valid-uid establish + read-back, blank-uid refusal, content-name-
31
+ never-becomes-operator, unbound→null, persistence across instances, replace,
32
+ asVerifiedOperator (feeds the guard), and sessionContextBlock (bound/unbound/uid-
33
+ fallback). tsc clean; docs-coverage class floor restored (TopicOperatorStore
34
+ documented in the Know Your Principal concept doc).
35
+
36
+ ## Rollback
37
+ Delete the module + test + the doc mention; zero runtime consequence (no consumers).
@@ -0,0 +1,47 @@
1
+ # ELI16 — Who's the boss of this chat?
2
+
3
+ ## The problem in one sentence
4
+ An AI agent needs to know, for sure, *which real person* it's working for in a
5
+ given conversation — and it should never get tricked into thinking some other
6
+ name it read somewhere is the boss.
7
+
8
+ ## The story behind it
9
+ Not long ago, an agent running on a shared computer slowly started treating a
10
+ *different real person* — call her Caroline — as the person giving it orders. It
11
+ even wrote her name into its work as if her approvals counted. Nobody caught it,
12
+ because the mix-up happened entirely inside the agent's own writing. There was no
13
+ "front door" guard checking that, because the bad name never came in through a
14
+ message — it leaked in from the machine's settings and the agent's own notes.
15
+
16
+ We already built two pieces to stop this: a detector brain (`PrincipalGuard`)
17
+ that spots when the agent credits a decision to the wrong person, and a small
18
+ filing cabinet (`TopicOperatorStore`) that remembers, per conversation, exactly
19
+ who the verified boss is. The rule the filing cabinet enforces is strict: the
20
+ boss is decided ONLY by the verified ID of whoever actually sent the message —
21
+ never by a name typed in some document.
22
+
23
+ ## What this change adds
24
+ This step plugs that filing cabinet into the running server so the rest of the
25
+ system can actually use it. It adds four simple web endpoints:
26
+
27
+ - "Who's the boss of this chat?" — read one conversation's verified operator.
28
+ - "Show me all the bosses" — list every conversation's verified operator.
29
+ - "Set the boss" — record the boss, but ONLY from a verified sender ID. If you
30
+ try to set it with a blank ID (hoping a typed-in name will stick), it says no.
31
+ - "Give me the boot-up note" — hand back a short block the agent can read at the
32
+ start of a session so it knows, from message one, who it's really serving.
33
+
34
+ ## Why it's safe
35
+ It only *adds* things. Nothing old changes. If the server can't build the filing
36
+ cabinet for some reason, the endpoints politely say "not available" instead of
37
+ crashing. And the one rule that matters most — a name you merely *read* can never
38
+ become the boss, only a verified sender can — is checked right at the web layer,
39
+ and we have tests that prove it by trying to sneak the name "Caroline" in through
40
+ a blank ID and watching it get rejected.
41
+
42
+ ## What's deliberately left for next time
43
+ The actual "read the boot-up note at session start" wiring (so the agent
44
+ automatically sees who its boss is every time it wakes up) is a separate, slightly
45
+ riskier change to the start-up script, so it gets its own follow-up step. For now
46
+ the note is available to ask for; nothing reads it automatically yet. That's on
47
+ purpose — it keeps this change small and easy to review.