@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.
- package/node_modules/@tomflow/chatloop-context/README.md +296 -0
- package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +48 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +151 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +376 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +290 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +134 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +82 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +349 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +72 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +73 -0
- package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +507 -0
- package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +11 -0
- package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +261 -0
- package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +277 -0
- package/node_modules/@tomflow/chatloop-context/index.mjs +238 -0
- package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +86 -0
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +77 -0
- package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +2036 -0
- package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +69 -0
- package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +338 -0
- package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +298 -0
- package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +286 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +117 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +51 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +134 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +262 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +246 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +180 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/run-cancel.mjs +68 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/run-recovery.mjs +112 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +367 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +398 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +264 -0
- package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +13 -0
- package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +111 -0
- package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +107 -0
- package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +118 -0
- package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +20 -0
- package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +316 -0
- package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +153 -0
- package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +19 -0
- package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +117 -0
- package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +142 -0
- package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +169 -0
- package/node_modules/@tomflow/chatloop-context/package.json +38 -0
- package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +114 -0
- package/node_modules/@tomflow/chatloop-extension/README.md +190 -0
- package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +13 -0
- package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +168 -0
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +246 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/entry_test.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/session.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +123 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +183 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +390 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +2 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/entry_test.js +241 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff-scoped.js +143 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +399 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +2 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +60 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +9 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +20 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +77 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/session.js +95 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +329 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +38 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +2 -0
- package/node_modules/@tomflow/chatloop-extension/extension/background.js +33 -0
- package/node_modules/@tomflow/chatloop-extension/extension/clean.html +5 -0
- package/node_modules/@tomflow/chatloop-extension/extension/content.js +40 -0
- package/node_modules/@tomflow/chatloop-extension/extension/continue.html +9 -0
- package/node_modules/@tomflow/chatloop-extension/extension/dom.html +17 -0
- package/node_modules/@tomflow/chatloop-extension/extension/entry_test.html +6 -0
- package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +9 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +2 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +275 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +84 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +107 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +36 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +299 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +144 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +172 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +109 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +211 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/resource-maintenance.js +159 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +399 -0
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +43 -0
- package/node_modules/@tomflow/chatloop-extension/extension/popup.html +25 -0
- package/node_modules/@tomflow/chatloop-extension/extension/popup.js +99 -0
- package/node_modules/@tomflow/chatloop-extension/extension/reload.html +17 -0
- package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +17 -0
- package/node_modules/@tomflow/chatloop-extension/extension/session.html +7 -0
- package/node_modules/@tomflow/chatloop-extension/extension/start.html +6 -0
- package/node_modules/@tomflow/chatloop-extension/extension/status.html +6 -0
- package/node_modules/@tomflow/chatloop-extension/extension/text.html +17 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +136 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +218 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +127 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +296 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +186 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +126 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +287 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +163 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +345 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +209 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +385 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/session-control.js +75 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-action-v2.js +278 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-cancel-recovery-v2.js +52 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-cancel-v2.js +93 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-continue-recovery-v2.js +78 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-handoff-recovery-v2.js +148 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-handoff-v2.js +325 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-hold-recovery-v2.js +109 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-intent-dispatch-v2.js +220 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-intent-v2.js +106 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-owner-resolver.js +110 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-recover-v2.js +209 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-routes-v2.js +357 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-run-store.js +400 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-scheduler.js +78 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-start-v2.js +361 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/task-terminal-v2.js +235 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +197 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +205 -0
- package/node_modules/@tomflow/chatloop-extension/index.mjs +78 -0
- package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +19 -0
- package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +82 -0
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +378 -0
- package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +89 -0
- package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +45 -0
- package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +122 -0
- package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +75 -0
- package/node_modules/@tomflow/chatloop-extension/lib/owner-kernel-lock.mjs +106 -0
- package/node_modules/@tomflow/chatloop-extension/lib/owner-ledger.mjs +316 -0
- package/node_modules/@tomflow/chatloop-extension/lib/owner-locked-write.mjs +30 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-cancel-v2.mjs +190 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-continue-v2.mjs +214 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-handoff-v2.mjs +338 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-native-control.mjs +398 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-recovery-v2.mjs +234 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-retire-v2.mjs +70 -0
- package/node_modules/@tomflow/chatloop-extension/lib/scoped-terminal-v2.mjs +143 -0
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +228 -0
- package/node_modules/@tomflow/chatloop-extension/package.json +36 -0
- package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +138 -0
- package/node_modules/@tomflow/chatloop-trace/README.md +118 -0
- package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +23 -0
- package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +22 -0
- package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +4 -0
- package/node_modules/@tomflow/chatloop-trace/index.mjs +59 -0
- package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +273 -0
- package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +308 -0
- package/node_modules/@tomflow/chatloop-trace/lib/trace-retention.mjs +140 -0
- package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +236 -0
- package/node_modules/@tomflow/chatloop-trace/package.json +28 -0
- package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +68 -0
- package/node_modules/ps-list/index.d.ts +76 -0
- package/node_modules/ps-list/index.js +366 -0
- package/node_modules/ps-list/license +9 -0
- package/node_modules/ps-list/package.json +44 -0
- package/node_modules/ps-list/readme.md +56 -0
- package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
- package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
- package/package.json +12 -4
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# @tomflow/chatloop-extension
|
|
2
|
+
|
|
3
|
+
Chrome MV3 companion for Chat Loop. **Browser Worker is the only Chrome Owner and
|
|
4
|
+
send authority**; Native Messaging is a guarded persistence/IPC boundary,
|
|
5
|
+
not a second browser executor.
|
|
6
|
+
|
|
7
|
+
## Runtime entrypoints
|
|
8
|
+
|
|
9
|
+
- `index.mjs`: npm SDK with `verifyOrphanOwnerIdle`, `extensionCliApi`,
|
|
10
|
+
`nativeHostApi` — the only three exported functions.
|
|
11
|
+
- `bin/cli.mjs`: the `chatloop-extension` CLI (`npx` after publishing).
|
|
12
|
+
- `bin/native-host.mjs`: private Chrome Native Messaging Host process.
|
|
13
|
+
- `extension/background.js`: MV3 Worker and unique Browser Owner.
|
|
14
|
+
- `extension/actions/*.js`: Action executors; browser APIs are not Node SDKs.
|
|
15
|
+
|
|
16
|
+
## V2 Task-first 多任务源码升级(未发布、未运行验收)
|
|
17
|
+
|
|
18
|
+
新增 `lib/owner-ledger.mjs`:当前 OS 用户内的 Task 级 Native Chat Claim/CAS 注册表(**跨 Chrome Profile、账户绑定尚未实证**),独立于 Context 业务真源;`extension/worker/task-run-store.js`:TaskKey 寻址状态;`task-scheduler.js`:有界逐 Task 串行与公平调度;`task-owner-resolver.js`:将 Observer 来源的 Tab/Chat 与当前 Native Claim、Context writer 只读核对。Native Host 的 `lib/scoped-native-control.mjs` 与 Tools Supervisor 的精确 Ledger/HMAC 路径已在**临时 SQLite + Native IPC** 中验证两个 Task 各自的 Start Permit、Native Claim 和 `run.bind.initial`。旧 V1 Native Session 与 V2 使用同一锁,V2 活跃时 V1 Worker 写入拒绝;共享 Chat/Action 资源账本已能按多个 Task 快照计算物理容量而不放开上限。
|
|
19
|
+
|
|
20
|
+
**现行安装版 V1 与本地未发布 V2 源码不能混为一谈。** 本地已写入 Task-scoped Adopt、Model Intent、Continue、Handoff、DONE/BLOCKED、空闲取消、精确 Status 和终态保留的实际 Source Producer/Consumer,但尚未执行类型检查、单测、构建、真实 Native/Chrome/Context E2E 或发布;**任何步骤均不宣告 PASS / ENABLED**。V2 的 UNKNOWN/Recovery 仍必须只查原请求、不自动重发;跨 Chrome Profile Owner 归属与切流还没有真实证据。
|
|
21
|
+
|
|
22
|
+
### Task Store/Owner Resolver 源码合同(2026-11-27,未运行用例)
|
|
23
|
+
|
|
24
|
+
- `task-run-store.js` 以 `(projectId,taskId)` 作为唯一槽位,校验同 Chat、同 Chrome tab 的活跃 Claim 不重复;Phase 不允许从已消费 Start 的 `PENDING` 倒退到 `RESERVED`,也不能以普通状态更新直接从 `WAITING_REPLY` 重入 `PENDING`;正式 Continue 必须由独立的原 Turn Token、一次性 Context Permit 和 Native CAS 证明;Worker 的 `BLOCKED` 仅可在精确 `CONTEXT_HANDOFF_RECOVERED` 或已有的独立取消 CAS 合同下转出,普通 Store 修改绝不复活为 `WAITING_REPLY`;已绑定 Owner 的 `WAITING_REPLY` 必须有有效的正整数 Chrome tab ID;一旦 Start/Handoff 持久化 Chat 的 `startedAt/deadlineAt`,Task Store 只验证起点/截止结构、顺序和四小时上限;**相对当前时间**的未来起点(如系统时钟回拨)由精确 Task Owner Resolver 及原 Continue/Handoff Action 单独拒绝、Task Status 只读显示 `FENCED_UNCERTAIN`。绝不能因 A 的时间问题在校验整个共享 Store 时阻断 B;实际窗口仍只由原 `policy.windowMsOf` 计算。每个 Task 的 `runRevision` 是该任务的写入 CAS,其他 Task 的修改只推进全局存储提交序号,不造成无关任务的 CAS 拒绝;`expectedStoreRevision` 仍要求是有效且不超前的存储序号。所有写入由唯一 Worker 内的同一队列短序列化并合并到最新快照,跨 Task 的同 Chat/Tab 冲突依然拒绝。正式 Continue/Handoff Permit、PENDING→WAITING_REPLY、WAITING_REPLY→DONE、Handoff generation 切换的 Native Session Revision 必须精确 +1;空闲取消从 BLOCKED 至 CANCELLED 的原 Native 总修订须精确 +2;不可用更晚的其它 Owner 修订冒领本次结果。此存储只是一份 Worker 观察快照,不能授予发送权。
|
|
25
|
+
- `CHAT_LOOP_TASK_TURN_OBSERVED_V2` 是**仅限扩展自身顶层 ChatGPT Observer** 的受控 Worker 消息:请求只含 `type,page,userKey,assistantKey,outcome,pendingConfirmation`(无正文、无许可证);Worker 从可信 `sender.tab.id/sender.url` 推导 Task,拒绝非顶层 Frame、来源不匹配、额外字段与不合规标识,复核 Native 与 Context Writer 后,正常观察返回 `{status:'OBSERVED',code:'TASK_SCOPED_OBSERVER_VERIFIED',scope:'TASK_SCOPED_OBSERVATION_ONLY'}`,仅存精简 User/Assistant ID、状态标记和时间;`DONE/BLOCKED` 再调用精确 Native/Context 终态证明后才允许转为业务终态回执。未携带本 Task 已登记意图的普通观察**不创建 Action、不发送消息、不授予许可**;只有当前 Task 已签发 `modelIntent`,且 Observer 的原 User/Assistant Turn 与最后状态再次双读匹配,才允许唯一 Worker 从 `task-intent-dispatch-v2.js` 创建原有 Action 页;创建并不等于发信授权。Worker 没有活跃 V2 Task 时直接回 `UNSCOPED/SCOPED_OBSERVER_TASK_NOT_FOUND`,不以 V2 格式要求破坏既有 V1 Observer;存在 V2 Task 时只有精确 Tab 未绑定才能返回同样的只读 `UNSCOPED`,旧 Observer 才沿原 `CHAT_LOOP_TURN_FINISHED_V1` 路径交付完整旧回执;其它 `DENIED/BLOCKED/UNVERIFIED` 或不认识的显式 V2 回执一律不降级为 V1 发送;`TURN_BLOCKED` 故障路由同样仅在精确 `UNSCOPED` 或旧 Worker 没有回执时回退,不能把新 Worker 的 `TASK_SCOPED_ROUTE_UNKNOWN` 拒绝冒作旧协议。老 Worker 没有该 V2 路由导致只读探测无回执/传输拒绝时,Observer 仅将原 V1 事件交付**一次**;该 V1 事件的后续实际副作用仍必须通过当前 Worker/Native 独立围栏。V2 返回明确 `BLOCKED/DENIED` 时不会降级;旧版 Worker 与活跃 V2 Native 混合部署的安全性不能仅凭源码视为已证明,必须在发行门禁中禁止混版切流。没有第二 Worker 或 npm SDK 出口;原消息被 Worker 统一 AOP 包裹。本轮只修改源码与 README,尚未做接口回归。
|
|
26
|
+
- `task-owner-resolver.js` 从 Observer 的实际 `sender.tab.id`、当前 tab URL 和 Chat ID 定位精确 Task;先核 Native Ledger 的 Session/Generation/Revision,再只读核 Context 当前 Writer;Native 的只读 `session-snapshot-v2` 包含完整规范 `activeChatUrl`,Resolver 需要它与 `https://chatgpt.com` 加上 Observer 原 Chat 路径严格一致(允许实际 tab URL 带查询参数,但绝不跨 Chat/项目路径借用相同 Chat ID;正式 Task-first Handoff Action 在旧 Chat 领取 Permit 后也按原 Tab ID + `https://chatgpt.com` origin + 精确 pathname 复核,不能因同 Chat 的查询参数误入 `NOT_SENT/BLOCKED`);在异步跨边界核验之后再次读取 Chrome tab URL 和本 Task 的 Worker revision,拒绝导航中或被其它事件抢先替换的旧路由。**返回的 `routeVerified` 不是 `canSend`**,Action 在产生网页副作用之前仍必须检查原 Turn Token、Native/Context 授权和 Action receipt。
|
|
27
|
+
- 资源账本 `extension/loop/resources.js` 对带 Task 身份的 Chat 只接受精确 `projectId+taskId+sessionId` 匹配;原 V1 无 Task 的资源记录不能清理另一个 Task。所有资源账本公开写入与 reconciliation 经同一 Worker 临界队列执行。`reserveChat(run,actionTabId)` 按 `sessionId+TaskKey+token+原 Action tab` 保存 Chat 名额预留,`registerReservedChat` 核对 Chrome 实际 `openerTabId` 与精确预留再消费它;未知发送结果、Chrome 回执丢失、Worker 重启**不会**凭超时自动释放该预留;唯一例外是同一 Task 已持久化 `preSendAbort` 与 `lastIntentReceipt=NOT_SENT`,且原 Action Tab、nextAttempt ID、TurnToken 在 Task Store 精确一致、证实 **从未进入 SEND_BEGIN**,且原 Action Tab 的扩展 URL/参数仍在、检查前后未漂移并查不到该 Action 的后继标签时,才能由原 Action 或唯一分钟 Alarm 调用 `releaseReservedChat` 释放物理名额;原 Action 若关闭或失联,Chrome opener 归属可能丢失,因此保留 Hold 而不猜测释放。只有原 Worker 持久化 `NOT_SENT` 且 Native 以原 Handoff 签发请求/Context Permit/Checkpoint 将 PENDING Owner 一次 CAS 围栏为 BLOCKED、再通过 `handoff-abort-fence-read-v2` 只读核对 BLOCKED 修订精确 +1、同一 Context pending attempt/Checkpoint 与 USED Permit 后,才允许释放;该只读对账即使原 Handoff 私有签发记录在四小时后已清理,也只能使用这些持久 Native/Context 证据,绝不恢复旧请求的 Permit、SEND_BEGIN 或 Writer 权限;成功后只记录 `resourceHoldSettledAt`,**永久保留 NOT_SENT/preSendAbort 证明供 Stage 06 调查**;释放响应丢失时核对原名额确实已经不存在,不重复动作、不恢复 Context Writer。只有资源存储键完全不存在才初始化新账本;若曾持久化的值为 `null`、空对象或损坏状态则拒绝并保留 UNKNOWN,不冒充空名额;Token、Session UUID 在 Hold 唯一性及释放核对中按大小写无关的同一逻辑身份处理,错 Task/Session/Action 不得被当作 `alreadyAbsent`。已存在的同一 Action 子 Home 标签或经 Task/Session 精确核对的已注册 Chat 已计入物理容量,不重复计入预留;找不到原属证据则保留预留、不猜测释放。新 Chat 已创建而 Worker 注册 ACK 丢失时,资源账本的原 Chrome opener 归属核对同时支持 V1 `run.token` 和 V2 原 Task `PENDING` 的 `turnToken+actionTabId`,只补记未确认的子标签来源;不推导发送已成功,也不解除原 Resource Hold。原资源扫表在 Chrome Action 刚创建却仍为 `about:blank` 且 `pendingUrl` 指向可信扩展 Action 的短暂窗口保留原账本条目并计入物理 Action 配额,避免导航待完成时误放宽上限;待导航失败或漂移仍按原分支拒绝。`withRegisteredAction(run,{url,create})` 将 Action quota→创建→注册合为同一临界区,`registerAction` 在写 Ledger 前复核真实 Chrome tab URL(含仅限目标相同的 pendingUrl),已有同 ID 不同 URL/kind 拒绝;如果唯一 Worker 的定时扫描先于创建回执记录了同一 Action,则正式注册在核实原 tab/URL/type 后将 `owned:false` 升级为 `owned:true`,否则成功发送 Action 的资源清理永不匹配;创建回调只由 Worker 执行,资源库自身不发送网页消息。既有 `CHAT_LIMIT=2`、`ACTION_LIMIT=3` 不变。原一分钟 Worker Alarm 也对仍在 Store 的 Task 使用既有 Resource Ledger 核对;若原 `resources.terminal` ACK 丢失,只在精确 Task/Session/Generation/Revision 的 Native `DONE/BLOCKED/CANCELLED` 终态证明后补记相同 Task 的资源终态(Handoff 预发送 `BLOCKED` 但 Native `PENDING` 时绝不释放);24 小时 Native 终态归档前先核原资源账本结算,避免丢失最后一份 Owner 对账证据。只有账本记录由 Worker 创建(`owned:true`)、原 Task `lastIntentReceipt=SENT_CONFIRMED` 且 TurnToken/动作严格匹配的 Continue/Handoff Action,才沿旧 `safeRemove` 在超龄、非活跃、未固定时清理。UNKNOWN、未确认发送和用户标签一律不凭超时删除;不增加 Alarm、发送器或资源事实源。有证据的 **未发送** 预留释放已写入源码,但关闭/失联后继标签、跨 Profile 统一容量、已发生 SEND_BEGIN 的 UNKNOWN 和真实并发行为仍待独立验证;本轮不能宣称 V2 已具备验收通过的多 Task 发送。
|
|
28
|
+
- V2 `task-scheduler.js` 复用唯一 Worker 的一分钟 Alarm:`due()` 按 Task 挑出到期项,`dispatchDue(candidate,work)` 在该 Task 自己的队列开始时再核对原 Session、generation、Native Revision、Task Run Revision、Phase(不拿其他 Task 的全局 StoreRevision 作为失权依据)。`worker/scheduler.js` 已把该结果接到**只读** `observeScopedDueTasks()`:对每个到期 Task 重新调用现有 `task-owner-resolver` 验证 Native Ledger 与 Context Writer、检查真实 Tab/Chat/Run Revision,然后读取旧 Observer 的无 `poll:true` 状态快照。它既不调用完成处理器、发送或修改 Run,也不创建第二个 Alarm;Worker 启动/安装恢复遇 V2 活跃 Task 复用同一分支。A 的任务队列阻塞不阻塞 B 的只读查询。Task-scoped Model Intent、Continue/Handoff 的本地源码发送路径后来已接通,但尚未运行验收;现在同一个分钟 Alarm 还可针对原 Task 的已持久化 `LAUNCHING` Action 恢复**已存在的原标签**、针对原 SEND_BEGIN 后确切 User Turn 的 DOM/Native/Context 原回执补 Worker 投影,以及对 preSendAbort、无后继标签的原资源预留进行安全释放;这些分支允许按本 Task CAS 写 Worker 观察状态或物理资源 Ledger,**绝不复发 Chat 消息、再建 Action 或复活旧 Context Writer**。本轮未做真实验收,不能把源码接线宣布为安装版自动续接已通过。
|
|
29
|
+
- V1 Worker `router.js` 在旧 Turn/Action/Start/Session 控制消息进入处理器之前检查 V2 Task Store;Popup Clean、Eye Target、Extension Reload 也在副作用前检查。
|
|
30
|
+
- V1 `worker/admission.js::approvedAdoptionTarget` 在目标 Chat 当前未打开、准备由 Chrome 新建标签来导航到用户已存在的 Chat URL 之前,重新核对 V2 活跃 Task;防止旧 V1 Adopt Helper 在跨异步窗口中绕过入口门禁打开标签。此项不发送 Chat 消息、不授权采用现有 Chat。
|
|
31
|
+
- V1 Worker `scheduler.js` 的周期 Alarm、交接期限、Worker 启动/安装恢复及 Observer 重连不经过 Router,现已单独加入 V1/V2 身份围栏;有活跃 V2 Task 时不运行旧 V1 周期状态机;V2 只读到期观察已接入唯一 Alarm,且重连时逐 Task 使用 `reconnectScopedObservers()`:先按 Task 及 runRevision、Chrome URL、Native/Context Writer 复核,之后仅为该 Tab 注入原来可复用的 Observer 脚本;**已通过 Native/Context+DOM 回执确认的同一 User Turn** 可以再通过既有 `TURN_RESUME` 只读重挂接以防漏观测;若这个 Turn 最终仍有 `pendingConfirmation:true`,则 Worker 保留 `awaitingUserKey`,禁止另一个人工 User Turn 冒领本次下一轮,未确认或历史 Turn 仍不允许这样恢复。不会创建第二 Worker 或发送器。无 V2 Task 时的旧 V1 重连与 Turn RESUME 在每个真实动作前重新核对 Native V2 活跃 Owner。V2 的真实 Observer→Continue/Handoff 已在源码层接通,但未执行源代码、Chrome、Native、Context 的真实交叉验收,不能宣称安装版具备该能力。旧 `saveRun()` 的写入围栏也保留,但无法代替 Native 原子代际切换。
|
|
32
|
+
- Native V1 `writeSession` 与 V2 `writeOwnerLedgerSession/retireOwnerLedgerTerminal` 现在通过同一个 Darwin `lockf -k` 私有一次性写入 Helper 串行化,仍保留原 CAS、Context/Chat Claim 排除及原子落盘合同。首次升级只允许在原 `owner-registry.lock` **不存在**时用旧 `O_EXCL` 独占迁移窗口,且同锁核实 V1/V2 都是空闲或确实终态后才原地写入 0600 永久标记;旧版本继续用 `wx` 会拒绝写入,新的 Kernel lock 随进程退出释放、不删除标记。旧锁已存在但不匹配标记(包括崩溃遗留锁)、旧 Owner `BLOCKED/PENDING/UNKNOWN`、文件损坏或无法辨别的混版一律拒绝迁移,不因 PID/锁文件年龄猜测失效;**仅当旧 V1 Owner 仍活动且永久标记尚未建立时**,新版 V1 原写入入口可继续用原双层 `O_EXCL` 锁完成**同 Session/Project/Task** 的既有 CAS/终态,拒绝换 Session 或新建旧任务。旧任务真正到 DONE/CANCELLED 后才可在后续一次写入中切换内核锁,不能通过临时锁误判旧任务已安全退场。两秒锁竞争失败为 `OWNER_LEDGER_LOCKED`;子进程异常或回执未知为 `OWNER_WRITE_RECEIPT_UNKNOWN`,不得盲目重试。此能力只写入源码、**NOT_RUN**;正式切流、崩溃恢复及旧版本竞争须单独验收。跨 Task 的 `expectedSessionRevision` 保持真正的 Owner CAS,`expectedLedgerRevision` 只作不超前水位;完整 Chat ID/URL 与 Session 去重规则未改变。
|
|
33
|
+
- Native 的 `session-snapshot-v2`、`context-writer-check-v2` 为内部只读验证消息,不是新的公开 npm SDK/CLI/MCP 权限。现有 Context `run.terminalStatus` 没有返回 `pending_attempt`;`run.snapshot` 读取最近 Checkpoint,并非实时 Pending Attempt。**因此 `TASK_SCOPED_WRITER_VERIFIED` 只能用于只读 Owner/Writer 绑定核验,不能独立证明下一次发送已获许可或不存在旧的待决尝试。** 本地 V2 源码现通过 Context `run.terminalStatus` 的 `pendingHandoff/pendingCheckpointId`、`permit.status` 的一次性消费记录、Native Task Owner CAS 和签发的原 Turn Token 共同构成发送前置;这些步骤分别有受控 Provider,不能被仅一个 `context-writer-check-v2` 代替。**上述源码已接线但运行证据 NOT_RUN**,不能把静态合同写成当前安装版已可用或已具备并行发送。`session-sync-v2`、`context-control-v2` 仍必须绑定已核实的私有 Start Request、Context lease 和 Ledger CAS。V2 发送路由目前只在本地源代码层接线,仍需逐项验证原 requestId、Context Permit、Native Owner CAS、真实 User Turn、单次 DOM 发送和回执;不得从这段只读核验推定已支持真实并发网页操作。
|
|
34
|
+
- 本轮明确只进行源码和 npm 文档修改:**单元测试、静态检查、生成器、构建、打包、Chrome E2E 均 `NOT_RUN`**;上一次隔离 IPC 历史回执不能当作本次源码的验收结果。
|
|
35
|
+
|
|
36
|
+
完整的任务身份、V1→V2 迁移、审批和并发 E2E 门禁见研发仓库的 `docs/research/chat-loop-multitask-architecture-design-20261126.md`(该研发材料不随 npm 包分发)。
|
|
37
|
+
|
|
38
|
+
Handoff 成功及丢 ACK 的只读恢复各自验证 Native/Context/DOM 原始证据,验证后共用同一 Worker 新代 Task 投影函数,要求 Native revision 和 Context binding revision 精确推进一代。新代 Chat 的 `startedAt/deadlineAt` 从持久化 `handoffReceipt.observedAt`(后继首次 User Turn 双重 DOM 证据)与原 `policy.windowMsOf` 重算,而不是继承上代已过期时钟,也不因晚收到 ACK/Worker 重启而重新给四小时;正常成功路径必须传入刚刚持久化的原后继 DOM 回执;只读丢 ACK 恢复必须复用同一回执,若时间/Tab/页面/UserKey 身份不可信则拒绝投影而非默默继承旧起点。Worker TaskCAS 仅将原 Chat Tab/页面与原 attemptId 保存在 `resourceTransfer`(原页面可为普通 `/c/...` 或已获 Owner 校验的 GPT `/g/.../c/...`;新 Chat/代际从当前 Run 读取,不重复持久化);单一资源账本将新 Chat 确认为当前资源,并将同 Task/Session 的旧 Chat 标为 `supersededBy`,只结算活跃名额、不主动关闭旧标签;既有成功 Action 的关旧标签行为不变。既有分钟 Alarm 在同 Task 队列内重读 Native 精确 Owner 后重试资源账本结算,不重放 Context 或 DOM 操作;结算前不再启动下一次 Handoff,也不归档尚未结算的终态。源码状态 `SOURCE_CHANGED_UNTESTED`。现在 Handoff TAKE 完成最终 Turn/Owner 双重核对后,先由原唯一 Resource Ledger 为本 Task/Session/TurnToken/ActionTab 持久预留 successor Chat 名额,再消费 Native/Context Handoff Permit 并围栏旧 Writer;满额只拒绝 TAKE,旧 Writer 不因此被冻结。重复同一 Action 只核对原有 Hold,Action 原 `preflight` 改为只读原 Hold、不得在围栏后补建名额;成功注册后沿用原 `registerReservedChat`。预留完成但 Permit 结果 UNKNOWN 时保留原 Hold,禁止以超时释放;该残留的受控撤销/复核仍属于 Stage 06 未闭环。
|
|
39
|
+
|
|
40
|
+
`CONTEXT_LIMIT`/`PAGE_ERROR`/`SECURITY_CHALLENGE` 的 V2 Observer 故障不再只落入会被 V2 围栏拦截的旧 `TURN_BLOCKED_V1` 路由。Observer 优先发送最小字段的 `CHAT_LOOP_TASK_TURN_BLOCKED_V2`,未命中 Task 或旧 Worker 无此路由才按既有 V1 入口回退;真正的 V2 DENIED/BLOCKED 不回退。单一 Worker 以真实 Tab、Native/Context Writer、两次 DOM 失败观察复核,只记录本 Task 的 `lastFault`,Status 显示 `PAGE_FAULT_REVIEW` 及原因/时间。诊断记录不改变 Native/Context Owner、不执行 Handoff、不点击 Retry、不作为 `BLOCKED` 或恢复许可;后续成功的原 Turn 观察或确认过的 Continue/Handoff 清除过时故障。若 Observer 的一次性错误上报因 MV3 暂停丢失,原 Worker 分钟 Alarm 从已核验 Task/Tab 的既有只读快照重用同一故障验证器补记(记录相同则不再核 DOM),在任何待启动 Action 前先检查页面 BLOCKED;不会新建 Alarm/Action、重发网页消息或恢复写权。仍需 Stage 06 的可信安全恢复合同及真机 E2E,本轮均 `NOT_RUN`。
|
|
41
|
+
|
|
42
|
+
已存在的 Task-first Handoff Action 收到 `RESOURCE_CHAT_LIMIT`(唯一 Resource Ledger 在消耗 Permit **之前**明确拒绝)时,在原 Action Tab 内按 1 分钟间隔受限等待、最多 1 小时重新发起同一 TAKE;每次仍由 Worker 复核原 Task/Tab/Native/Context/Turn,绝不另开 Action,也不重放网页发送。仅此确定性的未发信配额拒绝可重试;无回执、Permit 消耗/Native 围栏不明、Action Tab 漂移一律不重试。超过等待上限保留原 Task/Owner 与诊断,不推定完成;回归及安装版行为 `NOT_RUN`。
|
|
43
|
+
|
|
44
|
+
Native Host `bin/native-host.mjs` 的观察链现按私有请求类型为 V2 Start/Status/Continue/Handoff/Cancel 绑定相应原始签发请求的 `traceParent`;之前在 Continue/Handoff 等分支仅接受 `record.action==='start'`,会形成父 Span 缺口。此变更只针对 Native API 日志父链,不接受浏览器自填来源作为 Owner/Permit 授权,不改变任何业务结果;Trace BEGIN/终态一致性和真实回执仍 `NOT_RUN`。
|
|
45
|
+
|
|
46
|
+
The V2 Handoff Native pending-fence read now supplies its original
|
|
47
|
+
`sourceRequestId` as a private `expectedHandoffAttemptId` to trusted
|
|
48
|
+
Context `run.terminalStatus`; Context responds only with
|
|
49
|
+
`pendingAttemptMatches`, and the Native consumer refuses a mismatch.
|
|
50
|
+
A pending Boolean or Checkpoint by itself cannot prove the original
|
|
51
|
+
Handoff attempt. This is strictly read-only evidence and does not
|
|
52
|
+
restore a Writer, resubmit a Permit, create a Chat or authorize a retry.
|
|
53
|
+
The Context and Extension package updates are untested and unreleased.
|
|
54
|
+
|
|
55
|
+
### Task-first 跨包受控合同(源码现状;所有运行验收 NOT_RUN)
|
|
56
|
+
|
|
57
|
+
| 入口 | Native/Context/Worker 真实 Provider 与约束 | 源码副作用 |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `extension start` + `taskFirst:true` | 只允许 `mode:adopt`、原 Chat 的 R/P 两次真实 Turn 证据、独立 Task lease;`task-start-v2.js` → Native `session-{read,sync}-v2` → Context `permit.consume START` → `run.bind.initial`,Start/Reserve/START Permit 的 PENDING pin/Adopt Native 每一步均以原预期 Session Revision 精确 `+1` 验证,初次 Context Bind 以原 `expectedBindingRevision:0` 要求精确结果 `1`;正式 Adopt `startedAt`/轮询/`deadlineAt` 统一基于同一个已获 Owner 确认的时间点并使用原 `policy.windowMsOf`,避免毫秒级差值破坏 Task Store 四小时约束;成功回执还带已验证的 `activeChatId/activeChatUrl`,满足 Tools MCP 原 `start` 解析合同,避免已成功 Adopt 被错误判为 `START_RESULT_UNVERIFIED`(丢 ACK 只读查原请求) | 只接管原 Chat,不能重发已批准的消息、创建新 Chat;未消费 START Permit 的 Native STARTING/RESERVED 丢 ACK,仅凭原签发 Start Request 派生的同一 Session ID + 原 Chat R/P 证据恢复 Worker,不重放 Permit |
|
|
60
|
+
| `extension status` + `projectId/taskId` | `actions/status.js` → `CHAT_LOOP_TASK_STATUS_V2` → Native `context-status-v2` → Context 权威只读 `run.terminalStatus`,不选择 latest Task | 仅状态;无 Chat/无 Writer 的 V2 原始 Adopt `STARTING/RESERVED/PENDING` 统一显示只读 `PRE_ADOPT_UNBOUND`(不等于发送或启动 PASS),若该阶段 Context 出现绑定/待决副作用则显示 `FENCED_UNCERTAIN`,而不是误报 `PENDING_SEND_UNRESOLVED/VERIFIED`;原取消确已 Native `CANCELLED +2` 且 Context 已取消才显示 `CANCEL_ACK_REVIEW`,若只达到 Native `BLOCKED +1` 则显示 `FENCED_UNCERTAIN`;Handoff 新代 Native 已切换但 Context 未绑定亦显示 `FENCED_UNCERTAIN`,只有新代 Revision 精确 `+1`、Context Writer/审批/项目规则和零待决副作用一致时才显示 `HANDOFF_ACK_REVIEW`;即使 Worker/Native Phase 一致,Context 中非空的 Writer RunRef 也必须属于当前 Session/Task/generation(Native 只暴露 `writerMatchesOwner` 布尔证明,不暴露凭据),否则仅显示 `FENCED_UNCERTAIN` 而非 `VERIFIED`;Context Writer 失权或终态交付未结算亦同;Native 只暴露经 Context 核验的 `deliveryCommitted` 布尔值及精确匹配当前 Session/Generation 的 `sessionCancelled`,不泄露交付正文、取消证据或 Writer 凭据(均不是新许可);Handoff 预发送中止须原 Worker `NOT_SENT` 与 Native 的新只读 `handoff-abort-fence-read-v2` 同时证实原签发请求、USED Permit、Checkpoint、BLOCKED 撤销修订 +1 与 Context 仍 pending,才显示 `HANDOFF_PRE_SEND_FENCED`,否则仍为 FENCED_UNCERTAIN;两者均不代表恢复许可。无参数时仍旧 V1 Status |
|
|
61
|
+
| `extension continue` + `taskFirst:true/turnToken` | `task-intent-v2.js` → 同一个 `continue.html` → `task-action-v2.js` → Native `continue-{permit,send-check,result}-v2` → Context `permit.consume/permit.status` | 原 Start/Model Intent/Continue/Handoff/Cancel Action 均校验签发 URL + 扩展自身顶层 Frame,且真实动作继续独立核 Native/Context 原请求;原 Action 唯一 `sendOnce`;持久 `SEND_BEGIN` 后至多点一次;新 Turn Token 只能在精确回执后更换,UNKNOWN 不重发 |
|
|
62
|
+
| `extension handoff` + `taskFirst:true/turnToken` | 原 `handoff.html` 动态装配 `handoff-scoped.js`,复用 `verifyOldChat/waitForNewChat/sendHandoffOnce`;Native `handoff-{permit,send-check,result}-v2` 使用 Context 原 `run.fence/run.bind.handoff` | 旧 Writer 围栏后新建一次 Chat;原 Context Checkpoint / 代际 / 真实 DOM / Native / Context 双回执才转 Owner;Handoff Permit 的 Native PENDING CAS 与 Context Fence Binding 都须精确推进 `+1`(而非仅大于旧值)。新 Credential 仅留在一次性 Action,不写 Worker Store |
|
|
63
|
+
| `extension session` + `taskFirst:true/expectedNativeRevision` | `task-cancel-v2.js` 先核扩展自身顶层 Action Tab/正式 session.html 签发 URL → `task-cancel-v2` Native → Context `run.idleStartPermitStatus` 与 `run.fence.cancel` 同事务复核历史 Permit → Native+Worker `CANCELLED` | 只取消未执行业务的初始 Adopt;任何已消耗 Continue/Handoff Permit 均不可冒充空闲;不修改 Task DONE |
|
|
64
|
+
| `extension session` + `operation:recover-handoff` / `taskFirst:true` | 原签发请求→同一 `session.html` Action 显示原 Project/Task,要求浏览器中 60 秒内的可信用户点击(`confirmed:true` 参数不能代替;未点击不进入 Worker)→`task-recover-v2.js` 核原 Worker `NOT_SENT`、`sendBeginAt=null`、原 Action Tab/Chat/已结算 Resource Hold(若有先前 Alarm 的持久结算回执则不重复要求已关闭的 Action;否则必须重新核对实时 Action/opener)→Native `task-recover-{handoff,read,finalize}-v2` 原撤销/许可证明→Context 唯一 `RECOVER_HANDOFF` Permit 与 `run.restore-fenced-handoff`→Native `BLOCKED→WAITING_REPLY` 精确 CAS→Worker 独立投影 CAS;所有调用仍走私有签名 IPC | 恢复**原 Task、原 Chat、原 generation** 的 Writer;不新建 Chat、不自动发送;一次新凭据仅存原 0600 私有请求和正式回执,不入 Worker Store。IPC 丢 ACK 只查原请求及其原 Permit/Writer/CAS;Native 先提交但 Worker 未落盘,只读修复同 Task 投影;未知不生成第二个恢复请求。源码 **NOT_RUN**,不是已安装功能 |
|
|
65
|
+
| Observer `DONE/BLOCKED` | `task-terminal-v2.js` → Native `task-terminal-v2` → Context 交付/终态 Writer Fence;定时器只重核原 Turn,不能再发送 | 仅 Context 已确认 DONE 才释放已完成任务;普通 BLOCKED 锁住原任务,不影响 B |
|
|
66
|
+
| 终态保留 | 原唯一分钟 Alarm → `task-retire-v2` → Context 再证 DONE 或 `CANCELLED_NOT_DELIVERED` → Native 单 Task CAS 删除 + **同一 Ledger 内的精确归档回执** → Worker 同 Task Revision 删除 | 至少保留 24h;BLOCKED/UNKNOWN 绝不 GC。丢失首次 Native ACK 只能查询本 Ledger 的原 `TaskKey+Session+generation+revision` 归档回执;同一回执返回完整 `projectId/taskId/sessionId/generation/nativeOwnerRevision/terminal`,Worker Task Store 删除前必须逐一与当前槽位匹配,不能由 Native Owner 缺席或不完整回执猜测已经归档。回执有界保留,过期/耗尽时 `UNVERIFIED`,不可误删 Worker |
|
|
67
|
+
|
|
68
|
+
V2 Continue/Handoff 的原 `intentId` 或 `lookup:true` **只读查询**仍复用正式 Action/Native 私有请求;Worker 查询回执统一返回 `status:'STATUS', phase:<原状态>`,与原 V1 CLI 和 Tools MCP `formatExtensionResult` 约定相同(此前误返 `state` 会被 Tools 判为 `INVALID_MODEL_INTENT_REPLY`)。此结构对齐不改源 Task、Permit、Chrome 或发送行为;真实回执 `NOT_RUN`。
|
|
69
|
+
|
|
70
|
+
**两段式模型意图(仍是未验收源码)**:本地 V2 的每一个待继续助手轮次都必须先发起对应已签发 Task/TurnToken 的意图;**裸 CONTINUE 末行没有合法下一步 Action,不会自动发送**。原 V1 `turnToolNote` 仍是可选工具,V2 新 `scopedTurnToolNote` 强制在回复尚未结束时登记 `taskFirst:true` 的 `continue(nextPrompt)` 或 `handoff`;DONE/BLOCKED 不登记。新代 Successor Chat 也使用相同合同,不存在从模型末行推断 Permit 的隐式后门。`task-intent-v2.js` 只能在原 Chat **真实活动中的助手轮次**登记本 Task 的 `QUEUED`,先通过现有 Observer 的只读 `CHAT_LOOP_TURN_PROGRESS_V2` 验证本轮 User Turn 的身份与生成状态;此时不查最终末行、不消费 Permit、更不会创建 Action。模型随后正常结束本轮,原 Observer 的最终 `CONTINUE/HANDOFF` 与固定 User/Assistant Turn 经过 `task-intent-dispatch-v2.js` 双次 DOM 核验后,才将意图 `LAUNCHING` 持久化,再使用原唯一 Action 创建器。创建 ACK 不明保持 `ACTION_UNVERIFIED`,确定性物理额度拒绝可用 `CAPACITY_BLOCKED` 在同 Task 原 Alarm 后续复核。最终输出 DONE/BLOCKED 时,仅能在**同 Task 队列中、最终 DOM 双读后**撤销尚未创建 Action 的预备意图并留 `NOT_SENT` 收据,再走真实 Context 终态;最终 CONTINUE/HANDOFF/UNKNOWN 与本轮已登记意图不符时,也只可通过 `scopedSettleMismatchedIntent` 以同一 User/Assistant Turn 双读核实后记 `NOT_SENT`,不猜测执行成功,不擅自把 Task 标为 DONE。历史完成 Turn 不能拿旧 Token 再登记行动。
|
|
71
|
+
|
|
72
|
+
**跨进程丢回执补偿(仍是未验收源码)**:Continue 的正常回执与 ACK 丢失只读恢复在各自完成 Native/Context/DOM 验证后,复用单一 `scopedContinueSuccessorRun` 投影,避免 Turn Token、下一轮 User Key、NOT_SENT/UNKNOWN 字段清理因两套实现漂移。Continue 的 Native `WAITING_REPLY→PENDING→WAITING_REPLY` 每次只允许精确 Session Revision `+1`;正常结果回执与丢 ACK 的只读恢复均必须符合该同 Task CAS 边界,不接受仅“较大”的修订号。Continue 的 Context Permit + Native PENDING 已提交但 Worker 尚未记下 `SEND_BEGIN` 时,原 Action 仅能用同一 sourceRequestId 的 `continue-reconcile-v2` 查 Context `permit.status` 和原 Native CAS;不能再次消费 Permit。Worker 已记下 `TAKEN`、尚无 `SEND_BEGIN` 时,原 Action 只能取回同一 next Turn Token,不能再生成。**SEND_BEGIN 之后**若新 User Turn 已有稳定 DOM 回执,Worker 先存不含正文的 `continueReceipt`;Native `continue-result-v2` 的 ACK 丢失后,唯一 Alarm 只调用 `continue-result-read-v2` 对账原 Permit、Native 后继 Revision 与 Context Writer,才修复同 Task Worker 投影,不再次点击发送。Handoff 新 Chat 的发送已由 DOM 证明、而 Native/Context 新代绑定结果丢 ACK 时,Worker 先保存不含凭据的 `handoffReceipt`;`task-handoff-recovery-v2.js` 在原分钟 Alarm 中先双重核实真实后继标签、opener 和新 User Turn,再通过 Native 的**只读** `handoff-result-read-v2` 同时检查原签发请求、已消费 Permit、唯一新 generation Owner 与 Context 已绑定 Writer(原绑定修订 +1),并在投影 CAS 前重新复核真实标签才补 Worker 状态;若仅 Native 先切换、Context bind 未完成则必须保持 UNKNOWN,绝不重发新 Chat、再调用 Context bind 或另造凭据;Status 只显示 `HANDOFF_ACK_REVIEW`,不是授权。DONE/BLOCKED 的 Native 终态 ACK 丢失也只能走 `task-terminal-read-v2` 加原 Turn 双重 DOM 复核;终态 Native `WAITING_REPLY→DONE/BLOCKED` 与其只读恢复均要求精确 Session Revision `+1`,不能用任何较新状态冒认本次提交。BLOCKED **没有**可回收时间戳。
|
|
73
|
+
|
|
74
|
+
**私有请求时间窗**:旧版 CLI/Native Action 请求继续 20 分钟过期和清理;仅确实包含 `taskFirst:true` 的 V2 Continue/Handoff 模型意图,其原私有 sourceRequestId 必须跨越当前助手轮次,因此将 TTL 有界提高到四小时,清理仅保留未到期的这类签发记录。过期或失去原 Context/Native/Turn 身份仍拒绝,不凭保留请求文件赋予发送许可。不得把 TTL 提升当作聊天无限续接。
|
|
75
|
+
|
|
76
|
+
**取消终态的丢 ACK 对账**:正常原签发取消同只读 ACK 恢复均要求 Native `WAITING_REPLY→BLOCKED→CANCELLED` 精确各 `+1`(总 `+2`)及 Context Binding Revision `+1`,不接受仅“修订变大”的回执。正式 `session taskFirst cancel` 先用原 Worker Task CAS 进入 `SESSION_CANCEL_PENDING`,Native 将旧 Owner 围栏、Context `run.fence.cancel` 和 Native `CANCELLED` 依次提交。若一次性 ACK 在后两者全部提交后丢失,`task-cancel-read-v2` **只读**核查同 Task/Session/generation、原 requestId 对应的 Context `cancel-<requestId>`、Native 两步 Revision、Context BindingRevision/空 Writer,再由原 Alarm 的 `task-cancel-recovery-v2.js` 用 Worker CAS 写入 `CANCELLED`;Task Status 表示为 `CANCEL_ACK_REVIEW` 而非自动 PASS。若 Native 仍是 BLOCKED、Context 已取消但 Native 终态未提交,不能通过这条只读路径猜测成功或重跑取消;保留 Stage06 的阻断待权威恢复。
|
|
77
|
+
|
|
78
|
+
**Observer 恢复**:成功 Continue/Handoff 的已确认新 User Turn ID 写在同 Task 的 `awaitingUserKey`,重启/周期 Alarm 只能给这个 Turn 重新挂接原只读 Observer,不重发;完成观察后清除等待标识。误匹配其他人的新 User Turn 一律拒绝。以上均不解除未解决的 Handoff NOT_SENT、跨 Profile 及混版切流门禁。
|
|
79
|
+
|
|
80
|
+
以上内部 Native/MV3 消息不构成额外 npm 根导出、CLI 或第二发送器。为方便集成,`extension tool` 只新增可选的 `taskFirst` 与精确 Status TaskKey,全部来源仍走现有 Extension 正式 CLI + Tools MCP Provider。源代码能形成完整调用链,**不等于 npm 包、Native Host、Chrome 已安装新版**;未运行日志/DOM/Permit/ACK 验收,发布前须冻结版本与全部生成依赖;一旦出现 UNKNOWN 必须继续持有原 Task Fence。
|
|
81
|
+
|
|
82
|
+
## API invocation logging
|
|
83
|
+
|
|
84
|
+
The public npm SDK, CLI and Native Host functions use a generated, bounded,
|
|
85
|
+
non-blocking API observation slice. The MV3 Worker's formal message dispatch
|
|
86
|
+
records only the allowlisted message type, not payloads or chat text. It
|
|
87
|
+
forwards a separate, best-effort Native observation into the **existing
|
|
88
|
+
Supervisor Trace** when available; an unavailable Native Host or Supervisor
|
|
89
|
+
can drop these observations but cannot change Owner or action receipts.
|
|
90
|
+
Remotely exposed Extension MCP calls are recorded independently by the Tools
|
|
91
|
+
Gateway's single API observation port. No second log service is created.
|
|
92
|
+
Logging cannot authorize sending, change Owner or retry an UNKNOWN action.
|
|
93
|
+
|
|
94
|
+
## Build-time Action capabilities
|
|
95
|
+
|
|
96
|
+
Each `capabilities/<id>.mjs` owns an Action's name, CLI route, page,
|
|
97
|
+
execution kind, result type and local deadline. No separate API catalog is
|
|
98
|
+
maintained. `npm run build:actions` generates both:
|
|
99
|
+
|
|
100
|
+
- `actions.generated.mjs` — Node CLI/Native SDK action catalog.
|
|
101
|
+
- `extension/loop/action-catalog.generated.js` — browser-only Eye map.
|
|
102
|
+
|
|
103
|
+
New **read-only Eye** actions can declare an additional `chat_*` name,
|
|
104
|
+
their own CLI route, and either the existing `text` or `dom` read mode.
|
|
105
|
+
The builder creates their isolated Action HTML, which uses the same
|
|
106
|
+
`actions/common.js` target/Owner/Native receipt checks and the shared
|
|
107
|
+
`actions/read-mode.js` executor. No existing Action or central CLI/Worker
|
|
108
|
+
dispatch switch needs modification. The builder refuses duplicate names,
|
|
109
|
+
privileged type changes, invalid read modes, missing assets and stale output.
|
|
110
|
+
|
|
111
|
+
**A declaration does not grant sending authority.** The separately reviewed `entry test` Action is a TEST_ONLY, Native-authorized first-turn fixture: it requires an explicit confirmation, creates one ordinary Chat with a real structured @ App mention, and must prove the unique user message without a Browser Owner; it cannot approve R/P or invoke Start/Continue/Handoff. Its explicit privilege review is allowlisted by exact ID, route, page, deadline and receipt format. When no ChatGPT tab exists, only this TEST_ONLY Action may open in the one Chrome window containing the verified exact extension details page; the Action itself creates the normal Chat. Other Actions still require the unique current ChatGPT window. Any other new sending declaration is denied. Start, Continue, Handoff,
|
|
112
|
+
Clean, Status, screenshot and reload keep their reviewed, explicit Worker
|
|
113
|
+
handlers and existing trust boundaries. New send/Owner/Native mutation
|
|
114
|
+
requires a separate authorized security review and implementation; it cannot
|
|
115
|
+
be enabled by dropping in a capability file. Browser read actions never
|
|
116
|
+
clear an unknown send result or adopt a different Chat Owner.
|
|
117
|
+
Screenshot uses Chrome `captureVisibleTab` with the existing per-tab user
|
|
118
|
+
invocation (`activeTab`) or already granted capture permission; opening an
|
|
119
|
+
Action page programmatically does not itself grant this permission. Missing
|
|
120
|
+
permission is reported as `CAPTURE_PERMISSION_REQUIRED`, other capture API
|
|
121
|
+
failures as `CAPTURE_API_FAILED`, without exposing raw browser diagnostics.
|
|
122
|
+
Do not broaden host permissions or change the current Owner to obtain a screenshot.
|
|
123
|
+
|
|
124
|
+
### Validation
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
npm run build:actions
|
|
128
|
+
npm run build:actions:check
|
|
129
|
+
npm test
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Workspace `npm run check` and npm `pretest`/`prepack` also verify generated
|
|
133
|
+
catalogs. `test/capability-composition.test.mjs` proves isolated addition and
|
|
134
|
+
removal of an Eye action and rejects privileged or duplicate declarations.
|
|
135
|
+
The package build and Chrome manifest versions must match.
|
|
136
|
+
|
|
137
|
+
## CLI
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
Usage: chatloop-extension <command> [options]
|
|
141
|
+
Commands: capabilities, host, extension
|
|
142
|
+
Run: chatloop-extension <command> --help
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
Usage: chatloop-extension extension <command>
|
|
147
|
+
Commands: chat text | chat dom | chat screenshot | reload | continue | handoff | clean <tab-id> | status | start | session | entry test
|
|
148
|
+
Run: chatloop-extension extension <command> --help
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
For the installed command list, run `chatloop-extension extension --help`.
|
|
152
|
+
|
|
153
|
+
`extension start` requires the real approved intent; `mode=adopt` requires an exact Context `start.reserve` lease, taskId, store epoch and revisions at the public CLI input boundary, with actual approval/lease validity independently checked by Native `permit.consume`. A browser-only R/P text pattern and `confirmed:true` cannot authorize a production Adopt; the prompt-based legacy Start has separate rules. `mode=adopt` does not
|
|
154
|
+
re-send. Continue/Handoff only register intents with one Turn token and never
|
|
155
|
+
silently send or repeat. Clean needs an exact verified tab ID, and Status
|
|
156
|
+
is read-only. The single `session` Action page accepts a private, exact
|
|
157
|
+
`operation:cancel` request only for an idle, Context-managed Adopt with no
|
|
158
|
+
business work or UNKNOWN effects. It fences the Context writer before Native
|
|
159
|
+
accepts `CANCELLED`, and never impersonates delivered `DONE`. A previously BLOCKED Session with a lost old Owner tab remains
|
|
160
|
+
`state:BLOCKED` (not `IDLE`) when Worker/Native identities agree; the
|
|
161
|
+
`oldOwnerTabStatus:MISSING_UNVERIFIED` diagnostic is not a replacement permit.
|
|
162
|
+
A missing ACTIVE Owner or mismatched Native pointer remains `UNVERIFIED`.
|
|
163
|
+
Explicit Adopt of a different approved Task still requires the exact old
|
|
164
|
+
Session ID, old Context fence, and a fresh Start lease. An exceptional
|
|
165
|
+
same-Task recovery is limited to a proven pre-permit BLOCKED Adopt with no
|
|
166
|
+
send/Owner/writer, a fresh Context lease and one exact Native timestamp CAS;
|
|
167
|
+
a Worker-only failed Native sync permits at most one additional fenced repair,
|
|
168
|
+
never a general BLOCKED retry. Two distinct genuine Form A-confirmation
|
|
169
|
+
user Turns may serve as SOFT R/P evidence in an explicitly
|
|
170
|
+
specified original Chat; this never substitutes for Context approval or Start
|
|
171
|
+
permission. Without a supplied Chat URL, a distinct exact Form A pair in an
|
|
172
|
+
already-open, actively processing P-confirmation Turn can be a candidate.
|
|
173
|
+
The candidate must be unique; Native Context still compares both approval
|
|
174
|
+
sources to the reserved Task before Owner binding. Idle generic Form pairs,
|
|
175
|
+
multiple candidates and mismatched approval sources do not grant an Owner.
|
|
176
|
+
No URL means no Chat creation. IPC messages are one-shot and have durable identity checks. CLI and Native
|
|
177
|
+
Host resolve the same private `chatloop-extension-v2-<uid>` IPC directory in
|
|
178
|
+
the fixed system temporary root (macOS `/private/tmp`, Linux `/tmp`),
|
|
179
|
+
independent of TMPDIR/TMP/TEMP. The prior namespace is retained as historical
|
|
180
|
+
receipt evidence and is never searched or replayed by this protocol.
|
|
181
|
+
|
|
182
|
+
This package's source version is read from its own `package.json`. Installed
|
|
183
|
+
Tools/Context consumers may pin a different Extension version; updating
|
|
184
|
+
their dependencies is a separate release task. Source tests do not prove
|
|
185
|
+
npm publication, Chrome reload, Native Host installation or Stage 03 E2E.
|
|
186
|
+
Inspect real installed versions, Owner and authoritative receipts first.
|
|
187
|
+
|
|
188
|
+
Product-level Extension/Context documents live in the source repository,
|
|
189
|
+
**not in this published npm package**. Its runtime API and security contract
|
|
190
|
+
are described above without requiring that repository.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// GENERATED by scripts/build-actions.mjs — do not edit.
|
|
2
|
+
import {capability as a0} from './capabilities/chat_text.mjs';
|
|
3
|
+
import {capability as a1} from './capabilities/chat_dom.mjs';
|
|
4
|
+
import {capability as a2} from './capabilities/chat_screenshot.mjs';
|
|
5
|
+
import {capability as a3} from './capabilities/reload.mjs';
|
|
6
|
+
import {capability as a4} from './capabilities/continue.mjs';
|
|
7
|
+
import {capability as a5} from './capabilities/handoff.mjs';
|
|
8
|
+
import {capability as a6} from './capabilities/clean.mjs';
|
|
9
|
+
import {capability as a7} from './capabilities/status.mjs';
|
|
10
|
+
import {capability as a8} from './capabilities/start.mjs';
|
|
11
|
+
import {capability as a9} from './capabilities/session.mjs';
|
|
12
|
+
import {capability as a10} from './capabilities/entry_test.mjs';
|
|
13
|
+
export const actionCapabilities=Object.freeze([a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]);
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// CLI is owned by the Extension package; local-tools delegates, never implements actions.
|
|
3
|
+
import {existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync} from 'node:fs';
|
|
4
|
+
import {homedir} from 'node:os';
|
|
5
|
+
import {dirname,join,resolve} from 'node:path';
|
|
6
|
+
import {fileURLToPath} from 'node:url';
|
|
7
|
+
import {extensionCliApi} from '../index.mjs';
|
|
8
|
+
const cliContract=extensionCliApi();
|
|
9
|
+
const {ACTIONS,actionCapabilities,matchExtensionAction,HOST_NAME,configFile,prepare,readResult,privateDir,validateExtensionId,openExtensionActionPage}=cliContract;
|
|
10
|
+
const actionById=new Map(actionCapabilities.map(cap=>[cap.id,cap]));
|
|
11
|
+
const actionHelp=actionCapabilities.map(cap=>cap.cli.join(' ')+
|
|
12
|
+
(cap.kind==='owner-clean'?' <tab-id>':'')).join(' | ');
|
|
13
|
+
const contract='chat-loop.extension-cli.v1';
|
|
14
|
+
const providerVersion=JSON.parse(readFileSync(new URL('../package.json',import.meta.url),'utf8')).version;
|
|
15
|
+
const HELP={
|
|
16
|
+
'': 'Usage: chatloop-extension <command> [options]\nCommands: capabilities, host, extension\nRun: chatloop-extension <command> --help',
|
|
17
|
+
host: 'Usage: chatloop-extension host install <extension-id>\nRegisters the local Chrome Native Messaging Host (macOS).',
|
|
18
|
+
extension: 'Usage: chatloop-extension extension <command>\nCommands: '+actionHelp+'\nRun: chatloop-extension extension <command> --help',
|
|
19
|
+
'extension clean':'Usage: chatloop-extension extension clean <tab-id>\nClear only the verified ChatGPT composer. Never send or close a Chat.\nMachine Clean requires the exact tab id of a terminal Chat Loop Owner; popup Clean requires a user-selected ChatGPT tab.',
|
|
20
|
+
'extension continue':'Usage: chatloop-extension extension continue (JSON intent on stdin)\nSubmit next-turn text or query receipt; does not send directly.',
|
|
21
|
+
'extension handoff':'Usage: chatloop-extension extension handoff (JSON intent on stdin)\nRequest early handoff or query receipt; does not transfer directly.',
|
|
22
|
+
'extension status':'Usage: chatloop-extension extension status [optional JSON {projectId,taskId} on stdin]\nWithout input reads legacy V1 state. Explicit Task status never guesses the latest Task.',
|
|
23
|
+
'extension start':'Usage: chatloop-extension extension start (JSON on stdin)\nStart a new task with prompt, or use mode=adopt (no prompt) to bind the only R/P-approved existing Chat without sending.',
|
|
24
|
+
'extension session':'Usage: chatloop-extension extension session (JSON intent on stdin)\nCancel an exact idle Adopt, or request a separately confirmed, no-send recovery of a proven unsent Handoff. Recovery also requires a real click in the original session Action.',
|
|
25
|
+
'extension entry test':'Usage: chatloop-extension extension entry test (JSON intent on stdin)\nTEST_ONLY: use the built-in Extension Action to create a new normal Chat, choose the actual native @ App, and send exactly once without a Browser Owner.'
|
|
26
|
+
};
|
|
27
|
+
function helpFor(args){
|
|
28
|
+
if(args.length===1&&['-h','--help','help'].includes(args[0]))return HELP[''];
|
|
29
|
+
if(args.at(-1)==='--help'||args.at(-1)==='-h'){
|
|
30
|
+
const section=args.slice(0,-1).join(' ');
|
|
31
|
+
return HELP[section] || (section.startsWith('extension chat ')
|
|
32
|
+
? 'Usage: chatloop-extension '+section+'\nRead the current uniquely verified Chat Owner.'
|
|
33
|
+
: section==='extension reload'?'Usage: chatloop-extension extension reload\nRequest extension reload; final health is unverified.'
|
|
34
|
+
: null);
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
|
40
|
+
const emit=(event,command,fields={})=>process.stdout.write(JSON.stringify({contract,providerVersion,event,command,...fields})+'\n');
|
|
41
|
+
const quoted=s=>"'"+s.replaceAll("'","'\\''")+"'";
|
|
42
|
+
function installHost(extensionId) {
|
|
43
|
+
validateExtensionId(extensionId);
|
|
44
|
+
if(process.platform!=='darwin')throw Object.assign(Error('Native Host registration not verified on this OS'),{code:'HOST_INSTALL_UNSUPPORTED'});
|
|
45
|
+
const conf=configFile();privateDir(dirname(conf));
|
|
46
|
+
const node=process.execPath,script=fileURLToPath(new URL('./native-host.mjs',import.meta.url));
|
|
47
|
+
const runner=join(dirname(conf),'native-host.sh');
|
|
48
|
+
writeFileSync(runner,'#!/bin/sh\nexec '+quoted(node)+' '+quoted(script)+' "$@"\n',{mode:0o700});
|
|
49
|
+
chmodSync(runner,0o700);
|
|
50
|
+
const hostDir=join(homedir(),'Library','Application Support','Google','Chrome','NativeMessagingHosts');
|
|
51
|
+
mkdirSync(hostDir,{recursive:true});
|
|
52
|
+
const manifest={name:HOST_NAME,description:'Private Chat Loop Extension Native Messaging Host',
|
|
53
|
+
path:runner,type:'stdio',allowed_origins:['chrome-extension://'+extensionId+'/']};
|
|
54
|
+
const manifestPath=join(hostDir,HOST_NAME+'.json');
|
|
55
|
+
writeFileSync(manifestPath,JSON.stringify(manifest,null,2)+'\n',{mode:0o600});
|
|
56
|
+
writeFileSync(conf,JSON.stringify({extensionId,host:HOST_NAME,at:Date.now()},null,2)+'\n',{mode:0o600});
|
|
57
|
+
return {status:'INSTALLED',extensionId,manifestPath};
|
|
58
|
+
}
|
|
59
|
+
function configuration() {
|
|
60
|
+
if(!existsSync(configFile()))throw Object.assign(Error('Run host install <extension-id> first'),{code:'HOST_NOT_CONFIGURED'});
|
|
61
|
+
const config=JSON.parse(readFileSync(configFile(),'utf8'));
|
|
62
|
+
validateExtensionId(config.extensionId);
|
|
63
|
+
return config;
|
|
64
|
+
}
|
|
65
|
+
function openAction(url) {
|
|
66
|
+
return openExtensionActionPage(url);
|
|
67
|
+
}
|
|
68
|
+
async function executeAction(action,intent) {
|
|
69
|
+
if(!ACTIONS.includes(action))throw Object.assign(Error('Unknown action'),{code:'UNKNOWN_ACTION'});
|
|
70
|
+
const config=configuration(),req=prepare(action,intent);
|
|
71
|
+
const descriptor=actionById.get(action);
|
|
72
|
+
const page=descriptor?.page;
|
|
73
|
+
if(!page)throw Object.assign(Error('Unknown action'),{code:'UNKNOWN_ACTION'});
|
|
74
|
+
const url='chrome-extension://'+config.extensionId+'/'+page+'?requestId='+req.id
|
|
75
|
+
+(action==='session'?'&operation='+intent.operation:'');
|
|
76
|
+
openAction(url);
|
|
77
|
+
const until=Date.now()+descriptor.waitMs;
|
|
78
|
+
while(Date.now()<until){
|
|
79
|
+
const result=readResult(req.id);
|
|
80
|
+
if(result){
|
|
81
|
+
if(result.status!=='OK')throw Object.assign(Error(result.code||'ACTION_FAILED'),{code:result.code||'ACTION_FAILED'});
|
|
82
|
+
if(!result.verified) return {...result,status:'ACCEPTED_UNVERIFIED'};
|
|
83
|
+
// The temp file is the canonical artifact. Returning small text is a CLI convenience.
|
|
84
|
+
if(descriptor.textResult){
|
|
85
|
+
const contents=readFileSync(result.path,'utf8');
|
|
86
|
+
return {...result,content:contents.length<=500000?contents:undefined,
|
|
87
|
+
truncated:contents.length>500000};
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
await wait(100);
|
|
92
|
+
}
|
|
93
|
+
throw Object.assign(Error('No verified Extension Action result; do not retry blindly'),{code:'RESULT_TIMEOUT'});
|
|
94
|
+
}
|
|
95
|
+
async function readIntent() {
|
|
96
|
+
// Only for model control tools. Read a bounded stdin payload; never embed text in URL/argv.
|
|
97
|
+
if(process.stdin.isTTY)throw Object.assign(Error('JSON intent required on stdin'),{code:'INVALID_INTENT'});
|
|
98
|
+
let body='';
|
|
99
|
+
process.stdin.setEncoding('utf8'); // JSON intent may span UTF-8 chunks.
|
|
100
|
+
for await(const chunk of process.stdin){
|
|
101
|
+
body+=chunk;
|
|
102
|
+
if(body.length>6000)throw Object.assign(Error('Model intent too large'),{code:'INVALID_INTENT'});
|
|
103
|
+
}
|
|
104
|
+
try {return JSON.parse(body);}catch{
|
|
105
|
+
throw Object.assign(Error('Invalid JSON intent'),{code:'INVALID_INTENT'});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function readOptionalStatusIntent(){
|
|
109
|
+
if(process.stdin.isTTY)return undefined;
|
|
110
|
+
let body='';
|
|
111
|
+
process.stdin.setEncoding('utf8');
|
|
112
|
+
for await(const chunk of process.stdin){
|
|
113
|
+
body+=chunk;
|
|
114
|
+
if(body.length>2048)throw Object.assign(Error('Status input too large'),
|
|
115
|
+
{code:'INVALID_TASK_STATUS_INTENT'});
|
|
116
|
+
}
|
|
117
|
+
if(!body.trim())return undefined;
|
|
118
|
+
try{return JSON.parse(body);}
|
|
119
|
+
catch{throw Object.assign(Error('Invalid Task status JSON'),
|
|
120
|
+
{code:'INVALID_TASK_STATUS_INTENT'});}
|
|
121
|
+
}
|
|
122
|
+
async function execute(argv) {
|
|
123
|
+
const cmd=argv.join(' ');
|
|
124
|
+
if(argv.length===0||cmd==='capabilities'){
|
|
125
|
+
return {implemented:['capabilities','host install <extension-id>',
|
|
126
|
+
...actionCapabilities.map(cap=>'extension '+cap.cli.join(' ')+
|
|
127
|
+
(cap.kind==='owner-clean'?' <tab-id>':
|
|
128
|
+
['owner-intent','owner-start','owner-session',
|
|
129
|
+
'entry-test'].includes(cap.kind)?' (JSON on stdin)':''))],
|
|
130
|
+
available:existsSync(configFile()),hostConfigured:existsSync(configFile())};
|
|
131
|
+
}
|
|
132
|
+
if(argv[0]==='host'&&argv[1]==='install'&&argv.length===3)return installHost(argv[2]);
|
|
133
|
+
const route=matchExtensionAction(actionCapabilities,argv);
|
|
134
|
+
if(route)return executeAction(route.id,route.id==='status'
|
|
135
|
+
?await readOptionalStatusIntent()
|
|
136
|
+
:route.needsIntent?await readIntent():route.intent);
|
|
137
|
+
throw Object.assign(Error('Unknown command'),{code:'INVALID_ARGUMENT'});
|
|
138
|
+
}
|
|
139
|
+
const args=process.argv.slice(2),command=args.join(' ')||'capabilities';
|
|
140
|
+
const help=helpFor(args);
|
|
141
|
+
if(help!==null){
|
|
142
|
+
process.stdout.write(help+'\n');
|
|
143
|
+
}else{
|
|
144
|
+
emit('STARTED',command);
|
|
145
|
+
try{
|
|
146
|
+
const data=await execute(args);
|
|
147
|
+
emit('RESULT',command,{ok:true,value:data});
|
|
148
|
+
}catch(e){
|
|
149
|
+
const code=typeof e?.code==='string'&&/^[A-Z][A-Z0-9_]{1,95}$/.test(e.code)
|
|
150
|
+
?e.code:'UNKNOWN_RESULT';
|
|
151
|
+
// Preserve the versioned CLI error shape but never publish arbitrary
|
|
152
|
+
// native/OS error messages or absolute paths through stdout.
|
|
153
|
+
emit('RESULT',command,{ok:false,error:{code,message:code}});
|
|
154
|
+
process.exitCode=1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// After the CLI reply is produced, allow bounded observation delivery.
|
|
158
|
+
// This never changes its result or retries its business side effect.
|
|
159
|
+
try{
|
|
160
|
+
const audit=await cliContract[Symbol.for('chat-loop.telemetry.drain.internal')]?.(5000);
|
|
161
|
+
if(audit?.status!=='OK'){
|
|
162
|
+
// The already-emitted RESULT remains authoritative even if Trace stalls.
|
|
163
|
+
process.stderr.write('CHAT_LOOP_AUDIT_GAP '+JSON.stringify({
|
|
164
|
+
component:'extension.cli',...audit})+'\n');
|
|
165
|
+
}
|
|
166
|
+
}catch{
|
|
167
|
+
// Soft telemetry must not change the CLI exit code after its business reply.
|
|
168
|
+
}
|