@tomflow/chatloop-tools 0.9.64 → 0.9.70

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.
Files changed (175) hide show
  1. package/node_modules/@tomflow/chatloop-context/README.md +296 -0
  2. package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +48 -0
  3. package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +151 -0
  4. package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +376 -0
  5. package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +290 -0
  6. package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +134 -0
  7. package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +82 -0
  8. package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +349 -0
  9. package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +72 -0
  10. package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +73 -0
  11. package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +507 -0
  12. package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +11 -0
  13. package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +261 -0
  14. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +277 -0
  15. package/node_modules/@tomflow/chatloop-context/index.mjs +238 -0
  16. package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +86 -0
  17. package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +77 -0
  18. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +2036 -0
  19. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +69 -0
  20. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +338 -0
  21. package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +298 -0
  22. package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +286 -0
  23. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +117 -0
  24. package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +51 -0
  25. package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +134 -0
  26. package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +262 -0
  27. package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +246 -0
  28. package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +180 -0
  29. package/node_modules/@tomflow/chatloop-context/lib/core/run-cancel.mjs +68 -0
  30. package/node_modules/@tomflow/chatloop-context/lib/core/run-recovery.mjs +112 -0
  31. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +367 -0
  32. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +398 -0
  33. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +264 -0
  34. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +13 -0
  35. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +111 -0
  36. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +107 -0
  37. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +118 -0
  38. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +20 -0
  39. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +316 -0
  40. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +153 -0
  41. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +19 -0
  42. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +117 -0
  43. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +142 -0
  44. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +169 -0
  45. package/node_modules/@tomflow/chatloop-context/package.json +38 -0
  46. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +114 -0
  47. package/node_modules/@tomflow/chatloop-extension/README.md +190 -0
  48. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +13 -0
  49. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +168 -0
  50. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +246 -0
  51. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +1 -0
  52. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +1 -0
  53. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +1 -0
  54. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +1 -0
  55. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +1 -0
  56. package/node_modules/@tomflow/chatloop-extension/capabilities/entry_test.mjs +1 -0
  57. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +1 -0
  58. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +1 -0
  59. package/node_modules/@tomflow/chatloop-extension/capabilities/session.mjs +1 -0
  60. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +1 -0
  61. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +1 -0
  62. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +123 -0
  63. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +183 -0
  64. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +390 -0
  65. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +2 -0
  66. package/node_modules/@tomflow/chatloop-extension/extension/actions/entry_test.js +241 -0
  67. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff-scoped.js +143 -0
  68. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +399 -0
  69. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +2 -0
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +60 -0
  71. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +9 -0
  72. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +20 -0
  73. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +77 -0
  74. package/node_modules/@tomflow/chatloop-extension/extension/actions/session.js +95 -0
  75. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +329 -0
  76. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +38 -0
  77. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +2 -0
  78. package/node_modules/@tomflow/chatloop-extension/extension/background.js +33 -0
  79. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +5 -0
  80. package/node_modules/@tomflow/chatloop-extension/extension/content.js +40 -0
  81. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +9 -0
  82. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +17 -0
  83. package/node_modules/@tomflow/chatloop-extension/extension/entry_test.html +6 -0
  84. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +9 -0
  85. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +2 -0
  86. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +275 -0
  87. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +84 -0
  88. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +107 -0
  89. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +36 -0
  90. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +299 -0
  91. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +144 -0
  92. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +172 -0
  93. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +109 -0
  94. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +211 -0
  95. package/node_modules/@tomflow/chatloop-extension/extension/loop/resource-maintenance.js +159 -0
  96. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +399 -0
  97. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +43 -0
  98. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +25 -0
  99. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +99 -0
  100. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +17 -0
  101. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +17 -0
  102. package/node_modules/@tomflow/chatloop-extension/extension/session.html +7 -0
  103. package/node_modules/@tomflow/chatloop-extension/extension/start.html +6 -0
  104. package/node_modules/@tomflow/chatloop-extension/extension/status.html +6 -0
  105. package/node_modules/@tomflow/chatloop-extension/extension/text.html +17 -0
  106. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +136 -0
  107. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +218 -0
  108. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +127 -0
  109. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +296 -0
  110. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +186 -0
  111. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +126 -0
  112. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +287 -0
  113. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +163 -0
  114. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +345 -0
  115. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +209 -0
  116. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +385 -0
  117. package/node_modules/@tomflow/chatloop-extension/extension/worker/session-control.js +75 -0
  118. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-action-v2.js +278 -0
  119. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-cancel-recovery-v2.js +52 -0
  120. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-cancel-v2.js +93 -0
  121. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-continue-recovery-v2.js +78 -0
  122. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-handoff-recovery-v2.js +148 -0
  123. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-handoff-v2.js +325 -0
  124. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-hold-recovery-v2.js +109 -0
  125. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-intent-dispatch-v2.js +220 -0
  126. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-intent-v2.js +106 -0
  127. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-owner-resolver.js +110 -0
  128. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-recover-v2.js +209 -0
  129. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-routes-v2.js +357 -0
  130. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-run-store.js +400 -0
  131. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-scheduler.js +78 -0
  132. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-start-v2.js +361 -0
  133. package/node_modules/@tomflow/chatloop-extension/extension/worker/task-terminal-v2.js +235 -0
  134. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +197 -0
  135. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +205 -0
  136. package/node_modules/@tomflow/chatloop-extension/index.mjs +78 -0
  137. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +19 -0
  138. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +82 -0
  139. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +378 -0
  140. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +89 -0
  141. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +45 -0
  142. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +122 -0
  143. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +75 -0
  144. package/node_modules/@tomflow/chatloop-extension/lib/owner-kernel-lock.mjs +106 -0
  145. package/node_modules/@tomflow/chatloop-extension/lib/owner-ledger.mjs +316 -0
  146. package/node_modules/@tomflow/chatloop-extension/lib/owner-locked-write.mjs +30 -0
  147. package/node_modules/@tomflow/chatloop-extension/lib/scoped-cancel-v2.mjs +190 -0
  148. package/node_modules/@tomflow/chatloop-extension/lib/scoped-continue-v2.mjs +214 -0
  149. package/node_modules/@tomflow/chatloop-extension/lib/scoped-handoff-v2.mjs +338 -0
  150. package/node_modules/@tomflow/chatloop-extension/lib/scoped-native-control.mjs +398 -0
  151. package/node_modules/@tomflow/chatloop-extension/lib/scoped-recovery-v2.mjs +234 -0
  152. package/node_modules/@tomflow/chatloop-extension/lib/scoped-retire-v2.mjs +70 -0
  153. package/node_modules/@tomflow/chatloop-extension/lib/scoped-terminal-v2.mjs +143 -0
  154. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +228 -0
  155. package/node_modules/@tomflow/chatloop-extension/package.json +36 -0
  156. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +138 -0
  157. package/node_modules/@tomflow/chatloop-trace/README.md +118 -0
  158. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +23 -0
  159. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +22 -0
  160. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +4 -0
  161. package/node_modules/@tomflow/chatloop-trace/index.mjs +59 -0
  162. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +273 -0
  163. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +308 -0
  164. package/node_modules/@tomflow/chatloop-trace/lib/trace-retention.mjs +140 -0
  165. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +236 -0
  166. package/node_modules/@tomflow/chatloop-trace/package.json +28 -0
  167. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +68 -0
  168. package/node_modules/ps-list/index.d.ts +76 -0
  169. package/node_modules/ps-list/index.js +366 -0
  170. package/node_modules/ps-list/license +9 -0
  171. package/node_modules/ps-list/package.json +44 -0
  172. package/node_modules/ps-list/readme.md +56 -0
  173. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  174. package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
  175. package/package.json +12 -4
@@ -0,0 +1,296 @@
1
+ # @tomflow/chatloop-context
2
+
3
+ One authoritative per-Project SQLite Context Store for **Project / Task / R/P Review /
4
+ Run Permit / Checkpoint / CAS / Receipt**. This package does **not** own the
5
+ Chrome Session Owner, user-message evidence collection, Trace, MCP Supervisor,
6
+ execution workflow or external source discovery.
7
+
8
+ ## Exactly two npm access points
9
+
10
+ | Entry | npm declaration | Who uses it | Purpose |
11
+ | --- | --- | --- | --- |
12
+ | **Module entry** | `exports["."] = "./index.mjs"` | SDK clients, Tools MCP, Native/Operator adapters | All importable functions, clearly separated by role |
13
+ | **Executable entry** | `bin["chatloop-context"] = "./bin/cli.mjs"` | Pinned Tools CLI process or explicitly authorized local operator | Bounded `request --json`, method discovery and reviewed operator commands |
14
+
15
+ **No `./protocol`, `./methods`, `./operations`, `./migration`,
16
+ `./admin` or `./cli` npm subpath is exported.** Internal files in
17
+ `lib/` are implementation, not an integration contract. The installed CLI
18
+ comes from npm `bin`, not a second importable npm module.
19
+
20
+ **Implementation boundary:** No module in `lib/**` imports another `lib/**`
21
+ implementation. The sole SDK root `index.mjs` injects named API capabilities
22
+ through three lazy compositions: Business, Trusted Native and Local Operator.
23
+ `bin/cli.mjs` imports only `index.mjs` and invokes the reviewed operator
24
+ `runLocalCliCommand()` API; it does not import implementation files.
25
+
26
+ ```text
27
+ index.mjs (sole SDK entry and dependency assembler)
28
+ |-- Build manifest -> capability contracts and generic dispatcher
29
+ |-- Business API -> Core / Project / Task / Review / Context
30
+ |-- Trusted API -> Run / Permit (signed-IPC consumer)
31
+ +-- Operator API -> Workspace / Migration / CLI commands
32
+ bin/cli.mjs (sole executable entry) -> index.mjs -> Operator API
33
+ lib/** (private implementations) <- named capabilities injected by index.mjs
34
+ Core -> one SQLite handle, CAS transaction and durable receipt owner
35
+ ```
36
+
37
+ A module knows only its injected API contract, never the source file or internal
38
+ structure of the provider. Modules do not import `index.mjs` in reverse, so
39
+ no circular npm import is created. An import, `npx` invocation or module loader
40
+ alone **does not grant** Project ACL, Native Permit or operator permission.
41
+
42
+ ## Module exports: always import only from the package root
43
+
44
+ ```js
45
+ import {
46
+ CONTEXT_CONTRACT, CONTEXT_PACKAGE_VERSION,
47
+ requestContext, contextGateway, loadTrustedRuntime, loadLocalOperator,
48
+ subscribeContextApiLog
49
+ } from '@tomflow/chatloop-context';
50
+ ```
51
+
52
+ | Surface | Exact exported names | Trust boundary |
53
+ | --- | --- | --- |
54
+ | **Public SDK** | `CONTEXT_CONTRACT`, `CONTEXT_PACKAGE_VERSION`, `requestContext` | Strict Method Catalog; Project ACL; CAS / receipt |
55
+ | **Tools MCP adapter** | `contextGateway` namespace (`tools`, `validate`, `allowedProjects`, `cliPath`) | The pinned package owns its own CLI path; caller cannot select arbitrary executable |
56
+ | **Trusted Native adapter** | `loadTrustedRuntime()` → `execute(command,args,native)` | Only a signed IPC verified Native projection is accepted by its consumer; Context validates domain command, Native fields, Project grant and CAS |
57
+ | **Local operator** | `loadLocalOperator()` → only `runLocalCliCommand` (CLI consumer) | Explicit reviewed CLI/TTY and verified Project/SourceUnit / backups |
58
+ | **Observability** | `subscribeContextApiLog(listener)` → `unsubscribe()` | Tools routes non-authoritative events to the existing Supervisor Trace writer |
59
+
60
+ `loadTrustedRuntime` and `loadLocalOperator` do not themselves authorize any
61
+ action. They organize trusted integrators behind **the same root**; they are
62
+ not ordinary model/MCP operations.
63
+
64
+ **Task-scoped Native Writer read (unreleased source contract):**
65
+ `loadTrustedRuntime().execute('run.terminalStatus',args,native)` uses
66
+ an exact, independently verified `projectId/taskId/sessionId/generation`
67
+ Native owner projection. Its read-only result includes
68
+ `pendingHandoff: boolean` (from the authoritative Task
69
+ `pending_attempt`) and `pendingCheckpointId: string|null` (from
70
+ `pending_checkpoint`) alongside the existing `runRef`,
71
+ `bindingRevision`, `unknownEffectCount` and execution outcome.
72
+ It also reports `writerApprovalCurrent` and `projectRulesDrift`
73
+ from the same authoritative Task/Project snapshot; a later R/P change
74
+ or Project rule drift cannot silently inherit the old Writer.
75
+ A bound `runRef` by itself is **not** a safe Continue permission:
76
+ Native/Worker must reject a pending Handoff, pending Checkpoint,
77
+ an UNKNOWN effect or a stale owner. `run.snapshot` means the latest
78
+ immutable Checkpoint, **not** the live pending-attempt status.
79
+ When a signed Native Owner is already in `PENDING`, this private
80
+ `run.terminalStatus` may additionally accept the exact
81
+ `expectedHandoffAttemptId` (128-bit original signed Handoff request).
82
+ Context compares it with the authoritative `pending_attempt` inside
83
+ its read snapshot and returns only `pendingAttemptMatches: boolean`.
84
+ It never reveals the pending request ID, credential or digest, and never
85
+ releases a fenced Writer. The trusted adapter refuses the probe outside
86
+ Native PENDING except for a positive-revision V2 Native BLOCKED Owner
87
+ with an existing Chat, strictly for the original abort-revocation
88
+ **read-only** receipt; it always rejects a probe combined with Start
89
+ recovery. The Handoff Native consumer requires
90
+ `pendingAttemptMatches===true` before accepting the original
91
+ pending-fence or revoked-abort proof. The BLOCKED read cannot revive a
92
+ Writer, consume a Permit, replay Handoff or change Task data. This is NOT authorization to replay or
93
+ restore a Chat send.
94
+
95
+ A signed, exact V2 Native Task Status may also read
96
+ `run.terminalStatus` while generation zero is `STARTING/RESERVED/PENDING`
97
+ with both `activeChatId` and `activeChatUrl` null. This narrowly
98
+ scoped exception requires a positive V2 Native Session revision and
99
+ does not apply to V1, later generations, writes, Permit consumption
100
+ or `run.bind.initial`. It lets the existing Status Action report the
101
+ pre-Adopt phase instead of failing solely because no Chat has yet
102
+ been claimed.
103
+
104
+ This is an additive **internal trusted read**; it does not add a public
105
+ SDK method, MCP tool, writer, retry capability or browser send. Source
106
+ is not yet rebuilt, deployed or tested.
107
+
108
+ The private `loadTrustedRuntime().execute(command,...)` facade additionally
109
+ accepts `permit.status` (the exact original Task + actionToken, returning
110
+ bounded recorded kind/approval revision) and
111
+ `run.idleStartPermitStatus` (whether the **only** permit in that Task is
112
+ the consumed original START permit). The latter is preliminary evidence:
113
+ `run.fence.cancel` repeats the same original START-only Permit check inside
114
+ **its own SQLite transaction**, so a concurrent CONTINUE/HANDOFF reservation
115
+ cannot slip between the read and cancellation commit. V2 Context reads
116
+ also supply the fixed `storeEpoch` and current Project/R/P writer checks.
117
+ Neither method is an open/public `context.*` capability or additional
118
+ MCP tool. One Task's SQLite revisions never authorize another Task.
119
+
120
+ See [provider / consumer / dependency matrix](docs/interfaces.md) for the
121
+ **complete** cross-module reference. For exact method IDs, schemas and
122
+ semantics, use `sdk.methods.list` / `sdk.methods.describe` on the connected SDK.
123
+
124
+ ## External API minimization (no compatibility surface)
125
+
126
+ The npm module exposes exactly seven names, and the ordinary Method Catalog
127
+ contains **34 current business operations** (no Legacy aliases). Public
128
+ JavaScript consumers must use `requestContext(args)`; discovery also uses
129
+ that same operation with `sdk.methods.list` / `sdk.methods.describe`.
130
+ There are no separately exported `listMethods` / `describeMethod` helpers.
131
+
132
+ The CLI is the *only* consumer of `loadLocalOperator()`, whose returned
133
+ namespace contains only `runLocalCliCommand`. Its migration, workspace,
134
+ SourceUnit and orphan-fence utilities stay private to the `index.mjs`
135
+ composition. `project.create`, `project.registryAuthority`, `project.get`,
136
+ `project.archive`, `task.get`, `task.archive`, and `evidence.detach` are **not**
137
+ public operations. For new projects use reviewed `chatloop-context project
138
+ register/init`; for Project/Task detail use `project.open` / `task.open`.
139
+ There is no version-1 forwarding or fallback. Clients must upgrade together
140
+ and verify the `chat-loop.context-sdk.v2` contract before use.
141
+ `project.list` and `task.list` always return a bounded page object,
142
+ respectively `{projects,incomplete,nextCursor,limit}` and
143
+ `{tasks,incomplete,nextCursor,limit}`, with `limit=30` by default. There is
144
+ no implicit full-array result when pagination arguments are omitted.
145
+
146
+ ## Capability-based build composition
147
+
148
+ The stable npm/CLI/MCP entrypoints now compose **34 existing methods from
149
+ nine independent capability descriptors** in `capabilities/<group>.mjs`.
150
+ Each descriptor owns its method IDs, Schema, mode, version, and dispatch route.
151
+ To add an independent capability, create one new descriptor with a unique
152
+ group name; no edits to existing capabilities or the central router are needed.
153
+
154
+ `npm run build:capabilities` produces the deterministic
155
+ `capabilities.generated.mjs` (static imports) and
156
+ `lib/capability-catalog.generated.json` (strict metadata). The generated
157
+ catalog drives `sdk.methods.list/describe`, SDK validation, both MCP tool
158
+ schemas and CLI discovery. Build/check/pack fail when outputs
159
+ are missing or stale; runtime never scans arbitrary directories.
160
+
161
+ Existing Core writes continue to require the original Project authority,
162
+ MANAGED_RW, CAS and durable receipts. The new `module` route is limited to
163
+ authorized **read-only** Project access with a restricted document/material
164
+ read port; it does not expose a raw database, writer credential or Owner.
165
+ The scoped Store remains open until an asynchronous capability Promise settles,
166
+ then closes on both success and failure.
167
+ A future independently writable capability requires a separately reviewed
168
+ transaction/receipt contract, not a security bypass. No RAG implementation
169
+ or new business feature is included in this refactor.
170
+
171
+ The isolated additive `probe` test builds and routes a 35th method, verifies
172
+ its Project boundary, then removes it to recover the original 34 methods.
173
+ The compiler rejects unsafe writes and conflicting capability declarations.
174
+
175
+ ## Context API logging — Proxy/AOP, no domain instrumentation
176
+
177
+ The exported `requestContext` intercepts **all 34 business operations**.
178
+ The same reusable `Proxy` intercepts `contextGateway.validate`,
179
+ `contextGateway.allowedProjects`, Trusted Native `execute`, and Local
180
+ Operator `runLocalCliCommand`. The package exports one consumed hook,
181
+ `subscribeContextApiLog(listener)`, for Tools to attach a best-effort sink.
182
+
183
+ Each call emits a sanitized
184
+ `{contract,callId,traceId,spanId,parentSpanId,api,surface,mode,projectRef,taskRef,phase,time,durationMs,errorCode}`
185
+ event with `BEGIN` followed by `OK` or `FAILED`. API calls
186
+ within one asynchronous chain inherit a soft `traceId`; every API gets its
187
+ own `spanId` and optional parent. The pinned child CLI inherits only an
188
+ opaque sanitized parent reference, never a permission or Owner credential.
189
+ Input bodies, credentials, paths and output values are never logged. Callbacks and CLI STDERR output
190
+ are deferred through a bounded best-effort queue (up to 4096 pending events),
191
+ so an observer cannot synchronously delay a business API. Log failures and
192
+ queue saturation cannot change the original result, Promise rejection,
193
+ CAS transaction or business receipt; they must not trigger retries.
194
+ Observations can be dropped when overloaded and are not durable evidence.
195
+
196
+ Context CLI emits structured STDERR log records without polluting its
197
+ single JSON stdout response. For a Context-authorized single Project, Tools
198
+ routes these observations into **one** existing Supervisor Trace v2
199
+ `events.jsonl` file even when the public Trace MCP is disabled. Reading via
200
+ `chat_loop_trace_diagnose` still requires independent Trace opt-in.
201
+ Records use fixed `event=context.api`, typed `api={name,surface,mode}`,
202
+ and correlated `traceId/spanId/parentSpanId` for nested API calls. For
203
+ root calls without an inherited parent, `traceId=callId`.
204
+ No second logging database or daemon is created. Without a connected Trace
205
+ sink, CLI STDERR remains observable but no permanent retention is claimed.
206
+ These are soft execution observations, never R/P approval, browser-send
207
+ proof or Native Owner evidence.
208
+
209
+ ## Minimal usage
210
+
211
+ Node **20+** may import the root and discover methods; SQLite access, runtime
212
+ and operator work require **Node 24+**. The package does not create a daemon.
213
+
214
+ ```js
215
+ import {requestContext} from '@tomflow/chatloop-context';
216
+
217
+ const capabilities=await requestContext({operation:'sdk.methods.list',view:'groups'});
218
+ const schema=(await requestContext({operation:'sdk.methods.describe',
219
+ methodId:'project.open'})).inputSchema;
220
+ const project=await requestContext({operation:'project.open',projectId:'demo'});
221
+ console.log(project.authority,project.storeEpoch);
222
+ ```
223
+
224
+ A public SDK call is accepted only for configured, explicitly authorized
225
+ Project IDs. A normal adapter uses `CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS` plus
226
+ **exactly one** of `CHAT_LOOP_CONTEXT_ROOT` (one SQLite per Project) or the
227
+ explicitly controlled legacy `CHAT_LOOP_CONTEXT_DB` migration mode. Never
228
+ set both roots.
229
+
230
+ Write operations require relevant `expectedStoreEpoch`, revision CAS,
231
+ `writeRequestId`, and for active-run updates the real RunRef/credential.
232
+ **UNKNOWN** result: check `context.request.status` using the **original**
233
+ request ID; never invent a second write attempt.
234
+
235
+ ## CLI lifecycle
236
+
237
+ The npm executable is `chatloop-context`, installed by a fixed dependency
238
+ or invoked separately through a **pinned, available** npm version:
239
+
240
+ ```sh
241
+ npm install --save-exact "@tomflow/chatloop-context@${VERIFIED_CONTEXT_VERSION:?set-exact-verified-version}"
242
+ chatloop-context methods groups
243
+ chatloop-context methods list project
244
+ chatloop-context methods describe project.open
245
+ printf '%s
246
+ ' '{"operation":"sdk.methods.list","view":"groups"}' | chatloop-context request --json
247
+ ```
248
+
249
+ The CLI emits a **single structured result**:
250
+ `{contract,packageVersion,ok,result}` or
251
+ `{contract,packageVersion,ok:false,error:{code}}`. The binary is an
252
+ independent one-shot process; Tools starts its **pinned** CLI with
253
+ `shell:false` and does not resolve a new `npx` release per request.
254
+
255
+ Operator-only commands (`project register/bind/receipt/init`, `admin <action>`, recovery,
256
+ source audit and sealing, orphan fence, etc.) enforce separate local
257
+ authorization, exact input/revision and where required real TTY review.
258
+ See [operator and migration procedures](docs/operator-and-migration.md).
259
+
260
+ ## Actual consumers and dependencies
261
+
262
+ - **Consumers:** Project/Delivery/Continuity → Tools MCP
263
+ `chat_loop_context_get/mutate` → pinned Context CLI; Tools Registry
264
+ adapter → Context authority/Task reads; Extension Worker → Native Host
265
+ → signed Tools Supervisor → Context trusted runtime; local reviewed
266
+ operator → CLI.
267
+ - **npm dependencies:** `@tomflow/chatloop-extension` (official verified
268
+ Owner evidence API) and `ps-list` (cross-platform process enumeration).
269
+ Both are declared, pinned, and consumed through named APIs; SQLite,
270
+ filesystem and crypto remain Node built-ins.
271
+ - **Owner boundary:** Context no longer constructs the Extension installation
272
+ path or reads the private Native Session file. Its `fence-orphan`
273
+ operator asks Extension to independently verify terminal IDLE and Owner
274
+ mismatch before and after review. The process observation API is not
275
+ itself a durable stop receipt.
276
+
277
+ Read [interfaces.md](docs/interfaces.md) for the exact source files, calls,
278
+ ownership boundaries and known coupling risks.
279
+
280
+ ## Deployment is separate from source
281
+
282
+ The source version declared in [`package.json`](package.json) does **not** establish the connected MCP
283
+ version. Verify the real `sdk.methods.list` response, Node runtime,
284
+ pinned Tools dependency, package bytes and Project authority before any
285
+ separately authorized installation. Source refactoring does **not** migrate
286
+ production SQLite, change Chrome Owner or approve R/P.
287
+
288
+ ```sh
289
+ npm run build:capabilities:check
290
+ npm test
291
+ ```
292
+
293
+ Each capability owns its API contract in `capabilities/<group>.mjs`;
294
+ there is no separate API inventory document. To discover exact available
295
+ methods and their schemas, use `sdk.methods.list` / `sdk.methods.describe`
296
+ from the installed SDK. Never substitute local source docs for deployed contracts.
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ // The ONLY shell-visible entrypoint; all capabilities come from the root SDK.
3
+ import {CONTEXT_CONTRACT,CONTEXT_PACKAGE_VERSION,
4
+ requestContext,loadLocalOperator} from '../index.mjs';
5
+ // This short-lived Context CLI is the only process that emits the SDK's
6
+ // structured audit records on STDERR. Other npm consumers use subscriptions.
7
+ process.env.CHAT_LOOP_CONTEXT_API_LOG_STDERR='1';
8
+ const fail=code=>Object.assign(new Error(code),{code});
9
+ const limit=5*1024*1024;
10
+ const output=value=>process.stdout.write(JSON.stringify({
11
+ contract:CONTEXT_CONTRACT,packageVersion:CONTEXT_PACKAGE_VERSION,...value
12
+ })+'\n');
13
+ async function readJson(){
14
+ let bytes=0,parts=[];
15
+ for await(const chunk of process.stdin){
16
+ bytes+=chunk.length;
17
+ if(bytes>limit)throw fail('REQUEST_TOO_LARGE');
18
+ parts.push(chunk);
19
+ }
20
+ if(!bytes)throw fail('REQUEST_REQUIRED');
21
+ try{return JSON.parse(Buffer.concat(parts).toString('utf8'))}
22
+ catch{throw fail('INVALID_JSON')}
23
+ }
24
+ const args=process.argv.slice(2);
25
+ try{
26
+ const node24=Number(process.versions.node.split('.')[0])>=24;
27
+ if(!node24&&args[0]!=='methods')throw fail('CONTEXT_RUNTIME_UNSUPPORTED');
28
+ let value;
29
+ if(!node24){
30
+ const [command,sub,...rest]=args;
31
+ if(command==='methods'&&sub==='list'&&rest.length<=1)
32
+ value=await requestContext({operation:'sdk.methods.list',...(rest[0]==='--json'?{}:rest[0]?{group:rest[0]}:{})});
33
+ else if(command==='methods'&&sub==='groups'&&rest.length<=1)
34
+ value=await requestContext({operation:'sdk.methods.list',view:'groups',...(rest[0]?{group:rest[0]}:{})});
35
+ else if(command==='methods'&&sub==='describe'&&rest.length===1)
36
+ value=await requestContext({operation:'sdk.methods.describe',methodId:rest[0]});
37
+ else throw fail('UNKNOWN_COMMAND');
38
+ }else{
39
+ const {runLocalCliCommand}=await loadLocalOperator();
40
+ value=await runLocalCliCommand(args,readJson);
41
+ }
42
+ output({ok:true,result:value});
43
+ }catch(error){
44
+ // Never leak arbitrary filesystem, SQLite, or user data in CLI errors.
45
+ const code=error.code||'CONTEXT_FAILED';
46
+ output({ok:false,error:{code:/^[A-Z0-9_]+$/.test(code)?code:'CONTEXT_FAILED'}});
47
+ process.exitCode=1;
48
+ }
@@ -0,0 +1,151 @@
1
+ // One self-contained Context capability contract. Registered at build time.
2
+ export const capability={
3
+ "id": "approval",
4
+ "version": 1,
5
+ "purpose": "Observe or revoke R/P decisions with actual user-turn evidence",
6
+ "startWith": "approval.observe",
7
+ "methods": [
8
+ {
9
+ "id": "approval.observe",
10
+ "group": "approval",
11
+ "mode": "write",
12
+ "description": "Record soft evidence of a real user decision on a displayed R/P version.",
13
+ "inputSchema": {
14
+ "type": "object",
15
+ "required": [
16
+ "operation",
17
+ "projectId",
18
+ "taskId",
19
+ "issueId",
20
+ "decision",
21
+ "sourceRole",
22
+ "userTurn",
23
+ "presentedAssistantRef",
24
+ "expectedTaskRevision",
25
+ "expectedStoreEpoch",
26
+ "writeRequestId"
27
+ ],
28
+ "additionalProperties": false,
29
+ "properties": {
30
+ "operation": {
31
+ "const": "approval.observe"
32
+ },
33
+ "projectId": {
34
+ "type": "string",
35
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
36
+ },
37
+ "taskId": {
38
+ "type": "string",
39
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
40
+ },
41
+ "issueId": {
42
+ "type": "string",
43
+ "minLength": 8,
44
+ "maxLength": 64
45
+ },
46
+ "decision": {
47
+ "enum": [
48
+ "APPROVE",
49
+ "REJECT",
50
+ "REQUEST_CHANGE",
51
+ "CUSTOM"
52
+ ]
53
+ },
54
+ "sourceRole": {
55
+ "const": "user"
56
+ },
57
+ "userTurn": {
58
+ "type": "string",
59
+ "minLength": 8,
60
+ "maxLength": 256
61
+ },
62
+ "presentedAssistantRef": {
63
+ "type": "string",
64
+ "minLength": 8,
65
+ "maxLength": 256
66
+ },
67
+ "expectedTaskRevision": {
68
+ "type": "integer",
69
+ "minimum": 1
70
+ },
71
+ "expectedStoreEpoch": {
72
+ "type": "string",
73
+ "minLength": 10,
74
+ "maxLength": 64
75
+ },
76
+ "writeRequestId": {
77
+ "type": "string",
78
+ "minLength": 8,
79
+ "maxLength": 128
80
+ }
81
+ }
82
+ },
83
+ "order": 27,
84
+ "route": {
85
+ "kind": "core",
86
+ "method": "observeApproval",
87
+ "params": [
88
+ "$args"
89
+ ]
90
+ }
91
+ },
92
+ {
93
+ "id": "approval.revoke",
94
+ "group": "approval",
95
+ "mode": "write",
96
+ "description": "Invalidate earlier approvals at the correct task revision.",
97
+ "inputSchema": {
98
+ "type": "object",
99
+ "required": [
100
+ "operation",
101
+ "projectId",
102
+ "taskId",
103
+ "expectedTaskRevision",
104
+ "expectedApprovalRevision",
105
+ "expectedStoreEpoch",
106
+ "writeRequestId"
107
+ ],
108
+ "additionalProperties": false,
109
+ "properties": {
110
+ "operation": {
111
+ "const": "approval.revoke"
112
+ },
113
+ "projectId": {
114
+ "type": "string",
115
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
116
+ },
117
+ "taskId": {
118
+ "type": "string",
119
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
120
+ },
121
+ "expectedTaskRevision": {
122
+ "type": "integer",
123
+ "minimum": 1
124
+ },
125
+ "expectedApprovalRevision": {
126
+ "type": "integer",
127
+ "minimum": 1
128
+ },
129
+ "expectedStoreEpoch": {
130
+ "type": "string",
131
+ "minLength": 10,
132
+ "maxLength": 64
133
+ },
134
+ "writeRequestId": {
135
+ "type": "string",
136
+ "minLength": 8,
137
+ "maxLength": 128
138
+ }
139
+ }
140
+ },
141
+ "order": 28,
142
+ "route": {
143
+ "kind": "core",
144
+ "method": "revokeApproval",
145
+ "params": [
146
+ "$args"
147
+ ]
148
+ }
149
+ }
150
+ ]
151
+ };