@1agents/acp-service 0.10.11 → 0.11.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 +26 -0
- package/dist/bin/acp-service.js +6 -0
- package/dist/bin/dsh.d.ts +21 -0
- package/dist/bin/dsh.js +171 -0
- package/dist/src/catalog.js +13 -3
- package/dist/src/dsh-archive.d.ts +123 -0
- package/dist/src/dsh-archive.js +99 -0
- package/dist/src/dsh-host-client.d.ts +97 -0
- package/dist/src/dsh-host-client.js +275 -0
- package/dist/src/dsh-registry-file.d.ts +22 -0
- package/dist/src/dsh-registry-file.js +55 -0
- package/dist/src/dsh-session-files.d.ts +7 -0
- package/dist/src/dsh-session-files.js +63 -0
- package/dist/src/dsh.js +1 -1
- package/package.json +4 -4
- package/skills/acp-service/SKILL.md +1 -1
- package/vendor/dsh/README.md +1 -20
- package/vendor/dsh/index.d.ts +1 -4
- package/vendor/dsh/index.js +0 -17
- package/vendor/runtime/README.md +36 -11
- package/vendor/runtime/dist/{agent-registry-DxcyXXqb.js → agent-registry-CsdsVpJb.js} +209 -177
- package/vendor/runtime/dist/agent-registry-CsdsVpJb.js.map +1 -0
- package/vendor/runtime/dist/agent-registry.d.ts +0 -2
- package/vendor/runtime/dist/agent-registry.d.ts.map +1 -1
- package/vendor/runtime/dist/agent-registry.js +1 -1
- package/vendor/runtime/dist/{cli-BKmMxgix.js → cli-B5gQOSDl.js} +33 -14
- package/vendor/runtime/dist/cli-B5gQOSDl.js.map +1 -0
- package/vendor/runtime/dist/cli.d.ts +2 -6
- package/vendor/runtime/dist/cli.d.ts.map +1 -1
- package/vendor/runtime/dist/cli.js +189 -164
- package/vendor/runtime/dist/cli.js.map +1 -1
- package/vendor/runtime/dist/{client-C5zneoBs.d.ts → client-D5y4RXME.d.ts} +4 -12
- package/vendor/runtime/dist/client-D5y4RXME.d.ts.map +1 -0
- package/vendor/runtime/dist/docs-site/CLI.html +19 -21
- package/vendor/runtime/dist/docs-site/VISION.html +3 -2
- package/vendor/runtime/dist/docs-site/agents.html +10 -15
- package/vendor/runtime/dist/docs-site/assets/agents/Apache-2.0.txt +202 -0
- package/vendor/runtime/dist/docs-site/assets/agents/LobeHub-MIT.txt +21 -0
- package/vendor/runtime/dist/docs-site/assets/agents/Mux-AGPL-3.0.txt +661 -0
- package/vendor/runtime/dist/docs-site/assets/agents/README.md +41 -0
- package/vendor/runtime/dist/docs-site/assets/agents/ante.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/antigravity.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/claude.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/codex.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/copilot.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/cursor.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/deepseek-harness.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/devin.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/droid.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/fast-agent.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/fx.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/gemini.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/goose.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/grok-build.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/iflow.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/junie.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/kilocode.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/kimi.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/kiro.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/mcode.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/mux.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/octomind.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/openclaw.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/opencode.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/pi.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/pool.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/qoder.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/qwen.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/trae.png +0 -0
- package/vendor/runtime/dist/docs-site/assets/agents/zeroclaw.png +0 -0
- package/vendor/runtime/dist/docs-site/compare.html +8 -7
- package/vendor/runtime/dist/docs-site/config.html +5 -4
- package/vendor/runtime/dist/docs-site/custom-agents.html +13 -13
- package/vendor/runtime/dist/docs-site/exit-codes.html +4 -3
- package/vendor/runtime/dist/docs-site/flows.html +21 -8
- package/vendor/runtime/dist/docs-site/index.html +7 -6
- package/vendor/runtime/dist/docs-site/install.html +7 -6
- package/vendor/runtime/dist/docs-site/llms.txt +6 -6
- package/vendor/runtime/dist/docs-site/output-formats.html +9 -8
- package/vendor/runtime/dist/docs-site/permissions.html +5 -4
- package/vendor/runtime/dist/docs-site/prompting.html +9 -7
- package/vendor/runtime/dist/docs-site/quickstart.html +5 -4
- package/vendor/runtime/dist/docs-site/releasing.html +9 -8
- package/vendor/runtime/dist/docs-site/runtime-environment.html +28 -5
- package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +13 -7
- package/vendor/runtime/dist/docs-site/safe-errors.html +3 -2
- package/vendor/runtime/dist/docs-site/session-control.html +7 -6
- package/vendor/runtime/dist/docs-site/session-watch.html +6 -5
- package/vendor/runtime/dist/docs-site/sessions.html +13 -10
- package/vendor/runtime/dist/docs-site/shared-sessions.html +7 -4
- package/vendor/runtime/dist/{flows-VrII9VKZ.js → flows-CDj5YcTh.js} +136 -68
- package/vendor/runtime/dist/flows-CDj5YcTh.js.map +1 -0
- package/vendor/runtime/dist/flows.d.ts +28 -19
- package/vendor/runtime/dist/flows.d.ts.map +1 -1
- package/vendor/runtime/dist/flows.js +1 -1
- package/vendor/runtime/dist/{invocation-options-DHMZ5Rrb.js → input-file-BsfVGZgn.js} +30 -15
- package/vendor/runtime/dist/input-file-BsfVGZgn.js.map +1 -0
- package/vendor/runtime/dist/{ipc-CNNM5DP_.js → ipc-DfqJsbk6.js} +114 -146
- package/vendor/runtime/dist/ipc-DfqJsbk6.js.map +1 -0
- package/vendor/runtime/dist/{output-DtzXtiBc.js → output-DOIF4iFc.js} +20 -47
- package/vendor/runtime/dist/output-DOIF4iFc.js.map +1 -0
- package/vendor/runtime/dist/{queue-owner-runtime-ehuh3SQU.js → queue-owner-runtime-DHBQbjXo.js} +394 -258
- package/vendor/runtime/dist/queue-owner-runtime-DHBQbjXo.js.map +1 -0
- package/vendor/runtime/dist/runtime.d.ts +37 -36
- package/vendor/runtime/dist/runtime.d.ts.map +1 -1
- package/vendor/runtime/dist/runtime.js +117 -172
- package/vendor/runtime/dist/runtime.js.map +1 -1
- package/vendor/runtime/dist/{session-options-NjpFwf-c.d.ts → session-options-Ci4aw1oD.d.ts} +13 -16
- package/vendor/runtime/dist/session-options-Ci4aw1oD.d.ts.map +1 -0
- package/vendor/runtime/dist/{session-watch-CbKfGRkZ.js → session-watch-DRwFHcWw.js} +5 -6
- package/vendor/runtime/dist/{session-watch-CbKfGRkZ.js.map → session-watch-DRwFHcWw.js.map} +1 -1
- package/vendor/runtime/dist/{watch-BGt4kcE6.js → watch-CUDGkljG.js} +3 -4
- package/vendor/runtime/dist/{watch-BGt4kcE6.js.map → watch-CUDGkljG.js.map} +1 -1
- package/vendor/runtime/package.json +3 -3
- package/vendor/runtime/skills/acpx/SKILL.md +42 -11
- package/vendor/dsh/auto-archive.d.ts +0 -103
- package/vendor/dsh/auto-archive.js +0 -175
- package/vendor/runtime/dist/agent-registry-DxcyXXqb.js.map +0 -1
- package/vendor/runtime/dist/cli-BKmMxgix.js.map +0 -1
- package/vendor/runtime/dist/client-C5zneoBs.d.ts.map +0 -1
- package/vendor/runtime/dist/flows-VrII9VKZ.js.map +0 -1
- package/vendor/runtime/dist/invocation-options-DHMZ5Rrb.js.map +0 -1
- package/vendor/runtime/dist/ipc-CNNM5DP_.js.map +0 -1
- package/vendor/runtime/dist/output-DtzXtiBc.js.map +0 -1
- package/vendor/runtime/dist/queue-owner-runtime-ehuh3SQU.js.map +0 -1
- package/vendor/runtime/dist/session-options-NjpFwf-c.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -42,6 +42,32 @@ acp-service serve --host 127.0.0.1 --port 36812 --no-report
|
|
|
42
42
|
|
|
43
43
|
The service uses **ACP v1 JSON-RPC 2.0 over WebSocket**. DSH is unnecessary for the standalone entry points. A2A delegation is opt-in and disabled by default; its configuration is documented below. Waking a calling system's main Agent after task completion requires that system's receiving host adapter.
|
|
44
44
|
|
|
45
|
+
## Archiving silent DSH sessions
|
|
46
|
+
|
|
47
|
+
`acp-service dsh archive` archives DSH sessions that have been idle for a chosen number of days. It is a manual command: it installs no timer into DSH, changes no plugin configuration, and runs only when invoked. Archiving hides a session from the workspace grouping; it never deletes the session or its log, and the session can be restored from DSH's archived list.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
acp-service dsh archive --days 7 --dry-run # list what would be archived
|
|
51
|
+
acp-service dsh archive --days 7 # archive it
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| Option | Meaning |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `--days <n>` | Idle threshold in days; default `7`. |
|
|
57
|
+
| `--url <origin>` | DSH Host origin. Repeatable, tried in order. Omitted, the command probes the machine's loopback listeners. |
|
|
58
|
+
| `--dry-run` | Print the plan and change nothing. |
|
|
59
|
+
| `--include-pinned` | Archive pinned sessions too. Pinned sessions are skipped by default. |
|
|
60
|
+
| `--stop-activity` | Allow stopping a session's running work. Running sessions are skipped by default. |
|
|
61
|
+
| `--json` | Machine-readable output. |
|
|
62
|
+
|
|
63
|
+
**How "idle" is measured.** Last activity is the later of the Host's own recency (session creation time or its last real user message) and the modification time of the session's durable log file. A cold session whose log was written recently — a tool result, a title rewrite, a compaction — therefore does not count as silent.
|
|
64
|
+
|
|
65
|
+
**Which sessions are skipped.** Already archived sessions, sessions with running work (unless `--stop-activity`), and pinned sessions (unless `--include-pinned`). A pin is the explicit "keep this visible" signal, so it stays a manual decision.
|
|
66
|
+
|
|
67
|
+
**How it talks to DSH.** The command calls the running Host's own `workspace` service over its Typert RPC (`/api/workspace/archiveSession`), so the archive stays the Host's durable state. It authenticates as the Host's owner with a browser-session cookie minted from the local credential store (`$DSH_HOME/.credentials.yaml`), which is the same principal the DSH UI acts as on the machine that owns the Host.
|
|
68
|
+
|
|
69
|
+
**Two Hosts, one DSH home.** A `dsh web` instance and the desktop app can share `$DSH_HOME`, and each holds the workspace registry in memory while rewriting the whole document on every change. Planning therefore reads the durable registry document, and the command **refuses to write** through a Host whose registry is missing entries the document records — that Host started before the newer archives were written, and its next write would drop them. Restart that instance so it reloads, then run the command again. Auto-discovery prefers a Host that already matches the document; an explicit `--url` is always honoured, and the safety check still applies to it.
|
|
70
|
+
|
|
45
71
|
## Bundled usage skill
|
|
46
72
|
|
|
47
73
|
[ACP Service skill](skills/acp-service/SKILL.md) is distributed in this npm package and maintained with the source. It covers entry-point selection, ACP CLI/WebSocket sessions, DSH presets and native model controls, A2A delegation, task queries and the durable completion inbox. Detailed examples are included in its `references/` directory.
|
package/dist/bin/acp-service.js
CHANGED
|
@@ -60,6 +60,7 @@ function printUnifiedHelp(binName) {
|
|
|
60
60
|
ticket show|events|proposal --job <id> Read a job's task ticket and its events, or settle a proposal
|
|
61
61
|
process list|answer --job <id> Read a job's process requests, or answer one as the coach or a person
|
|
62
62
|
trail --job <id> One task's record: who asked, what ran, who approved, what came out, who read it
|
|
63
|
+
dsh archive --days <n> [--dry-run] Archive DSH sessions that have been silent for n days (manual; no timer)
|
|
63
64
|
serve [options] Start DreamMate Network ACP runtime daemon (HTTP + WS)`;
|
|
64
65
|
help = help.replace(/^Commands:/m, serverCommands);
|
|
65
66
|
const serverOptions = `Options:
|
|
@@ -161,6 +162,11 @@ async function main() {
|
|
|
161
162
|
await runRsiCli(rawArgs.slice(1));
|
|
162
163
|
return;
|
|
163
164
|
}
|
|
165
|
+
if (rawArgs[0] === 'dsh') {
|
|
166
|
+
const { runDshArchiveCli } = await import('./dsh.js');
|
|
167
|
+
await runDshArchiveCli(rawArgs.slice(1));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
164
170
|
const isServe = rawArgs[0] === 'serve' || rawArgs[0] === 'run';
|
|
165
171
|
const hasServerExplicitFlag = rawArgs[0] === '--port' ||
|
|
166
172
|
rawArgs[0] === '-p' ||
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Options the command accepts. */
|
|
2
|
+
interface ArchiveArgs {
|
|
3
|
+
days: number;
|
|
4
|
+
urls: string[];
|
|
5
|
+
dryRun: boolean;
|
|
6
|
+
includePinned: boolean;
|
|
7
|
+
stopActivity: boolean;
|
|
8
|
+
json: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Parse the command line, rejecting values that cannot mean anything. */
|
|
11
|
+
export declare function parseArchiveArgs(argv: string[]): ArchiveArgs;
|
|
12
|
+
/** The DSH home directory whose storage and credentials the command reads. */
|
|
13
|
+
export declare function resolveDshHome(env?: NodeJS.ProcessEnv): string;
|
|
14
|
+
/**
|
|
15
|
+
* Run the archive command.
|
|
16
|
+
*
|
|
17
|
+
* @param argv - the command's arguments, without the command name.
|
|
18
|
+
* @param env - the environment, for the DSH home directory.
|
|
19
|
+
*/
|
|
20
|
+
export declare function runDshArchiveCli(argv: string[], env?: NodeJS.ProcessEnv): Promise<void>;
|
|
21
|
+
export {};
|
package/dist/bin/dsh.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `acp-service dsh archive` — archive DSH sessions that have been silent.
|
|
3
|
+
*
|
|
4
|
+
* The command is manual by design: it runs when a person asks it to, against
|
|
5
|
+
* a DSH Host that is already running. It never installs a timer and never
|
|
6
|
+
* changes the Host's plugin configuration.
|
|
7
|
+
*/
|
|
8
|
+
import { parseArgs } from 'node:util';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { planArchive, runArchive, DAY_MS } from '../src/dsh-archive.js';
|
|
12
|
+
import { DshHostClient, DshRpcError, discoverHost, mintSessionCookie, readBrowserSessionSecret } from '../src/dsh-host-client.js';
|
|
13
|
+
import { readRegistryFile } from '../src/dsh-registry-file.js';
|
|
14
|
+
import { readSessionFileMtimes } from '../src/dsh-session-files.js';
|
|
15
|
+
const USAGE = `用法: acp-service dsh archive [选项]
|
|
16
|
+
|
|
17
|
+
归档 DSH 中静默超过指定天数的会话。命令手动执行,不会安装定时器,也不改动 DSH 插件配置。
|
|
18
|
+
归档只隐藏会话,不删除会话日志;可用 DSH 界面的归档列表随时恢复。
|
|
19
|
+
|
|
20
|
+
选项:
|
|
21
|
+
--days <n> 静默天数阈值(默认: 7)
|
|
22
|
+
--url <origin> DSH Host 地址,可重复指定;省略时自动探测本机监听端口
|
|
23
|
+
--dry-run 只列出将要归档的会话,不做任何改动
|
|
24
|
+
--include-pinned 连置顶会话一起归档(默认跳过,置顶表示「保留可见」)
|
|
25
|
+
--stop-activity 允许停止正在运行的会话来完成归档(默认跳过运行中的会话)
|
|
26
|
+
--json 以 JSON 输出结果
|
|
27
|
+
-h, --help 显示帮助信息
|
|
28
|
+
|
|
29
|
+
示例:
|
|
30
|
+
acp-service dsh archive --days 7 --dry-run
|
|
31
|
+
acp-service dsh archive --days 14 --url http://127.0.0.1:51971
|
|
32
|
+
`;
|
|
33
|
+
/** Parse the command line, rejecting values that cannot mean anything. */
|
|
34
|
+
export function parseArchiveArgs(argv) {
|
|
35
|
+
const { values } = parseArgs({
|
|
36
|
+
args: argv,
|
|
37
|
+
strict: true,
|
|
38
|
+
allowPositionals: false,
|
|
39
|
+
options: {
|
|
40
|
+
days: { type: 'string', default: '7' },
|
|
41
|
+
url: { type: 'string', multiple: true, default: [] },
|
|
42
|
+
'dry-run': { type: 'boolean', default: false },
|
|
43
|
+
'include-pinned': { type: 'boolean', default: false },
|
|
44
|
+
'stop-activity': { type: 'boolean', default: false },
|
|
45
|
+
json: { type: 'boolean', default: false },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const days = Number(values.days);
|
|
49
|
+
if (!Number.isFinite(days) || days <= 0)
|
|
50
|
+
throw new Error(`--days must be a positive number of days, got ${String(values.days)}`);
|
|
51
|
+
for (const url of values.url) {
|
|
52
|
+
let parsed;
|
|
53
|
+
try {
|
|
54
|
+
parsed = new URL(url);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new Error(`--url must be an absolute origin, got ${url}`);
|
|
58
|
+
}
|
|
59
|
+
if (!['http:', 'https:'].includes(parsed.protocol))
|
|
60
|
+
throw new Error(`--url must use http or https, got ${url}`);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
days,
|
|
64
|
+
urls: values.url,
|
|
65
|
+
dryRun: values['dry-run'],
|
|
66
|
+
includePinned: values['include-pinned'],
|
|
67
|
+
stopActivity: values['stop-activity'],
|
|
68
|
+
json: values.json,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** The DSH home directory whose storage and credentials the command reads. */
|
|
72
|
+
export function resolveDshHome(env = process.env) {
|
|
73
|
+
return env.DSH_HOME ?? join(homedir(), '.dsh');
|
|
74
|
+
}
|
|
75
|
+
function formatCandidate(candidate) {
|
|
76
|
+
const title = candidate.title ? candidate.title.replace(/\s+/g, ' ').slice(0, 60) : '(无标题)';
|
|
77
|
+
const cwd = candidate.cwd ? ` ${candidate.cwd}` : '';
|
|
78
|
+
return `- ${candidate.sessionId} 静默 ${candidate.idleDays} 天 ${title}${cwd}`;
|
|
79
|
+
}
|
|
80
|
+
function formatSkip(skip) {
|
|
81
|
+
const label = skip.reason === 'pinned' ? '置顶' : skip.reason === 'running' ? '运行中' : '已归档';
|
|
82
|
+
const title = skip.title ? ` ${skip.title.replace(/\s+/g, ' ').slice(0, 60)}` : '';
|
|
83
|
+
return `- ${skip.sessionId} 跳过(${label})${title}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Run the archive command.
|
|
87
|
+
*
|
|
88
|
+
* @param argv - the command's arguments, without the command name.
|
|
89
|
+
* @param env - the environment, for the DSH home directory.
|
|
90
|
+
*/
|
|
91
|
+
export async function runDshArchiveCli(argv, env = process.env) {
|
|
92
|
+
try {
|
|
93
|
+
await archiveCommand(argv, env);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Expected failures (no Host, a stale registry, a bad option) print one
|
|
97
|
+
// line; an unexpected crash keeps its stack for diagnosis.
|
|
98
|
+
if (error instanceof DshRpcError || /^(no reachable|none of the given|cannot read|--days|--url)/.test(String(error instanceof Error ? error.message : error))) {
|
|
99
|
+
console.error(`acp-service dsh archive: ${error instanceof Error ? error.message : String(error)}`);
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function archiveCommand(argv, env) {
|
|
107
|
+
// `acp-service dsh archive` passes the subcommand name through; drop it.
|
|
108
|
+
const args = argv[0] === 'archive' ? argv.slice(1) : argv;
|
|
109
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
110
|
+
console.log(USAGE);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const options = parseArchiveArgs(args);
|
|
114
|
+
const home = resolveDshHome(env);
|
|
115
|
+
const secret = readBrowserSessionSecret(join(home, '.credentials.yaml'));
|
|
116
|
+
// The durable document is read before discovery so an out-of-date Host is
|
|
117
|
+
// not chosen when an up-to-date one is running.
|
|
118
|
+
const document = await readRegistryFile(home);
|
|
119
|
+
const endpoint = await discoverHost(options.urls, secret, document.found ? document.archivedSessionIds : undefined);
|
|
120
|
+
const client = new DshHostClient(endpoint, mintSessionCookie(secret, endpoint.authority));
|
|
121
|
+
const mtimes = await readSessionFileMtimes(join(home, 'sessions'));
|
|
122
|
+
// Plan against the durable document, not the Host's in-memory copy: when two
|
|
123
|
+
// Hosts share one DSH home the older one's copy can be behind. The Host is
|
|
124
|
+
// only asked for the session list here, and its own registry is compared
|
|
125
|
+
// against the document before the first write.
|
|
126
|
+
const hostArchive = (await client.readRegistry()).archivedSessionIds;
|
|
127
|
+
const planSource = {
|
|
128
|
+
listSessions: () => client.listSessions(),
|
|
129
|
+
readRegistry: async () => ({
|
|
130
|
+
archivedSessionIds: document.found ? document.archivedSessionIds : hostArchive,
|
|
131
|
+
pinnedSessionIds: document.found ? document.pinnedSessionIds : (await client.readRegistry()).pinnedSessionIds,
|
|
132
|
+
}),
|
|
133
|
+
archiveSession: (sessionId, archiveOptions) => client.archiveSession(sessionId, archiveOptions),
|
|
134
|
+
};
|
|
135
|
+
const plan = await planArchive(planSource, {
|
|
136
|
+
inactivityMs: Math.round(options.days * DAY_MS),
|
|
137
|
+
now: Date.now(),
|
|
138
|
+
includePinned: options.includePinned,
|
|
139
|
+
fileMtimes: mtimes,
|
|
140
|
+
});
|
|
141
|
+
if (options.dryRun) {
|
|
142
|
+
if (options.json) {
|
|
143
|
+
console.log(JSON.stringify({ dryRun: true, endpoint: endpoint.origin, ...plan }, null, 2));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
console.log(`DSH: ${endpoint.origin}`);
|
|
147
|
+
console.log(`会话总数 ${plan.totalSessions},已归档 ${plan.alreadyArchived},静默超过 ${options.days} 天的待归档 ${plan.candidates.length}`);
|
|
148
|
+
for (const candidate of plan.candidates)
|
|
149
|
+
console.log(formatCandidate(candidate));
|
|
150
|
+
for (const skip of plan.skipped)
|
|
151
|
+
console.log(formatSkip(skip));
|
|
152
|
+
console.log('(预演模式,未做任何改动)');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Refuse to write through a Host that started before the document was last
|
|
156
|
+
// written: its in-memory registry would drop those newer entries.
|
|
157
|
+
if (document.found)
|
|
158
|
+
await client.assertRegistryFresh(document.archivedSessionIds);
|
|
159
|
+
const result = await runArchive(client, plan, { stopActivity: options.stopActivity });
|
|
160
|
+
if (options.json) {
|
|
161
|
+
console.log(JSON.stringify({ dryRun: false, endpoint: endpoint.origin, ...result }, null, 2));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
console.log(`DSH: ${endpoint.origin}`);
|
|
165
|
+
console.log(`会话总数 ${plan.totalSessions},已归档 ${plan.alreadyArchived},候选 ${plan.candidates.length}`);
|
|
166
|
+
console.log(`已归档 ${result.archived.length},失败 ${result.failed.length},跳过 ${result.skipped.length}`);
|
|
167
|
+
for (const failure of result.failed)
|
|
168
|
+
console.error(`- ${failure.sessionId} 归档失败:${failure.error}`);
|
|
169
|
+
for (const skip of result.skipped)
|
|
170
|
+
console.log(formatSkip(skip));
|
|
171
|
+
}
|
package/dist/src/catalog.js
CHANGED
|
@@ -82,11 +82,21 @@ function localLaunch(id, options) {
|
|
|
82
82
|
if (!Array.isArray(argv))
|
|
83
83
|
return undefined;
|
|
84
84
|
if (argv[0] === 'npx') {
|
|
85
|
+
// Adapter argv may carry the package spec in `--package=<spec>` with the
|
|
86
|
+
// bin selector as the first positional (runtime #922 shape), or keep the
|
|
87
|
+
// spec itself positional (legacy shape). Resolve the spec from either
|
|
88
|
+
// shape so local packages keep precedence over PATH shims and npx.
|
|
89
|
+
const packagedFlag = argv.find((arg, i) => i > 0 && arg.startsWith('--package='));
|
|
85
90
|
const index = argv.findIndex((arg, i) => i > 0 && !arg.startsWith('-'));
|
|
86
|
-
|
|
91
|
+
const spec = packagedFlag
|
|
92
|
+
? packagedFlag.slice('--package='.length)
|
|
93
|
+
: index >= 0
|
|
94
|
+
? argv[index]
|
|
95
|
+
: undefined;
|
|
96
|
+
if (!spec)
|
|
87
97
|
return undefined;
|
|
88
|
-
const extraArgs = argv.slice(index + 1);
|
|
89
|
-
const packaged = packageLaunch(
|
|
98
|
+
const extraArgs = index >= 0 ? argv.slice(index + 1) : [];
|
|
99
|
+
const packaged = packageLaunch(spec, extraArgs, options);
|
|
90
100
|
if (packaged)
|
|
91
101
|
return packaged;
|
|
92
102
|
// Use the runtime's adapter entrypoint, rather than the display/native CLI.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manual archiving of silent DSH sessions.
|
|
3
|
+
*
|
|
4
|
+
* DSH owns the durable archive set: archiving a session hides it from the
|
|
5
|
+
* workspace grouping and stops every model step for it and its subagent
|
|
6
|
+
* descendants. This module only decides *which* sessions to hand to that
|
|
7
|
+
* API. It never deletes sessions or their logs, and a pinned session stays a
|
|
8
|
+
* manual decision unless the caller explicitly opts in.
|
|
9
|
+
*
|
|
10
|
+
* The work runs against a live DSH Host over its Typert RPC, because the
|
|
11
|
+
* workspace registry keeps its state in memory: writing the storage file
|
|
12
|
+
* behind a running Host would be overwritten by its next write.
|
|
13
|
+
*/
|
|
14
|
+
/** One day in milliseconds. */
|
|
15
|
+
export declare const DAY_MS: number;
|
|
16
|
+
/** A session as the Host reports it. */
|
|
17
|
+
export interface DshSessionSummary {
|
|
18
|
+
readonly sessionId: string;
|
|
19
|
+
/** Epoch milliseconds of the session's last recorded activity. */
|
|
20
|
+
readonly updatedAt: number;
|
|
21
|
+
readonly cwd?: string;
|
|
22
|
+
readonly running?: boolean;
|
|
23
|
+
readonly blank?: boolean;
|
|
24
|
+
readonly agentAvailable?: boolean;
|
|
25
|
+
readonly parentSessionId?: string;
|
|
26
|
+
readonly origin?: string;
|
|
27
|
+
readonly projections?: {
|
|
28
|
+
readonly values?: {
|
|
29
|
+
readonly title?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The registry sets the CLI reads and writes. */
|
|
34
|
+
export interface ArchiveRegistryState {
|
|
35
|
+
readonly archivedSessionIds: readonly string[];
|
|
36
|
+
readonly pinnedSessionIds: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
/** The live Host calls the archive pass needs. */
|
|
39
|
+
export interface DshArchiveClient {
|
|
40
|
+
/** Every session the Host can see, live or persisted. */
|
|
41
|
+
listSessions(): Promise<readonly DshSessionSummary[]>;
|
|
42
|
+
/** The registry's current archive and pin sets. */
|
|
43
|
+
readRegistry(): Promise<ArchiveRegistryState>;
|
|
44
|
+
/** Ask the Host to archive one session. */
|
|
45
|
+
archiveSession(sessionId: string, options: {
|
|
46
|
+
readonly stopActivity: boolean;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/** How the pass selects its targets. */
|
|
50
|
+
export interface ArchivePlanOptions {
|
|
51
|
+
/** Sessions idle for at least this many milliseconds are candidates. */
|
|
52
|
+
readonly inactivityMs: number;
|
|
53
|
+
/** Current time in epoch milliseconds. */
|
|
54
|
+
readonly now: number;
|
|
55
|
+
/** Archive pinned sessions too. Off by default: a pin is the explicit "keep this visible" signal. */
|
|
56
|
+
readonly includePinned?: boolean;
|
|
57
|
+
/** Stop a session's running work to archive it. Off by default: running sessions are skipped. */
|
|
58
|
+
readonly stopActivity?: boolean;
|
|
59
|
+
/** Durable session file modification times, by session id. */
|
|
60
|
+
readonly fileMtimes?: ReadonlyMap<string, number>;
|
|
61
|
+
}
|
|
62
|
+
/** One session the pass would archive, with the reason it was selected. */
|
|
63
|
+
export interface ArchiveCandidate {
|
|
64
|
+
readonly sessionId: string;
|
|
65
|
+
readonly title: string;
|
|
66
|
+
readonly cwd: string;
|
|
67
|
+
/** Epoch milliseconds of the session's last activity. */
|
|
68
|
+
readonly lastActiveAt: number;
|
|
69
|
+
/** Whole days since that activity, rounded down. */
|
|
70
|
+
readonly idleDays: number;
|
|
71
|
+
/** Whether the session's last activity came from its durable file. */
|
|
72
|
+
readonly fromFile: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** A session the pass deliberately left alone. */
|
|
75
|
+
export interface ArchiveSkip {
|
|
76
|
+
readonly sessionId: string;
|
|
77
|
+
readonly reason: 'pinned' | 'running' | 'already-archived';
|
|
78
|
+
readonly title: string;
|
|
79
|
+
}
|
|
80
|
+
/** The computed plan, before anything is written. */
|
|
81
|
+
export interface ArchivePlan {
|
|
82
|
+
readonly candidates: readonly ArchiveCandidate[];
|
|
83
|
+
readonly skipped: readonly ArchiveSkip[];
|
|
84
|
+
readonly totalSessions: number;
|
|
85
|
+
readonly alreadyArchived: number;
|
|
86
|
+
}
|
|
87
|
+
/** The result of executing a plan. */
|
|
88
|
+
export interface ArchiveRunResult {
|
|
89
|
+
readonly archived: readonly string[];
|
|
90
|
+
readonly failed: readonly {
|
|
91
|
+
readonly sessionId: string;
|
|
92
|
+
readonly error: string;
|
|
93
|
+
}[];
|
|
94
|
+
readonly skipped: readonly ArchiveSkip[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Compute the sessions to archive, without writing anything.
|
|
98
|
+
*
|
|
99
|
+
* Last activity is the later of the Host's own recency (`updatedAt`, the
|
|
100
|
+
* creation time or the last real user message) and the modification time of
|
|
101
|
+
* the session's durable log. That covers both readings of "last activity" —
|
|
102
|
+
* the last message block and the backing file's mtime — and keeps a cold
|
|
103
|
+
* session whose file was touched recently out of the candidate set.
|
|
104
|
+
*
|
|
105
|
+
* @param client - the live Host calls.
|
|
106
|
+
* @param options - threshold, clock and selection policy.
|
|
107
|
+
* @returns the plan and the sessions left alone.
|
|
108
|
+
*/
|
|
109
|
+
export declare function planArchive(client: DshArchiveClient, options: ArchivePlanOptions): Promise<ArchivePlan>;
|
|
110
|
+
/**
|
|
111
|
+
* Archive the planned sessions through the Host, one at a time.
|
|
112
|
+
*
|
|
113
|
+
* Each session is archived on its own so one refusal does not stop the rest.
|
|
114
|
+
* A refusal is reported with its message; the caller decides what to do.
|
|
115
|
+
*
|
|
116
|
+
* @param client - the live Host calls.
|
|
117
|
+
* @param plan - candidates from {@link planArchive}.
|
|
118
|
+
* @param options - whether running work may be stopped.
|
|
119
|
+
* @returns the archived ids and the failures.
|
|
120
|
+
*/
|
|
121
|
+
export declare function runArchive(client: DshArchiveClient, plan: ArchivePlan, options?: {
|
|
122
|
+
readonly stopActivity?: boolean;
|
|
123
|
+
}): Promise<ArchiveRunResult>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manual archiving of silent DSH sessions.
|
|
3
|
+
*
|
|
4
|
+
* DSH owns the durable archive set: archiving a session hides it from the
|
|
5
|
+
* workspace grouping and stops every model step for it and its subagent
|
|
6
|
+
* descendants. This module only decides *which* sessions to hand to that
|
|
7
|
+
* API. It never deletes sessions or their logs, and a pinned session stays a
|
|
8
|
+
* manual decision unless the caller explicitly opts in.
|
|
9
|
+
*
|
|
10
|
+
* The work runs against a live DSH Host over its Typert RPC, because the
|
|
11
|
+
* workspace registry keeps its state in memory: writing the storage file
|
|
12
|
+
* behind a running Host would be overwritten by its next write.
|
|
13
|
+
*/
|
|
14
|
+
/** One day in milliseconds. */
|
|
15
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
16
|
+
/**
|
|
17
|
+
* Compute the sessions to archive, without writing anything.
|
|
18
|
+
*
|
|
19
|
+
* Last activity is the later of the Host's own recency (`updatedAt`, the
|
|
20
|
+
* creation time or the last real user message) and the modification time of
|
|
21
|
+
* the session's durable log. That covers both readings of "last activity" —
|
|
22
|
+
* the last message block and the backing file's mtime — and keeps a cold
|
|
23
|
+
* session whose file was touched recently out of the candidate set.
|
|
24
|
+
*
|
|
25
|
+
* @param client - the live Host calls.
|
|
26
|
+
* @param options - threshold, clock and selection policy.
|
|
27
|
+
* @returns the plan and the sessions left alone.
|
|
28
|
+
*/
|
|
29
|
+
export async function planArchive(client, options) {
|
|
30
|
+
if (!Number.isSafeInteger(options.now) || options.now < 0)
|
|
31
|
+
throw new Error('now must be a non-negative safe integer');
|
|
32
|
+
if (!Number.isSafeInteger(options.inactivityMs) || options.inactivityMs < 1)
|
|
33
|
+
throw new Error('inactivityMs must be a positive integer');
|
|
34
|
+
const [sessions, registry] = await Promise.all([client.listSessions(), client.readRegistry()]);
|
|
35
|
+
const archived = new Set(registry.archivedSessionIds);
|
|
36
|
+
const pinned = new Set(registry.pinnedSessionIds);
|
|
37
|
+
const mtimes = options.fileMtimes ?? new Map();
|
|
38
|
+
const cutoff = options.now - options.inactivityMs;
|
|
39
|
+
const candidates = [];
|
|
40
|
+
const skipped = [];
|
|
41
|
+
for (const session of sessions) {
|
|
42
|
+
if (archived.has(session.sessionId))
|
|
43
|
+
continue;
|
|
44
|
+
const title = session.projections?.values?.title ?? '';
|
|
45
|
+
if (session.running === true) {
|
|
46
|
+
skipped.push({ sessionId: session.sessionId, reason: 'running', title });
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (pinned.has(session.sessionId) && options.includePinned !== true) {
|
|
50
|
+
skipped.push({ sessionId: session.sessionId, reason: 'pinned', title });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const fileMtime = mtimes.get(session.sessionId) ?? 0;
|
|
54
|
+
const fromFile = fileMtime > (session.updatedAt ?? 0);
|
|
55
|
+
const lastActiveAt = Math.max(session.updatedAt ?? 0, fileMtime);
|
|
56
|
+
if (lastActiveAt >= cutoff)
|
|
57
|
+
continue;
|
|
58
|
+
candidates.push({
|
|
59
|
+
sessionId: session.sessionId,
|
|
60
|
+
title,
|
|
61
|
+
cwd: session.cwd ?? '',
|
|
62
|
+
lastActiveAt,
|
|
63
|
+
idleDays: Math.floor((options.now - lastActiveAt) / DAY_MS),
|
|
64
|
+
fromFile,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
candidates.sort((left, right) => left.lastActiveAt - right.lastActiveAt);
|
|
68
|
+
return {
|
|
69
|
+
candidates,
|
|
70
|
+
skipped,
|
|
71
|
+
totalSessions: sessions.length,
|
|
72
|
+
alreadyArchived: sessions.filter(session => archived.has(session.sessionId)).length,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Archive the planned sessions through the Host, one at a time.
|
|
77
|
+
*
|
|
78
|
+
* Each session is archived on its own so one refusal does not stop the rest.
|
|
79
|
+
* A refusal is reported with its message; the caller decides what to do.
|
|
80
|
+
*
|
|
81
|
+
* @param client - the live Host calls.
|
|
82
|
+
* @param plan - candidates from {@link planArchive}.
|
|
83
|
+
* @param options - whether running work may be stopped.
|
|
84
|
+
* @returns the archived ids and the failures.
|
|
85
|
+
*/
|
|
86
|
+
export async function runArchive(client, plan, options = {}) {
|
|
87
|
+
const archived = [];
|
|
88
|
+
const failed = [];
|
|
89
|
+
for (const candidate of plan.candidates) {
|
|
90
|
+
try {
|
|
91
|
+
await client.archiveSession(candidate.sessionId, { stopActivity: options.stopActivity === true });
|
|
92
|
+
archived.push(candidate.sessionId);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
failed.push({ sessionId: candidate.sessionId, error: error instanceof Error ? error.message : String(error) });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { archived, failed, skipped: plan.skipped };
|
|
99
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ArchiveRegistryState, DshArchiveClient, DshSessionSummary } from './dsh-archive.js';
|
|
2
|
+
/** A Host endpoint the CLI can reach. */
|
|
3
|
+
export interface DshEndpoint {
|
|
4
|
+
readonly origin: string;
|
|
5
|
+
readonly authority: string;
|
|
6
|
+
}
|
|
7
|
+
/** An RPC failure reported by the Host. */
|
|
8
|
+
export declare class DshRpcError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
constructor(code: string, message: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Read the browser-session signing secret from the local credential store.
|
|
14
|
+
*
|
|
15
|
+
* The store is a YAML document; this reads the one field it needs rather than
|
|
16
|
+
* taking a YAML dependency, and never returns the secret to the caller.
|
|
17
|
+
*
|
|
18
|
+
* @param credentialsPath - path to the credential document.
|
|
19
|
+
* @returns the signing secret.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readBrowserSessionSecret(credentialsPath: string): Buffer;
|
|
22
|
+
/**
|
|
23
|
+
* Mint the signed browser-session cookie for one authority.
|
|
24
|
+
*
|
|
25
|
+
* @param secret - the signing secret from the credential store.
|
|
26
|
+
* @param authority - the host:port the cookie is scoped to.
|
|
27
|
+
* @returns the cookie header value.
|
|
28
|
+
*/
|
|
29
|
+
export declare function mintSessionCookie(secret: Buffer, authority: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* List the loopback TCP ports this machine is listening on.
|
|
32
|
+
*
|
|
33
|
+
* The desktop app binds an ephemeral port, so the CLI discovers the Host by
|
|
34
|
+
* probing local listeners rather than by a configured address.
|
|
35
|
+
*
|
|
36
|
+
* @returns the loopback ports, ascending.
|
|
37
|
+
*/
|
|
38
|
+
export declare function listLoopbackPorts(): number[];
|
|
39
|
+
/**
|
|
40
|
+
* Ask one origin whether it is a DSH Host that answers the session API.
|
|
41
|
+
*
|
|
42
|
+
* @param origin - the origin to probe.
|
|
43
|
+
* @param cookie - the minted cookie for that origin's authority.
|
|
44
|
+
* @returns whether the origin answered a session list.
|
|
45
|
+
*/
|
|
46
|
+
export declare function probeHost(origin: string, cookie: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Find a reachable DSH Host.
|
|
49
|
+
*
|
|
50
|
+
* An explicit origin is authoritative: the CLI uses the first named origin
|
|
51
|
+
* that answers, so a caller can target one instance on purpose. Without one
|
|
52
|
+
* the CLI probes the machine's loopback listeners, because the desktop app
|
|
53
|
+
* binds an ephemeral port that nothing else records; there it prefers a Host
|
|
54
|
+
* whose registry already holds every archived id, since two Hosts can share
|
|
55
|
+
* one DSH home and the older one's copy would drop the newer archives on its
|
|
56
|
+
* next write.
|
|
57
|
+
*
|
|
58
|
+
* @param origins - explicit origins from the command line.
|
|
59
|
+
* @param secret - the browser-session signing secret.
|
|
60
|
+
* @param documentArchived - archive ids the durable document records, when known.
|
|
61
|
+
* @returns the chosen origin.
|
|
62
|
+
*/
|
|
63
|
+
export declare function discoverHost(origins: readonly string[], secret: Buffer, documentArchived?: readonly string[]): Promise<DshEndpoint>;
|
|
64
|
+
/** A live DSH Host reached over RPC. */
|
|
65
|
+
export declare class DshHostClient implements DshArchiveClient {
|
|
66
|
+
private readonly endpoint;
|
|
67
|
+
private readonly cookie;
|
|
68
|
+
private rpcId;
|
|
69
|
+
/** The archive set this Host most recently reported, for the freshness check. */
|
|
70
|
+
private lastArchivedSessionIds;
|
|
71
|
+
constructor(endpoint: DshEndpoint, cookie: string);
|
|
72
|
+
/**
|
|
73
|
+
* Call one Host method.
|
|
74
|
+
*
|
|
75
|
+
* @param method - the `namespace/method` endpoint.
|
|
76
|
+
* @param args - the method's arguments.
|
|
77
|
+
* @returns the decoded result value.
|
|
78
|
+
*/
|
|
79
|
+
call<T>(method: string, args: Record<string, unknown>): Promise<T>;
|
|
80
|
+
listSessions(): Promise<readonly DshSessionSummary[]>;
|
|
81
|
+
readRegistry(): Promise<ArchiveRegistryState>;
|
|
82
|
+
archiveSession(sessionId: string, options: {
|
|
83
|
+
readonly stopActivity: boolean;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Refuse to write through a Host whose registry is behind the document.
|
|
87
|
+
*
|
|
88
|
+
* The Host holds the registry in memory and rewrites the whole document on
|
|
89
|
+
* every change, so a Host that started before another Host wrote the
|
|
90
|
+
* document would drop the newer archive entries. The command reports this
|
|
91
|
+
* instead of silently undoing someone else's archives.
|
|
92
|
+
*
|
|
93
|
+
* @param documentArchived - the archive set the durable document records.
|
|
94
|
+
* @throws DshRpcError when the Host is behind the document.
|
|
95
|
+
*/
|
|
96
|
+
assertRegistryFresh(documentArchived: readonly string[]): Promise<void>;
|
|
97
|
+
}
|