@tomflow/chatloop-tools 0.4.34 → 0.9.0
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/README.md +117 -127
- package/bin/cli.mjs +48 -38
- package/bin/supervisor.mjs +4 -0
- package/index.mjs +238 -0
- package/lib/adapters/fixture.mjs +3 -2
- package/lib/adapters/index.mjs +14 -5
- package/lib/adapters/mcp-child.mjs +29 -7
- package/lib/adapters/tunnel.mjs +25 -7
- package/lib/api-aspect.mjs +190 -0
- package/lib/cli-command-router.mjs +34 -0
- package/lib/context-control-auth.mjs +12 -1
- package/lib/context-control-run.mjs +17 -79
- package/lib/context-gateway.mjs +108 -15
- package/lib/control.mjs +3 -2
- package/lib/extension-cli-contract.mjs +22 -0
- package/lib/extension-proxy.mjs +48 -19
- package/lib/gateway.mjs +46 -176
- package/lib/mcp-tool-router.mjs +60 -0
- package/lib/release-owner-preflight.mjs +41 -0
- package/lib/release.mjs +94 -49
- package/lib/{supervisor.mjs → supervisor-runtime.mjs} +143 -80
- package/lib/trace-gateway.mjs +12 -1
- package/lib/trace-observation.mjs +118 -0
- package/lib/tunnel.mjs +17 -29
- package/package.json +20 -14
- package/providers/context.mjs +20 -0
- package/providers/desktop.mjs +80 -0
- package/{lib/extension-contract.mjs → providers/extension.mjs} +36 -0
- package/providers/runtime.mjs +32 -0
- package/providers/trace.mjs +25 -0
- package/providers.generated.mjs +8 -0
- package/scripts/build-providers.mjs +69 -0
- package/lib/context-cli.mjs +0 -2
- package/lib/context-migration.mjs +0 -2
- package/lib/context-protocol.mjs +0 -2
- package/lib/task-registry-managed.mjs +0 -38
- package/lib/task-registry.mjs +0 -221
- package/node_modules/@tomflow/chatloop-context/README.md +0 -271
- package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -273
- package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -301
- package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -272
- package/node_modules/@tomflow/chatloop-context/lib/context-protocol.mjs +0 -1617
- package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -264
- package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -219
- package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -455
- package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -159
- package/node_modules/@tomflow/chatloop-context/package.json +0 -21
- package/node_modules/@tomflow/chatloop-trace/README.md +0 -13
- package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -259
- package/node_modules/@tomflow/chatloop-trace/package.json +0 -11
package/README.md
CHANGED
|
@@ -1,140 +1,130 @@
|
|
|
1
1
|
# @tomflow/chatloop-tools
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Tools is the single private MCP Gateway and local Supervisor for Chat Loop.
|
|
4
|
+
The installed SDK and its CLI entrypoints are stable; tool capabilities are
|
|
5
|
+
independently assembled at **build time**, not detected from arbitrary runtime
|
|
6
|
+
files, registry URLs, or user-supplied executable paths.
|
|
7
|
+
|
|
8
|
+
## Public entrypoints
|
|
9
|
+
|
|
10
|
+
- npm SDK: `index.mjs` exposes `loadToolsCli()` and `runToolsSupervisor()`.
|
|
11
|
+
- npm executable: `bin/cli.mjs`, command `chatloop-tools`.
|
|
12
|
+
- Private process entry: `bin/supervisor.mjs`; not another npm executable.
|
|
13
|
+
- MCP stdio: `chatloop-tools mcp`.
|
|
14
|
+
|
|
15
|
+
Run `chatloop-tools --help`, `chatloop-tools capabilities`, or
|
|
16
|
+
`chatloop-tools doctor` for the installed commands and local readiness.
|
|
17
|
+
Doctor does not verify ChatGPT authorization, Chrome Owner, or deployment.
|
|
18
|
+
|
|
19
|
+
`chatloop-tools api-usage 60` asks the **existing local Supervisor** for the last
|
|
20
|
+
60 minutes of recorded MCP, Tools SDK/CLI, Extension/Native, Trace SDK and
|
|
21
|
+
platform Tunnel SDK API calls.
|
|
22
|
+
With an exact authorized Context Project grant it also aggregates that
|
|
23
|
+
Project's sanitized `context.api` events. Counts, success, failure,
|
|
24
|
+
incomplete calls and calls per minute are grouped by named entrypoint and
|
|
25
|
+
deduplicated by call/span ID; unmatched completions are reported separately.
|
|
26
|
+
Nested calls share a soft `traceId` and retain unique `spanId/parentSpanId`,
|
|
27
|
+
including a sanitized MCP-to-Context-CLI parent handoff.
|
|
28
|
+
It never starts a Supervisor, opens a browser, replays a call, or reads model
|
|
29
|
+
inputs. The Trace writer stores only safe API identity, call ID, phase, time
|
|
30
|
+
and bounded duration/error code; Context logs remain Project-scoped.
|
|
31
|
+
Browser dispatch is only listener acceptance, not an authenticated user
|
|
32
|
+
click or successful ChatGPT action. These rates are **API invocation rates**,
|
|
33
|
+
not UI click-through rates. This is best-effort telemetry, not proof that
|
|
34
|
+
every standalone package invocation reached the Supervisor; without a
|
|
35
|
+
verified running Supervisor it returns BLOCKED, not invented data.
|
|
36
|
+
`npm run check` verifies generated six-package AOP copies and all published
|
|
37
|
+
callable SDK facades (the gate reports its live count), while Context's 34
|
|
38
|
+
declared methods and MCP Provider
|
|
39
|
+
catalog have separate capability tests. Internal Trace Writer health/record
|
|
40
|
+
operations are excluded from re-submitting themselves to prevent recursive logs.
|
|
41
|
+
Non-authoritative process/control logs use a bounded async queue, with drops
|
|
42
|
+
and pending counts visible in Supervisor Trace health.
|
|
8
43
|
|
|
9
44
|
```text
|
|
10
45
|
Usage: chatloop-tools <command> [target]
|
|
11
|
-
Commands: doctor, mcp, start, stop, restart, status, upgrade, tunnel, capabilities,
|
|
46
|
+
Commands: doctor, mcp, start, stop, restart, status, upgrade, tunnel, capabilities, api-usage
|
|
12
47
|
Run: chatloop-tools <command> --help
|
|
13
48
|
```
|
|
14
49
|
|
|
15
|
-
```sh
|
|
16
|
-
npx --yes --package=@tomflow/chatloop-tools@latest chatloop-tools start --help
|
|
17
|
-
```
|
|
18
|
-
|
|
19
50
|
```text
|
|
20
51
|
Usage: chatloop-tools start [desktop-commander|tunnel]
|
|
21
52
|
Start all enabled tools or one.
|
|
22
53
|
```
|
|
23
54
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
`Requires explicit CHAT_LOOP_CONTEXT_DB and CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS. Classify/import-sources/prepare/activate require interactive operator consent; never execute as an MCP tool.`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
**V6 Project Material**:版本化的项目专属指令、历史全文与旧证据统一入库,`project.material.list` 只出元数据,`project.material.get` 必须带精确版本才返正文;同 ID+版本不可修改,原物理 Markdown 的整份正文及 SHA-256 经 `context import-sources <projectId> <privateReviewJsonPath>` 真实本地操作员核验后仅登记为 `LEGACY_UNVERIFIED`。不因此导入 R/P 批准、Chrome Owner 或伪 Checkpoint。旧 `schemaVersion=5` Store 不自动升为 v6,必须另有可回滚迁移。
|
|
104
|
-
|
|
105
|
-
混合 `CURRENT.md` 必须先通过本机 `context classify <projectId> <shadowManifestPath> <privateReviewJsonPath>` 人工归属审核,再进入 `prepare`。Review JSON 必须含核实过的 `projectId/sourceUnitId/sourceHash/currentFactsComplete/reviewRef/projectSharedContext/taskContexts/unknownHistoryRefs`,其中 `unknownHistoryRefs` **必须至少包含整个原文件的精确绝对路径与源 SHA-256**,即使已分类当前事实也保留历史 EvidenceOnly。只接受当前操作员可访问的 0600 私有 Review 文件、原物理 SourceUnit 不变与精确 revision;没有可信归属、review 或真实操作员输入时继续 SHADOW_RO,不得自动认领。已存在的旧格式 SQLite 数据库不会自动升级或覆盖:先核对 schema/epoch/mode,升级方案及备份未核实之前明确拒绝。
|
|
106
|
-
|
|
107
|
-
迁移按 SourceUnit 只读扫描/哈希对账 → SHADOW_RO → CUTOVER_FENCED → MANAGED_RW;旧 Registry 写入口只有**源单元已证明切换**后才拒写,新客户端不得双写,旧缓存进程不受新 adapter 自动约束。`context restore-branch` 只生成**新 epoch 的诊断只读分支**,不自动恢复 Browser Owner、用户审批或私有写凭据;恢复包、未知副作用与原文件保留。`/g` ChatGPT Project 路由当前仍必须单独验证,不允许绕过 Handoff guard。
|
|
108
|
-
|
|
109
|
-
**迁移写权门禁(源码候选)**:`project.authority(projectId)` 是只读可回查入口,区分 SQLite `ACTIVE` 与物理 SourceUnit `MANAGED_RW`。已导入 `LEGACY_UNVERIFIED` 的正文若没有对应已激活且来源路径+哈希均相符的 SourceUnit,返回 `MIGRATION_NOT_MANAGED/writable=false`;普通 MCP 写和 Native 运行绑定拒绝 `PROJECT_CUTOVER_NOT_VERIFIED`,保留只读检查。新 Project 没有遗留来源且 Store ACTIVE 时返回 `NEW_PROJECT`。实际切换仍需本地操作员 TTY 与旧写者收口,不能靠 `project.patch` 伪造。
|
|
110
|
-
|
|
111
|
-
## Context SDK CLI (候选,未发布)
|
|
112
|
-
|
|
113
|
-
独立 Context npm 包源码在 ../context,候选包名 @tomflow/chatloop-context@0.1.0。真实 ChatGPT Agent 通过已连接的两个 MCP 工具 chat_loop_context_get / chat_loop_context_mutate 访问 SDK,而不是直接操作本机 Node/SQLite。调用前先用 sdk.methods.list 获取方法摘要,再按需要用 sdk.methods.describe 获取精确参数合同;SDK、CLI 和 MCP Schema 共用一个 Method Catalog。
|
|
114
|
-
|
|
115
|
-
Tools 的普通 MCP 实现直接调用**自身固定依赖**的独立 Context SDK CLI(`require.resolve('@tomflow/chatloop-context/cli')`,受信 Node24 子进程,非 `npx`),省去每个请求额外一次 npm 离线解析与缓存查找;版本从已安装 SDK Method Catalog 与 CLI 回执核对,不能由模型指定包版本、执行路径或参数。内部 Native run.bind/fence/permit 依旧限制在已有签名控制通道。**独立 Project 库候选**:设置 `CHAT_LOOP_CONTEXT_API_ENABLE=1`、`CHAT_LOOP_CONTEXT_ROOT=<privateContextRoot>`、`CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS=<grantedId>`(不设置 `CHAT_LOOP_CONTEXT_DB`);普通 Gateway 和 Native 签名 IPC 共用 SDK 的 Project 身份校验与同一份 `<projectId>/context.sqlite`。旧共享 Store 仅在单独配置 `CHAT_LOOP_CONTEXT_DB` 时作为迁移兼容入口;两种根路径同时配置会拒绝提供 Context MCP、Native 写入与 SDK 数据访问,以防双写。Native 内部权限仍需要实际 Extension/Owner 身份、Session 及运行凭证通过,根路径并不授权执行。已完成隔离 Gateway/Native Handoff 回归,**不是生产旧版 Tools 或真实 Chrome 已升级**。当前发布版的真实 tools/list 尚未升级,因此这只是代码候选;完成 npm 打包、发布、连接回读和旧写者收口之前,禁止生产数据切换,也不得把本地测试视为真实 Chrome E2E。
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
## 单一 Tools tarball 发行候选(尚未发布)
|
|
119
|
-
|
|
120
|
-
`@tomflow/chatloop-tools` 是用户连接 ChatGPT 的唯一 Tools 安装入口。
|
|
121
|
-
其 SDK 依赖仍各自独立维护,Tools 仅在构建发布包时将精确固定版本的
|
|
122
|
-
`@tomflow/chatloop-context` 和 `@tomflow/chatloop-trace` 作为 npm
|
|
123
|
-
`bundleDependencies` 放入一份 Tools tarball,避免要求用户先安装或
|
|
124
|
-
发布另外两个 SDK。这不是新增服务,也不改变 SDK 方法/版本合同。
|
|
125
|
-
|
|
126
|
-
在仓库根使用 `npm run pack:tools -- /absolute/existing/output-directory`
|
|
127
|
-
进行**离线、本地、无发布副作用**的打包。构建脚本先比对 Tools
|
|
128
|
-
dependencies 与两个 SDK 实际 package version,只复制三个包各自的
|
|
129
|
-
发行白名单文件,不追随 workspace symlink;在独立临时目录执行
|
|
130
|
-
`npm pack --offline --ignore-scripts` 并核对真正 bundled 文件,
|
|
131
|
-
然后以禁止覆盖的方式产出 tarball 与 SHA-256 回执。
|
|
132
|
-
**不要直接从 workspace `npm pack packages/local-tools` 作为正式
|
|
133
|
-
捆绑发行包**:该位置的 SDK `node_modules` 是开发用 symlink,
|
|
134
|
-
常规 pack 无法证明 SDK 实际随包交付。
|
|
135
|
-
|
|
136
|
-
已经在干净目录中**只安装这一份 Tools tarball**(本机离线),
|
|
137
|
-
验证其 bundled Context/Trace 均可加载,且 Gateway 不经 npx 完成
|
|
138
|
-
独立 Project SQLite 的 get → mutate → readback。正式 npm publish、
|
|
139
|
-
升级 Supervisor/Tunnel、可信操作员 SourceUnit 审核及 Chrome Owner E2E
|
|
140
|
-
仍是后续独立门禁,**不得用打包通过代替生产已部署**。
|
|
55
|
+
## Capability composition
|
|
56
|
+
|
|
57
|
+
`providers/<id>.mjs` owns each MCP Provider's tool names, schemas,
|
|
58
|
+
activation condition, scoped call adapter and optional CLI commands.
|
|
59
|
+
|
|
60
|
+
The five built-in Providers are:
|
|
61
|
+
|
|
62
|
+
- `desktop`: allowlisted Desktop Commander tools and isolated fixtures
|
|
63
|
+
- `extension`: official pinned Extension CLI and nine scoped actions
|
|
64
|
+
- `runtime`: exact-request receipt lookup without replay
|
|
65
|
+
- `context`: independent Context SDK read/write schemas and fixed CLI
|
|
66
|
+
- `trace`: Project-scoped diagnosis and SOFT stage observations
|
|
67
|
+
|
|
68
|
+
`npm run build:providers` generates `providers.generated.mjs`, the static
|
|
69
|
+
assembly and release fingerprint manifest. Both `tools/list` and `tools/call`
|
|
70
|
+
use a single `lib/mcp-tool-router.mjs` instance. `lib/gateway.mjs` handles
|
|
71
|
+
MCP framing only; it knows no individual Provider. There is no parallel
|
|
72
|
+
hand-maintained API inventory or runtime plugin directory scan.
|
|
73
|
+
|
|
74
|
+
`lib/cli-command-router.mjs` also recognizes additional CLI commands owned
|
|
75
|
+
by Providers, without another central command branch.
|
|
76
|
+
|
|
77
|
+
### Add a tool or CLI command
|
|
78
|
+
|
|
79
|
+
1. Create `providers/<id>.mjs` with a `provider` export: unique `id` and
|
|
80
|
+
`names`, plus `create(services)` returning `tools()` and `call(name,args)`.
|
|
81
|
+
An optional `commands` list can declare `name`, `help` and
|
|
82
|
+
`run({args,api})` returning `{exitCode,result}`.
|
|
83
|
+
A CLI-only Provider may set `names:[]` and omit `create()` entirely;
|
|
84
|
+
it does not need a fake MCP tool or adapter.
|
|
85
|
+
2. Build: `npm run build:providers`.
|
|
86
|
+
3. Verify: `npm run build:providers:check`, `npm test` and workspace
|
|
87
|
+
`npm run check`.
|
|
88
|
+
|
|
89
|
+
The compiler rejects duplicate tool and command identities, missing
|
|
90
|
+
implementations, and attempts to shadow built-in CLI names. At runtime
|
|
91
|
+
unregistered, undeclared and disabled tools fail closed as `UNKNOWN_TOOL`.
|
|
92
|
+
`test/provider-composition.test.mjs` demonstrates adding and removing a
|
|
93
|
+
sixth isolated Provider with an MCP tool and CLI command, with no edits
|
|
94
|
+
to any existing Provider, the Gateway, or either npm entrypoint.
|
|
95
|
+
|
|
96
|
+
## Authority and lifecycle
|
|
97
|
+
|
|
98
|
+
- Desktop Commander publishes only the reviewed 21 tools, regardless of
|
|
99
|
+
upstream vendor additions. GUI Terminal launches remain prohibited.
|
|
100
|
+
- Context enforces Project authorization, CAS, Store epochs, and durable
|
|
101
|
+
request receipts. Tools does not own a second task database.
|
|
102
|
+
- Extension alone controls browser Owner and actual ChatGPT Action sends.
|
|
103
|
+
- Supervisor alone owns child-process lifecycle, serialization, unknown
|
|
104
|
+
side-effect receipts and the single Trace writer.
|
|
105
|
+
- Trace observations and logging never authorize business writes or
|
|
106
|
+
trigger retries of unknown effects. In particular, verified Extension MCP
|
|
107
|
+
results are returned **before** optional Trace transport finishes; a
|
|
108
|
+
slow, rejecting or unavailable observer cannot replace the action receipt.
|
|
109
|
+
These events are best-effort evidence, not an all-API AOP coverage claim.
|
|
110
|
+
|
|
111
|
+
No legacy Task Registry MCP or JSON fallback is shipped. Historical
|
|
112
|
+
SourceUnit files remain migration evidence, not alternate current facts.
|
|
113
|
+
|
|
114
|
+
## Local validation and packaging
|
|
115
|
+
|
|
116
|
+
- `npm test` runs isolated package and Gateway regression tests.
|
|
117
|
+
- Workspace `npm run check` verifies API boundaries, source syntax,
|
|
118
|
+
documentation links, and both Context/Tools generated compositions.
|
|
119
|
+
- Workspace `npm run pack:tools -- <existing-output-directory>` produces
|
|
120
|
+
an offline, version-pinned Tools tarball containing the declared Context
|
|
121
|
+
and Trace SDKs. The build checks the provider manifest before packaging.
|
|
122
|
+
Release staging uses the **candidate package's own** generated Provider manifest
|
|
123
|
+
and fingerprints every Tools-owned source file, including new Provider helpers;
|
|
124
|
+
missing, substituted, or added files block activation before Owner handoff.
|
|
125
|
+
- `chatloop-tools upgrade prepare <absolute-tarball.tgz> <sha256>` and
|
|
126
|
+
`chatloop-tools upgrade activate <sha256>` are separate authorized steps.
|
|
127
|
+
|
|
128
|
+
Source tests and a release tarball do **not** prove npm publication, an
|
|
129
|
+
installed Supervisor upgrade, private MCP activation or real Chrome E2E.
|
|
130
|
+
Check the installed version and authoritative runtime evidence separately.
|
package/bin/cli.mjs
CHANGED
|
@@ -5,35 +5,39 @@ import {randomUUID} from 'node:crypto';
|
|
|
5
5
|
import {createRequire} from 'node:module';
|
|
6
6
|
import {dirname,join} from 'node:path';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
|
-
import {
|
|
9
|
-
safeFallback,recoverStaleLock,exitCode,talk} from '../lib/control.mjs';
|
|
10
|
-
import {runGateway} from '../lib/gateway.mjs';
|
|
11
|
-
import {tunnelDoctor,runTunnel} from '../lib/tunnel.mjs';
|
|
12
|
-
import {promptTunnelRuntimeKey,storeTunnelRuntimeKey} from '../lib/tunnel-auth.mjs';
|
|
13
|
-
import {upgradeRuntime,runtimeNeedsUpgrade,prepareReleaseCandidate} from '../lib/release.mjs';
|
|
8
|
+
import {loadToolsCli} from '../index.mjs';
|
|
14
9
|
|
|
10
|
+
const cliApi=await loadToolsCli();
|
|
11
|
+
const cliExtensions=cliApi.cliExtensions;
|
|
15
12
|
const HELP={
|
|
16
|
-
'': 'Usage: chatloop-tools <command> [target]\nCommands: doctor, mcp, start, stop, restart, status, upgrade, tunnel, capabilities,
|
|
13
|
+
'': 'Usage: chatloop-tools <command> [target]\nCommands: doctor, mcp, start, stop, restart, status, upgrade, tunnel, capabilities, api-usage\nRun: chatloop-tools <command> --help',
|
|
17
14
|
doctor:'Usage: chatloop-tools doctor\nInspect local readiness without changing services.',
|
|
18
15
|
mcp:'Usage: chatloop-tools mcp\nServe namespaced MCP tools over stdio.',
|
|
19
16
|
start:'Usage: chatloop-tools start [desktop-commander|tunnel]\nStart all enabled tools or one.',
|
|
20
17
|
stop:'Usage: chatloop-tools stop [desktop-commander|tunnel]\nStop all enabled tools or one.',
|
|
21
18
|
restart:'Usage: chatloop-tools restart [desktop-commander|tunnel]\nRestart all or one.',
|
|
22
19
|
status:'Usage: chatloop-tools status [desktop-commander|tunnel]\nRead runtime state.',
|
|
23
|
-
upgrade:'Usage: chatloop-tools upgrade prepare <absolute-tarball.tgz> <sha256> | upgrade activate <sha256>\nPrepare is offline and never stops the old service. Activate checks the expected artifact SHA-256 before stopping any service
|
|
24
|
-
tunnel:'Usage: chatloop-tools tunnel <doctor|auth|--version
|
|
20
|
+
upgrade:'Usage: chatloop-tools upgrade prepare <absolute-tarball.tgz> <sha256> | upgrade activate <sha256>\nPrepare is offline and never stops the old service. Activate checks the expected artifact SHA-256 before stopping any service. No unpinned upgrade.',
|
|
21
|
+
tunnel:'Usage: chatloop-tools tunnel <doctor|auth|--version>\nTunnel runs under Supervisor; auth requires explicit setup.',
|
|
25
22
|
capabilities:'Usage: chatloop-tools capabilities\nList supported tool categories.',
|
|
26
|
-
|
|
23
|
+
'api-usage':'Usage: chatloop-tools api-usage [window-minutes]\nRead local Supervisor aggregated API calls and rates; never replays calls.'
|
|
27
24
|
};
|
|
28
25
|
const helpArgs=process.argv.slice(2);
|
|
29
26
|
const helpSection=helpArgs.length===1&&['-h','--help','help'].includes(helpArgs[0])?''
|
|
30
27
|
: helpArgs.at(-1)==='--help'||helpArgs.at(-1)==='-h'
|
|
31
28
|
? helpArgs.slice(0,-1).join(' '):null;
|
|
32
29
|
if(helpSection!==null){
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
await cliApi.observeCliCommand('help',async()=>{
|
|
31
|
+
const help=HELP[helpSection]||cliExtensions.help(helpSection);
|
|
32
|
+
process.stdout.write((help||'Unknown help topic. Run: chatloop-tools --help')+'\n');
|
|
33
|
+
process.exitCode=help?0:2;
|
|
34
|
+
});
|
|
35
|
+
}else{
|
|
36
36
|
|
|
37
|
+
const {lifecycleDeadlineMs,CONTRACT,ACTIONS,registry,ensurePrivateDir,
|
|
38
|
+
safeFallback,recoverStaleLock,exitCode,talk,runGateway,apiUsage,tunnelDoctor,runTunnel,
|
|
39
|
+
promptTunnelRuntimeKey,storeTunnelRuntimeKey,upgradeRuntime,runtimeNeedsUpgrade,
|
|
40
|
+
prepareReleaseCandidate}=cliApi;
|
|
37
41
|
const require=createRequire(import.meta.url);
|
|
38
42
|
const command=process.argv[2]??'doctor';
|
|
39
43
|
const extra=process.argv.slice(3);
|
|
@@ -69,7 +73,7 @@ async function connectOrLaunch(request){
|
|
|
69
73
|
}
|
|
70
74
|
throw Object.assign(new Error('Owner alive, IPC unavailable'),{code:'MANAGER_UNAVAILABLE'});
|
|
71
75
|
}
|
|
72
|
-
const entry=fileURLToPath(new URL('
|
|
76
|
+
const entry=fileURLToPath(new URL('./supervisor.mjs',import.meta.url));
|
|
73
77
|
const manager=spawn(process.execPath,[entry],{detached:true,stdio:'ignore',env:process.env});
|
|
74
78
|
manager.unref();
|
|
75
79
|
let last;
|
|
@@ -116,21 +120,8 @@ async function runControl(action=command, params=extra){
|
|
|
116
120
|
}
|
|
117
121
|
emit(reply);process.exitCode=exitCode(reply);
|
|
118
122
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// Do not even import node:sqlite on the published legacy Node 20 path.
|
|
122
|
-
emit({contract:'chat-loop.context-cli.v1',status:'BLOCKED',
|
|
123
|
-
code:'CONTEXT_RUNTIME_UNSUPPORTED'});
|
|
124
|
-
process.exitCode=5;
|
|
125
|
-
}else try{
|
|
126
|
-
const {runContextCli}=await import('../lib/context-cli.mjs');
|
|
127
|
-
emit({contract:'chat-loop.context-cli.v1',...await runContextCli(extra)});
|
|
128
|
-
}catch(e){
|
|
129
|
-
emit({contract:'chat-loop.context-cli.v1',status:'BLOCKED',
|
|
130
|
-
code:e.code||'CONTEXT_ADMIN_FAILED'});
|
|
131
|
-
process.exitCode=5;
|
|
132
|
-
}
|
|
133
|
-
}else if(command==='mcp'){
|
|
123
|
+
await cliApi.observeCliCommand(command,async()=>{
|
|
124
|
+
if(command==='mcp'){
|
|
134
125
|
if(extra.length){process.stderr.write(JSON.stringify(fail('INVALID_ARGUMENT'))+'\n');process.exitCode=2;}
|
|
135
126
|
else runGateway();
|
|
136
127
|
}else if(command==='upgrade'){
|
|
@@ -138,9 +129,7 @@ if(command==='context'){
|
|
|
138
129
|
?await prepareReleaseCandidate({tarball:extra[1],sha256:extra[2]})
|
|
139
130
|
:extra[0]==='activate'&&extra.length===2
|
|
140
131
|
?await upgradeRuntime({args:[],requirePrepared:true,expectedArtifactSha256:extra[1]})
|
|
141
|
-
:
|
|
142
|
-
?{command:'upgrade',status:'BLOCKED',code:'RELEASE_ARTIFACT_PIN_REQUIRED'}
|
|
143
|
-
:await upgradeRuntime({args:extra});
|
|
132
|
+
:{command:'upgrade',status:'BLOCKED',code:'RELEASE_ARTIFACT_PIN_REQUIRED'};
|
|
144
133
|
emit(result);if(result.status!=='OK')process.exitCode=result.status==='STARTING'?4:5;
|
|
145
134
|
}else if(command==='start'&&extra.length===0&&
|
|
146
135
|
!process.env.CHAT_LOOP_LOCAL_TOOLS_FIXTURES&&
|
|
@@ -154,12 +143,9 @@ else if(command==='doctor'){
|
|
|
154
143
|
else{const snapshot=inspect();emit({contract:'chat-loop.local-tools.v1',command,...snapshot});if(snapshot.status!=='LOCAL_READY')process.exitCode=1;}
|
|
155
144
|
}else if(command==='tunnel'){
|
|
156
145
|
if(extra.length===1&&extra[0]==='doctor'){
|
|
157
|
-
const result=tunnelDoctor();
|
|
146
|
+
const result=await tunnelDoctor();
|
|
158
147
|
emit({contract:'chat-loop.local-tools.v1',command,...result});
|
|
159
148
|
if(result.status!=='BUNDLED_READY')process.exitCode=1;
|
|
160
|
-
}else if(extra.length===1&&extra[0]==='run'){
|
|
161
|
-
// Compatibility alias: all tunnel execution now belongs to the Supervisor.
|
|
162
|
-
await runControl('start',['tunnel']);
|
|
163
149
|
}else if(extra.length===1&&extra[0]==='auth'){
|
|
164
150
|
try{
|
|
165
151
|
const key=await promptTunnelRuntimeKey();
|
|
@@ -176,13 +162,37 @@ else if(command==='doctor'){
|
|
|
176
162
|
code:e.code||'TUNNEL_EXEC_FAILED'});process.exitCode=1;}
|
|
177
163
|
}else{
|
|
178
164
|
emit({contract:'chat-loop.local-tools.v1',command,status:'FAILED',
|
|
179
|
-
code:'INVALID_ARGUMENT',usage:'tunnel doctor | tunnel --version | tunnel auth
|
|
165
|
+
code:'INVALID_ARGUMENT',usage:'tunnel doctor | tunnel --version | tunnel auth'});
|
|
180
166
|
process.exitCode=2;
|
|
181
167
|
}
|
|
168
|
+
}else if(command==='api-usage'){
|
|
169
|
+
const windowMinutes=extra.length===0?60:
|
|
170
|
+
extra.length===1&&/^[1-9][0-9]{0,3}$/.test(extra[0])?Number(extra[0]):0;
|
|
171
|
+
if(windowMinutes<1||windowMinutes>1440){
|
|
172
|
+
emit({contract:CONTRACT,command,status:'FAILED',code:'TRACE_INVALID_LIMIT'});
|
|
173
|
+
process.exitCode=2;
|
|
174
|
+
}else{
|
|
175
|
+
try{
|
|
176
|
+
const result=await apiUsage({windowMinutes});
|
|
177
|
+
emit(result);
|
|
178
|
+
if(result.status!=='OK')process.exitCode=1;
|
|
179
|
+
}catch(e){
|
|
180
|
+
emit({contract:CONTRACT,command,status:'BLOCKED',code:e.code||'MANAGER_UNAVAILABLE'});
|
|
181
|
+
process.exitCode=3;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
182
184
|
}else if(command==='capabilities'){
|
|
183
185
|
if(extra.length){emit(fail('INVALID_ARGUMENT'));process.exitCode=2;}
|
|
184
186
|
else emit({contract:'chat-loop.local-tools.v1',command,status:'OK',
|
|
185
|
-
implemented:[
|
|
187
|
+
implemented:[...Object.keys(HELP).filter(Boolean),...cliExtensions.names()].sort(),
|
|
186
188
|
lifecycle:'SUPERVISOR_MCP_GATEWAY',mcpTools:'Namespaced tool catalog',
|
|
187
189
|
tunnel:'BUNDLED_SUPERVISOR_MANAGED'});
|
|
190
|
+
}else if(cliExtensions.names().includes(command)){
|
|
191
|
+
try{
|
|
192
|
+
const outcome=await cliExtensions.execute(command,extra,cliApi);
|
|
193
|
+
emit(outcome.result);process.exitCode=outcome.exitCode;
|
|
194
|
+
}catch(e){emit({contract:'chat-loop.local-tools.v1',command,status:'FAILED',
|
|
195
|
+
code:e.code||'CLI_COMMAND_FAILED'});process.exitCode=1;}
|
|
188
196
|
}else{emit({contract:'chat-loop.local-tools.v1',command,status:'FAILED',code:'UNKNOWN_COMMAND'});process.exitCode=1;}
|
|
197
|
+
});
|
|
198
|
+
}
|