@tomflow/chatloop-tools 0.9.20 → 0.9.22

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 (137) hide show
  1. package/node_modules/@tomflow/chatloop-context/README.md +240 -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 +266 -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 +182 -0
  14. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +277 -0
  15. package/node_modules/@tomflow/chatloop-context/index.mjs +233 -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 +24 -0
  18. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +1989 -0
  19. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +67 -0
  20. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +280 -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 +280 -0
  23. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +115 -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 +55 -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 +147 -0
  29. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +343 -0
  30. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +391 -0
  31. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +166 -0
  32. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +13 -0
  33. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +111 -0
  34. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +107 -0
  35. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +117 -0
  36. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +20 -0
  37. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +312 -0
  38. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +153 -0
  39. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +19 -0
  40. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +115 -0
  41. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +86 -0
  42. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +169 -0
  43. package/node_modules/@tomflow/chatloop-context/package.json +40 -0
  44. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +114 -0
  45. package/node_modules/@tomflow/chatloop-extension/README.md +94 -0
  46. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +11 -0
  47. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +141 -0
  48. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +109 -0
  49. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +1 -0
  50. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +1 -0
  51. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +1 -0
  52. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +1 -0
  53. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +1 -0
  54. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +1 -0
  55. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +1 -0
  56. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +1 -0
  57. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +1 -0
  58. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +120 -0
  59. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +180 -0
  60. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +322 -0
  61. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +2 -0
  62. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +378 -0
  63. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +2 -0
  64. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +54 -0
  65. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +9 -0
  66. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +20 -0
  67. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +69 -0
  68. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +287 -0
  69. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +23 -0
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +2 -0
  71. package/node_modules/@tomflow/chatloop-extension/extension/background.js +16 -0
  72. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +5 -0
  73. package/node_modules/@tomflow/chatloop-extension/extension/content.js +40 -0
  74. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +9 -0
  75. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +17 -0
  76. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +9 -0
  77. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +2 -0
  78. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +275 -0
  79. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +76 -0
  80. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +107 -0
  81. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +36 -0
  82. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +227 -0
  83. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +144 -0
  84. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +171 -0
  85. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +109 -0
  86. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +154 -0
  87. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +254 -0
  88. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +42 -0
  89. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +25 -0
  90. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +93 -0
  91. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +17 -0
  92. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +17 -0
  93. package/node_modules/@tomflow/chatloop-extension/extension/start.html +6 -0
  94. package/node_modules/@tomflow/chatloop-extension/extension/status.html +6 -0
  95. package/node_modules/@tomflow/chatloop-extension/extension/text.html +17 -0
  96. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +136 -0
  97. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +220 -0
  98. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +122 -0
  99. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +155 -0
  100. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +185 -0
  101. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +120 -0
  102. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +172 -0
  103. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +165 -0
  104. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +244 -0
  105. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +181 -0
  106. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +147 -0
  107. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +197 -0
  108. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +200 -0
  109. package/node_modules/@tomflow/chatloop-extension/index.mjs +71 -0
  110. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +18 -0
  111. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +74 -0
  112. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +208 -0
  113. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +40 -0
  114. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +45 -0
  115. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +111 -0
  116. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +67 -0
  117. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +120 -0
  118. package/node_modules/@tomflow/chatloop-extension/package.json +38 -0
  119. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +133 -0
  120. package/node_modules/@tomflow/chatloop-trace/README.md +105 -0
  121. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +23 -0
  122. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +22 -0
  123. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +4 -0
  124. package/node_modules/@tomflow/chatloop-trace/index.mjs +59 -0
  125. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +273 -0
  126. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +265 -0
  127. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +205 -0
  128. package/node_modules/@tomflow/chatloop-trace/package.json +30 -0
  129. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +68 -0
  130. package/node_modules/ps-list/index.d.ts +76 -0
  131. package/node_modules/ps-list/index.js +366 -0
  132. package/node_modules/ps-list/license +9 -0
  133. package/node_modules/ps-list/package.json +44 -0
  134. package/node_modules/ps-list/readme.md +56 -0
  135. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  136. package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
  137. package/package.json +10 -2
@@ -0,0 +1,182 @@
1
+ # Context npm package — actual interface, consumer and dependency map
2
+
3
+ > Applies to the **source** package `@tomflow/chatloop-context@0.6.1`.
4
+ > The connected MCP may still be running an earlier installed release.
5
+ > This document describes source contracts, not production cutover approval.
6
+
7
+ ## 1. Only two package entrypoints
8
+
9
+ | Physical path | npm entry | API classification | Access |
10
+ | --- | --- | --- | --- |
11
+ | `index.mjs` | `exports["."]` | Only module surface: Public SDK, pinned MCP adapter, trusted runtime and reviewed operator | `import {...} from '@tomflow/chatloop-context'` |
12
+ | `bin/cli.mjs` | `bin.chatloop-context` | Only executable surface | `chatloop-context <command>` from installed npm bin |
13
+
14
+ No `exports["./*"]`; all `lib/**` files are private source modules.
15
+ The two entrypoints are **forms of access**. Trust and authority remain
16
+ explicitly **separate** (import or CLI execution does not grant permission).
17
+
18
+ ## 2. Exact JavaScript exports from index.mjs
19
+
20
+ | Export | Returns / exposes | Provider implementation | Consumed by |
21
+ | --- | --- | --- | --- |
22
+ | `CONTEXT_CONTRACT` | method contract ID | `lib/methods.mjs` | Tools MCP gateway / SDK |
23
+ | `CONTEXT_PACKAGE_VERSION` | installed package version | `lib/methods.mjs` | Tools CLI result verification |
24
+ | `requestContext(args)` | authorized operation result | `lib/operations.mjs` → `lib/core/store.mjs` | Public SDK, CLI |
25
+ | `contextGateway` | namespace: `tools`, `validate`, `allowedProjects`, `cliPath` | `lib/methods.mjs`, `index.mjs` | Tools `lib/context-gateway.mjs`, `lib/context-control-run.mjs` |
26
+ | `loadTrustedRuntime()` | namespace: `execute(command,args,native)` | `lib/trusted-run.mjs` → private Core | Tools signed Native adapter |
27
+ | `loadLocalOperator()` | only `runLocalCliCommand()` | `lib/cli-commands.mjs` (other operator utilities private to root composition) | Context CLI only |
28
+ | `subscribeContextApiLog(listener)` | non-authoritative callback / unsubscribe | `lib/api-log.mjs` unified Proxy cut | Tools SDK root → Supervisor Trace Writer |
29
+
30
+ **Important:** `loadTrustedRuntime` and `loadLocalOperator` are callable
31
+ only by trusted adapters in the intended architecture, but JavaScript imports
32
+ **are not an OS security boundary**. Real authorization comes from signed
33
+ messages, same-UID boundaries, native session state, project grants, SQLite
34
+ access control, TTY reviews and Core's CAS/receipt checks.
35
+
36
+ ## 2.1 Build-time capability composition
37
+
38
+ `capabilities/<group>.mjs` owns the unique business method descriptors,
39
+ full Schema and execution route; `scripts/build-capabilities.mjs` generates
40
+ a static import manifest and a JSON method catalog. The root SDK composes
41
+ a generic capability router, rather than a per-method `switch`. API
42
+ documentation no longer parses implementation source. All original Core
43
+ CAS, authorization and receipt rules remain authoritative. Independent
44
+ new module routes are read-only and receive scoped read ports; new writers
45
+ require an explicitly reviewed transaction/receipt boundary.
46
+ No new runtime plugin loader, CLI entry or MCP service is introduced.
47
+
48
+ ## 3. Public business API and MCP exposure
49
+
50
+ The generated capability catalog served through `lib/methods.mjs` contains **34** current methods; redundant and legacy operations are removed outright. Each method is available through one of
51
+ exactly **two MCP tools**:
52
+
53
+ - **Read:** `chat_loop_context_get` — discovery, Project/Task,
54
+ document/evidence/history, authority, checkpoint and receipt reads.
55
+ - **Write:** `chat_loop_context_mutate` — guarded Project/Task,
56
+ R/P issue/approval, evidence, Start lease, Context patch and checkpoint.
57
+
58
+ `project.list` and `task.list` have one bounded page response shape,
59
+ including when `limit` is omitted (`limit=30`). No legacy array API exists.
60
+
61
+ Exact IDs, modes, input schemas and dispatch routes are owned by
62
+ `capabilities/<group>.mjs` and compiled into the package Method Catalog.
63
+ Call `sdk.methods.list` and `sdk.methods.describe` for the installed SDK
64
+ contract; this prose document is not a parallel API schema authority.
65
+
66
+ Ordinary MCP **never exposes** `permit.consume`, `run.bind.initial`,
67
+ `run.fence`, `run.bind.handoff` or other private Run/Permit actions.
68
+
69
+ ## 4. Provider → consumer matrix (actual source paths)
70
+
71
+ | Provider | API / action consumed | Actual consumer | Boundary and result |
72
+ | --- | --- | --- | --- |
73
+ | Context index — `contextGateway` | `tools, validate, allowedProjects, cliPath` | `packages/local-tools/lib/context-gateway.mjs` | Registers two MCP tools, validates args, spawns pinned executable without shell |
74
+ | Context CLI | `request --json` | Tools `lib/context-gateway.mjs` | One JSON request and one contract-versioned receipt per short-lived process |
75
+ | Context index — `contextGateway` | `allowedProjects` | Tools `lib/context-control-run.mjs` | Verifies Native Project ACL before trusted runtime is opened |
76
+ | Context index — `loadTrustedRuntime` | `execute(command,args,native)` | Tools `lib/context-control-run.mjs` | Signed, session-bound Supervisor IPC; Core Run/Permit CAS |
77
+ | Context CLI | `admin <action>` | Reviewed local operator | Single executable; private `lib/context-cli.mjs` interpreter is not an npm SDK API |
78
+ | Context MCP: Project | `project.authority/open/resolve/material.*` | Project Skill | Project binding, material identity, rules and authority |
79
+ | Context MCP: Review | `document.*`, `approval.*` | Workflow Stage 02/07 | Document issue and approval facts; user-turn capture is external |
80
+ | Context MCP: Task/Context | `task.open`, `context.resume/history/request.status` | Workflow Stage 03–06 | Recovery, checkpoint and UNKNOWN-safe action planning |
81
+ | Context MCP: Tools authorized Provider | `project.authority`, `task.list/open` | Tools `providers/context.mjs` and `lib/context-gateway.mjs` | No legacy Registry API or second business writer |
82
+ | Context CLI | `project init/register/bind`, `task fence-orphan` and others | Local reviewed operator | Filesystem/path, SourceUnit, TTY and durable evidence gates |
83
+ | Context CLI/package | packaged `index.mjs`, `bin/cli.mjs`, `lib/core/**` | Tools release/bundle | Exact file fingerprint verification; no npm subpath |
84
+
85
+ All 34 public operations and the Gateway/Trusted/Operator entrypoints pass the `lib/api-log.mjs` Context adapter backed by the **single public AOP implementation** exported from `@tomflow/chatloop-trace`; domain code does not implement logging. Tools maps payload-free events to Trace v2 fixed `event=context.api` and `api={name,surface,mode}`. Each call has its own `callId=spanId`; `traceId` is inherited from the verified correlation parent when available, otherwise equals `callId`. The SDK does not write a second log database. API observations never replace the SQLite CAS receipt.
86
+
87
+ The authoritative SQLite state owner is **Context Core**; Tools is an
88
+ adapter and Supervisor, not another Context database writer. The Chrome
89
+ Worker/Native is responsible for real Session Owner and browser actions.
90
+
91
+ ### Private execution chain (not an MCP method)
92
+
93
+ `Extension Worker → Browser Native Host (context-control) → signed
94
+ context-ipc.mjs → Tools Supervisor (context-control-run.mjs) →
95
+ loadTrustedRuntime() → Context Core → one Project SQLite`.
96
+
97
+ The Tools private handler passes a signed-IPC-verified Native projection into the Context trusted domain facade, which validates project binding, phase, RunRef and CAS. The private handler supports: `permit.consume`,
98
+ `run.bind.initial`, `run.fence`, `run.bind.handoff`,
99
+ `run.restore-same-owner`, `run.fence.terminal`,
100
+ `run.credential.rotate`, `run.terminalStatus`,
101
+ `run.reopenStatus`, `run.snapshot`.
102
+
103
+ The Browser Native Host now permits the Worker-used `run.reopenStatus`
104
+ through the same signed private IPC path; it is not a public MCP method.
105
+
106
+ ## 5. Context → external dependencies (reverse direction)
107
+
108
+ | External owner / dependency | Context call, file or mechanism | Source | Coupling and scope |
109
+ | --- | --- | --- | --- |
110
+ | **Node built-ins** (not an npm dependency) | `node:sqlite`, `node:crypto`, `node:fs`, `node:path`, `node:os`, `node:child_process`, `node:readline/promises`, `node:module/url` | `lib/core/store.mjs`, migration, admin, orphan etc. | SQLite/file security, transactions, hashes, backups, TTY, system checks |
111
+ | **Extension API (declared npm dependency)** | `verifyOrphanOwnerIdle({oldRunRef,projectId})` | `lib/orphan-operator.mjs` → `@tomflow/chatloop-extension` | Official provider verifies its own Native Session and live Extension IDLE, returning bounded evidence |
112
+ | **Process provider (declared npm dependency)** | `psList({all:false})` | `lib/process-inventory.mjs` → `ps-list` | Observable known MCP processes only; snapshots do not authorize migration cutover |
113
+ | **Context Store** | Project-local `context.sqlite` via `lib/project-store.mjs` | `lib/operations.mjs`, `lib/core/store.mjs` | Authoritative State + receipt; **not** a cross-module API |
114
+
115
+ `packages/context/package.json` declares exactly two runtime dependencies:
116
+ `ps-list` for bounded process observation, and
117
+ `@tomflow/chatloop-extension` for its official Owner evidence API.
118
+ All remaining file/SQLite/crypto APIs are provided by Node. This is an
119
+ explicit Provider→Consumer edge: Context no longer constructs the
120
+ Extension install path or reads the Extension-owned Session file directly.
121
+ A process snapshot is never equivalent to a durable stop/fence receipt.
122
+ The migration functions no longer accept a caller-supplied `knownWriters`
123
+ bypass; privileged operator and persistent-state checks remain mandatory.
124
+
125
+ ## 6. Core source ownership (one transaction authority)
126
+
127
+ | File | Responsibility |
128
+ | --- | --- |
129
+ | `lib/core/store.mjs` | Open/verify single SQLite DB, schema, WAL, mode, shared auth/CAS/receipt/transaction context |
130
+ | `lib/core/health.mjs` | Store diagnostics, terminal/reopen status, latest checkpoint |
131
+ | `lib/core/migration.mjs` | SourceUnit classification/reconciliation/cutover transactions |
132
+ | `lib/core/project.mjs` | Project identity, authority, Material versions and writes |
133
+ | `lib/core/task.mjs` | Task status, revision and lifecycle |
134
+ | `lib/core/review.mjs` | R/P documents, presentation evidence and approvals |
135
+ | `lib/core/evidence.mjs` | Task evidence references |
136
+ | `lib/core/context.mjs` | Context history, request receipt, UNKNOWN handling, checkpoints and resume |
137
+ | `lib/core/run.mjs` | Lease, Permit, credential, bind/fence/handoff/orphan controls |
138
+
139
+ The root `index.mjs` injects domain factories into Store API ports. `store.mjs`
140
+ assembles them using a **single shared SQLite handle**. Implementation modules
141
+ never import each other; no extra database, service, Owner controller, or
142
+ independent commit/receipt writer is created.
143
+
144
+ ## 7. Final-version decisions and exclusions
145
+
146
+ - **No subpath exports or compatibility forwarding modules**; direct
147
+ imports of `lib/*` across npm package boundaries are prohibited.
148
+ - The identical `context.open` alias is gone; `project.open` is the
149
+ single bounded Project summary. No raw `project.get` / `task.get`
150
+ projection is published; consumers use `project.open` / `task.open`.
151
+ - Migration and SourceUnit safeguards remain private to Operator/Core;
152
+ they do **not** create legacy public MCP methods or compatibility aliases.
153
+ - The package exports **no** Extension/Trace/Tools private implementation
154
+ path; Native/Tools import **only `@tomflow/chatloop-context`**.
155
+ - No npm publish, production migration, Chrome E2E or Owner change is
156
+ implied by this source refactor.
157
+
158
+ ## 8. Removed/unneeded exports
159
+
160
+ The root Local Operator namespace contains **one** CLI entry function (`runLocalCliCommand`); all other operator functions are private to root composition. The root Trusted Runtime namespace is now **one** `execute` method (was raw Core / path resolver / credential generator). The CLI `project reconcile-receipt` duplicate command is removed; use `project migration-receipt`.
161
+
162
+ The redundant `chatloop-tools context` command is removed; operators must use the single `chatloop-context admin <action>` entry instead. This does not change Store approval, TTY or migration guards.
163
+
164
+ ## 9. Enforced implementation boundary (source-level)
165
+
166
+ ```text
167
+ @tomflow/chatloop-context
168
+ index.mjs [only npm SDK import entry + API composition]
169
+ |-- Business SDK tier -> Core / project-store / operations
170
+ |-- Trusted tier -> Run/Permit API (signed IPC caller)
171
+ +-- Operator tier -> migration / workspace / cli-commands
172
+ bin/cli.mjs [only npm executable entry]
173
+ +-- index.mjs -> loadLocalOperator().runLocalCliCommand()
174
+ lib/** [private modules, named injected capability contracts]
175
+ +-- Node built-ins / explicitly declared external providers only
176
+ ```
177
+
178
+ - Forbidden: `lib/a.mjs` importing `lib/b.mjs`, reverse-importing the npm root from private modules, and `bin/cli.mjs` bypassing the root SDK to import private modules.
179
+ - Allowed: the sole root `index.mjs` loads implementations and injects named capability functions into each module exactly once, with lazy SDK, Trusted and Operator tiers.
180
+ - SQLite ownership: `core/store.mjs` creates the only Store handle and coordinates transaction/CAS/receipt authority. The domain factories receive one shared connection, not separate writers.
181
+ - Security: direct import or dependency injection never grants ACL, operator TTY, Native Owner, signed IPC, or write access.
182
+ - Regression: `test/module-boundary.test.mjs` enforces both npm entrypoints, bans private-module imports, and verifies assembled capability counts and absence of raw SQLite exports. Context/Tools/Native integration tests protect behavior. Node 20 retains catalog discovery without loading SQLite.
@@ -0,0 +1,277 @@
1
+ # Context local operator, Legacy and migration procedures (historical reference)
2
+
3
+ This preserves the previous detailed operator/migration procedures. For the current SDK entry,
4
+ Node/runtime requirements, API discovery and up-to-date contract links, begin with [README](../README.md).
5
+ Do not treat older version examples, readiness labels or production-blocked statements below as
6
+ current deployment facts; verify the live connected SDK and SourceUnit authority.
7
+
8
+
9
+ Independent Context SDK. Method Catalog supports Node >=20; CLI/Core require Node >=24. Chat Loop Tools and other explicitly
10
+ authorized local adapters use the same versioned Method Catalog and SQLite Core.
11
+ This package is not a Chrome controller, HTTP service or background process.
12
+
13
+ ## Project data (target layout, not a production cutover)
14
+
15
+ Each explicitly registered project has one SQLite source of truth:
16
+ ~/.chat-loop/context/<projectId>/context.sqlite
17
+
18
+ Optional artifacts/ and backups/ live beside it; no competing project.json,
19
+ current.md, history.md or handoff.md. The user's source repository and AGENTS.md
20
+ are NOT managed or modified by Context. A project may reference authorized
21
+ Workspace roots via Project.sharedContext.workspaceRefs.
22
+
23
+ ## SDK method disclosure
24
+
25
+ Use:
26
+ chatloop-context methods list --json
27
+ chatloop-context methods describe project.open
28
+
29
+ Both use lib/methods.mjs, the same catalog that generates ChatGPT MCP inputSchema.
30
+ No hidden run.bind/fence/permit controls are exposed as ordinary SDK methods.
31
+
32
+ Example after an approved pinned installation (future release, not yet published):
33
+ npx --yes --offline --package=@tomflow/chatloop-context@0.1.0 chatloop-context methods list --json
34
+
35
+ Requests take one bounded JSON object from stdin and emit one JSON object on
36
+ stdout. Never place credentials or sensitive project bodies in CLI args or logs:
37
+ echo '{"operation":"sdk.methods.list","group":"project"}' | chatloop-context request --json
38
+
39
+ A trusted local adapter supplies CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS and, if
40
+ needed, CHAT_LOOP_CONTEXT_ROOT (default ~/.chat-loop/context) or an explicit
41
+ CHAT_LOOP_CONTEXT_DB solely for existing legacy Store compatibility.
42
+ The comma-separated Project grant is parsed atomically: invalid, empty or
43
+ duplicate IDs reject the whole grant, including in MCP and Native adapters.
44
+ Use project.list/task.list with limit (1–100) and cursor for bounded pages;
45
+ omitting both keeps the legacy array return. A page is not a cross-request
46
+ snapshot; verify revisions when resuming after concurrent writes.
47
+
48
+ ## Reviewed Project registration and Workspace ownership (local operator)
49
+
50
+ The local operator must explicitly enable admin scope, choose the permitted
51
+ Project IDs, and use an **interactive terminal**. The user-reviewed entry
52
+ validates real canonical directories and prompts for an exact action+scope
53
+ confirmation BEFORE creating a Store:
54
+
55
+ CHAT_LOOP_CONTEXT_ADMIN_ENABLE=1 \
56
+ CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS=demo \
57
+ chatloop-context project register demo "Demo project" /confirmed/workspace
58
+
59
+ Additional Workspace roots may be supplied to `register` (up to 16).
60
+ Registration uses a global per-Context-root lock, rejects symlink roots,
61
+ nested/overlapping roots and previously claimed roots, and atomically renames
62
+ a newly staged per-Project SQLite. An existing Project is never overwritten.
63
+
64
+ To replace the **whole** Workspace set on an existing Project, first call
65
+ `project.open` and read its projectRevision and storeEpoch, then explicitly
66
+ run the local operator command (with the same admin grant and TTY confirmation):
67
+
68
+ chatloop-context project bind demo <revision> <storeEpoch> <writeRequestId> /root/a /root/b
69
+ chatloop-context project bind demo <revision> <storeEpoch> <writeRequestId> --clear
70
+
71
+ The second command explicitly clears every Workspace binding. A bind checks
72
+ the original Project identity, CAS revision/epoch, global Project ownership,
73
+ path stability, active execution/Handoff writer fences, then writes one durable
74
+ Core receipt. If the CLI result is lost, use the **same** request ID for a
75
+ read-only operator lookup, never repeat the mutation with a different ID:
76
+
77
+ chatloop-context project receipt demo <storeEpoch> <writeRequestId>
78
+
79
+ The older `project init` remains an explicit *local-admin* compatibility
80
+ command for already approved automated setup; it does **not** itself collect
81
+ a real user-review prompt and must not be offered as the normal first-use flow.
82
+ None of these commands are exposed as ordinary model Context MCP mutations.
83
+ A local TTY/OS-UID operator approval is not cryptographic ChatGPT user
84
+ authentication. Without explicit user authorization, do not infer independent
85
+ approval or claim a completed in-Chat self-service onboarding. For a user-
86
+ delegated Agent migration, label the operator `USER_DELEGATED_AGENT` and retain
87
+ the exact verified source/backup/revision evidence; never describe this as an
88
+ independent human or platform-authenticated approval. None of these operations
89
+ grant Chrome Owner or migrate an existing Legacy Store by themselves.
90
+
91
+ ## Offline shared Store extraction (diagnostic ONLY, not a cutover)
92
+
93
+ Before a cutover, use the **read-only** source integrity audit with an explicitly
94
+ granted Project and a verified old Store epoch:
95
+
96
+ CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS=demo \
97
+ chatloop-context project audit-sources demo /private/old/shared.sqlite <sourceEpoch>
98
+
99
+ To inspect a Registry task document that changed since shadow scan, point to
100
+ a verified private Recovery Archive copy of the **original** document:
101
+
102
+ chatloop-context project inspect-reference demo /private/old/shared.sqlite \
103
+ <sourceEpoch> <sourceUnitId> <taskId> /private/archive/task-document.md
104
+
105
+ This is a read-only two-version evidence check: exact Registry SHA and
106
+ task identity, archived document SHA, current document SHA, and a bounded
107
+ insertions-only vs changed-content comparison. It outputs a review-required
108
+ receipt (not a stored approval); `canActivate` and `canExecute` remain false.
109
+ Never rewrite the old Registry to suppress drift.
110
+
111
+ **Reviewed local reconciliation (not SourceUnit activation):** after independently
112
+ reviewing the exact original archive, current document, Project scope and old
113
+ writers, a local terminal operator may run:
114
+
115
+ CHAT_LOOP_CONTEXT_ADMIN_ENABLE=1 CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS=demo \
116
+ chatloop-context project reconcile-reference demo /private/old/shared.sqlite \
117
+ <epoch> <sourceUnitId> <migrationRevision> <taskId> <originalArchiveFile> \
118
+ <currentDocSha256> <operatorReviewRef> <writeRequestId>
119
+
120
+ A real TTY is required and the exact source/old/new hashes and review reference
121
+ must be confirmed. Only insertions-only Task document drift is admitted; other
122
+ content changes need separate review. The Core uses epoch, migration revision
123
+ and durable request receipts, keeps original and current SHA plus original
124
+ archive locator in the SourceUnit, leaves the Registry file unchanged and
125
+ keeps the SourceUnit in SHADOW_RO. It cannot create R/P approvals or Browser
126
+ Owner, or assert the independent old-writer / user-authentication gates.
127
+ For an uncertain result, **query** with the same ID, never resubmit with a new ID:
128
+
129
+ chatloop-context project migration-receipt demo /private/old/shared.sqlite \
130
+ <epoch> <writeRequestId>
131
+
132
+ This interface is a local-operator entry; a TTY under one OS UID is not
133
+ proof of platform-authenticated ChatGPT user approval. By default an autonomous
134
+ agent MUST NOT infer an independent operator decision. When the user expressly
135
+ delegates the precise migration scope in the current conversation, the agent
136
+ may operate the existing TTY path as a **disclosed user-delegated local agent**,
137
+ with exact SourceUnit/hash/revision checks and an immutable private delegation
138
+ audit record. Record `USER_DELEGATED_AGENT`, never `INDEPENDENT_HUMAN` or
139
+ platform-authenticated consent. This delegation does not approve R/P or Owner.
140
+ The audit reads source bytes and Registry-linked Task documents, checks exact
141
+ Project Material hash/path coverage, and distinguishes a changed Registry
142
+ file from drift in a linked task document. Its CLI receipt also includes
143
+ `supportedWriterObservation: {status,pids}` from the same bounded process
144
+ inventory used by `activate` (PID only; never argv). `MATCHED` reports a known
145
+ writer still running; `NO_SUPPORTED_PROCESS_MATCH` is **not proof** that all
146
+ legacy writers were independently fenced, and `UNVERIFIED` means the process
147
+ scan itself failed. It reports mixed CURRENT items still requiring human
148
+ classification, without revealing historical document bodies or treating a
149
+ recovered user Turn as fresh approval. Its `BLOCKED` status intentionally
150
+ includes independent old-writer fencing and release/E2E gates that a local
151
+ file scan cannot prove. It never creates a Store or modifies SourceUnits,
152
+ revisions, permissions, Owner or approvals.
153
+
154
+ **Mixed CURRENT EvidenceOnly classification (local operator only):** when
155
+ the complete, exact historical Markdown bytes are already stored as a
156
+ `LEGACY_UNVERIFIED` Project Material under the canonical source path/hash,
157
+ the operator may explicitly classify a mixed source as historical evidence
158
+ without promoting ANY text to a current Project/Task/R/P fact:
159
+
160
+ CHAT_LOOP_CONTEXT_ADMIN_ENABLE=1 CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS=demo \
161
+ chatloop-context project classify-evidence demo /private/old/shared.sqlite \
162
+ <epoch> <sourceUnitId> <migrationRevision> <sourceSha256> \
163
+ <operatorReviewRef> <writeRequestId>
164
+
165
+ The preflight verifies the physical SourceUnit and the complete stored body,
166
+ and requires exact interactive terminal confirmation. Only the Core's
167
+ `migrationClassify` mutates the SourceUnit manifest with
168
+ `taskContexts=[]`, `projectSharedContext={}` and a reference to the
169
+ entire original content as EvidenceOnly/UNKNOWN; the Unit stays SHADOW_RO.
170
+ This is an intentional human-reviewed historical *disposition*, not a
171
+ claim that the historical statements are current or approved. It does not
172
+ activate a Store, release an old writer, or authorize Chrome Owner.
173
+ For an unknown result use `project migration-receipt` with original epoch and
174
+ writeRequestId. Local TTY is not ChatGPT platform user authentication.
175
+
176
+ An older single SQLite may contain several Projects. Never copy or rename it
177
+ directly into the active per-Project location: doing so leaks unrelated data,
178
+ reuses the old epoch and risks reviving stale runs. The local operator can
179
+ first inspect the legacy Store read-only to obtain the **exact** source
180
+ `storeEpoch` and target `projectRevision`, then, on a separate private
181
+ target root and with explicit real TTY confirmation, use:
182
+
183
+ CHAT_LOOP_CONTEXT_ROOT=/private/review-target \\
184
+ CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS=demo \\
185
+ CHAT_LOOP_CONTEXT_ADMIN_ENABLE=1 \\
186
+ chatloop-context project stage-diagnostic demo /private/old/shared.sqlite <sourceEpoch> <projectRevision>
187
+
188
+ This action reads the source through a SQLite online snapshot, selects ONLY
189
+ the named Project and its scoped rows, retains their exact Task/Material/
190
+ SourceUnit history and old-epoch receipts, then strips runnable leases,
191
+ permits and writer credentials. It vacuums foreign Project content from the
192
+ new database and checks the physical row counts, integrity and ownership
193
+ before atomically publishing the result. A private `migration-diagnostic.json`
194
+ receipt names the old/new epochs and counts but is **not** a second active
195
+ Context authority or a retained full-Store backup.
196
+
197
+ The resulting Project is always `DIAGNOSTIC_ONLY`, with a new epoch,
198
+ `canExecute=false` and `approvalsRevalidated=false`. Old receipts cannot
199
+ replay under the new epoch. No SourceUnit becomes `MANAGED_RW`, and no
200
+ Task/Run, browser Owner or previously observed R/P approval gains authority.
201
+ The source is left untouched. An invalid SourceUnit, unexpected schema,
202
+ stale revision, missing operator approval or existing target fails closed;
203
+ incomplete staging is removed. This command is not exposed through MCP.
204
+
205
+ ## Reviewed single-Project release (local operator, not MCP)
206
+
207
+ A diagnostic branch is **never** promoted. A separate terminal-only release
208
+ works exclusively with an already reviewed legacy SQLite containing **exactly
209
+ one Project**. The existing `project audit-sources` must show source hashes,
210
+ reference checks, mixed evidence and bodies reviewed, and every SourceUnit
211
+ must already be `MANAGED_RW`. All known Gateway writers must be stopped, any
212
+ unknown legacy clients independently fenced, and all running Task leases/
213
+ permits/UNKNOWN effects reconciled before sealing. If any requirement fails,
214
+ do not run these commands.
215
+
216
+ With `CHAT_LOOP_CONTEXT_ADMIN_ENABLE=1` and a single explicit Project grant,
217
+ and **without** `CHAT_LOOP_CONTEXT_DB`, the local operator first confirms
218
+ the exact source Epoch/revision, backup path and output receipt in a real TTY:
219
+
220
+ chatloop-context project seal-source <projectId> <sourceDb> <epoch> \
221
+ <projectRevision> <privateBackup.sqlite> <privateSeal.json>
222
+
223
+ Sealing makes a fresh private SQLite online backup, verifies the source again
224
+ under an exclusive write transaction, and durably sets the single old Store
225
+ to `CUTOVER_FENCED`. The old Store then rejects ordinary and internal writes
226
+ even when the old Epoch is supplied. This is **not** SourceUnit approval and
227
+ does not restore any Browser Owner. If the command reports UNKNOWN, inspect
228
+ the old Store mode and original private receipt; never remove the fence or
229
+ retry with a new Project/backup path.
230
+
231
+ Only when the seal receipt and its SHA-256 are independently verified, the
232
+ operator may separately confirm:
233
+
234
+ chatloop-context project publish-managed <projectId> <sourceDb> <epoch> \
235
+ <projectRevision> <privateSeal.json> <sealSha256>
236
+
237
+ Publication accepts only a sealed, **single-Project** source, exact backup
238
+ hash, unchanged logical source hash, all reviewed SourceUnits and no known
239
+ live MCP writer. It creates a new-Epoch `ACTIVE` single-Project SQLite under
240
+ the canonical Context root, with an atomic directory rename, zero foreign
241
+ projects, zero runnable permits/leases and **zero inherited R/P approvals or
242
+ run credentials**. The original old Store stays `CUTOVER_FENCED`; no dual
243
+ write. The published Project can use Context business writes, but its old
244
+ approvals are untrusted: Workspace binding and **fresh** R/P presentation,
245
+ confirmation, Native Owner and Chrome E2E must each be validated separately.
246
+ The response deliberately sets `canExecute:false`.
247
+
248
+ If publication fails after sealing, preserve the sealed source, existing
249
+ private backup and seal receipt for offline recovery; never copy/rename a
250
+ `DIAGNOSTIC_ONLY` Store into production or flip `storeMode` directly.
251
+ The CLI rejects non-TTY callers and the module is not exposed via ordinary
252
+ MCP. Same-UID local terminal confirmation alone is **not** proof of an
253
+ independent ChatGPT user authorization. Exception: a current explicit user
254
+ instruction can delegate a specific Project cutover to an Agent, which may
255
+ operate the local TTY as `USER_DELEGATED_AGENT` after recording the source
256
+ identities, hashes, revisions, physical writer fence, backup and restoration
257
+ evidence. The resulting review is delegated, **not independently human-verified**.
258
+ Do not weaken the actual Core CAS, offline backup, old-writer check, Legacy
259
+ fence, R/P approval, UNKNOWN-send or browser Owner guards.
260
+
261
+ **Production remains BLOCKED** until the physical source hashes, mixed
262
+ CURRENT ownership, old writers and true operator approval have been reviewed,
263
+ old app/Native/Registry clients fenced, fresh backup plus recovery tested and
264
+ the release/real Chrome E2E gates passed. See P0-02 in
265
+ `docs/research/chat-loop-context-cli-architecture-20261109.md`.
266
+
267
+ ## Safety
268
+
269
+ Writes use expectedStoreEpoch, revision CAS and durable writeRequestId.
270
+ Unknown results must be checked with the SAME request ID; never blindly
271
+ resubmit with another ID. Active-run holder controls live outside ordinary
272
+ MCP/CLI mutations in the restricted Worker→Native adapter. An SDK business
273
+ checkpoint never grants Browser Owner. One OS UID is not per-Chat isolation.
274
+
275
+ No serve, Socket, HTTP API, second Tunnel or per-project daemon. The real
276
+ legacy Context and UNKNOWN Chrome Owner remain unchanged until explicit
277
+ migration and recovery approval.