evolcore 0.0.43-test.6 → 0.0.43-test.7
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/CHANGELOG.md +48 -0
- package/bin/ecmsg.js +171 -54
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +234 -21
- package/dist/cli/agent-create.js +2 -2
- package/dist/cli/daemon-commands.js +6 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/restart-monitor.js +45 -47
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +6 -1
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +104 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +4 -3
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +53 -11
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +198 -84
- package/dist/core/command/menu-protocol.js +60 -11
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +8 -5
- package/dist/core/daemon-lifecycle.js +132 -73
- package/dist/core/handoff/runtime.js +3 -3
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +46 -7
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +147 -17
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/response-engine.js +157 -54
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +43 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/permission/ec-command-parser.js +3 -2
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +2 -3
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +285 -99
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +7 -14
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +15 -3
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +0 -5
- package/kits/templates/system-fragments/thread.md +10 -8
- package/package.json +3 -5
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -16,9 +16,6 @@ Bootstrap 只允许向当前 owner 提问、回显最终值、请求确认或说
|
|
|
16
16
|
{{?chatMode=interactive}}
|
|
17
17
|
interactive:直接输出文本就是回复,由框架自动投递。当前会话的普通文本回复无需调用发送命令;不要先手动发送同一正文,再输出“已发送”等重复说明。
|
|
18
18
|
{{/}}
|
|
19
|
-
{{?chatMode=paactive}}
|
|
20
|
-
paactive:模型自动产生的普通文本由框架转为 activity 展示,不构成正式回复;需要正式回复时使用托管发送命令。工具、文件、图片、审批/提问卡片和 notify 沿用 interactive 行为。
|
|
21
|
-
{{/}}
|
|
22
19
|
{{?chatMode=proactive}}
|
|
23
20
|
proactive:普通输出作为思考过程展示,不作为正式回复、不触发对端的消息接收。要正式回复,必须使用下面的托管发送命令。
|
|
24
21
|
首轮工具调用里要包含一次托管发送命令,说明当前情况和下一步意图。连续多轮没有成功发送时,框架只放行发送命令,其他工具会被拒绝。
|
|
@@ -71,11 +68,9 @@ proactive:普通输出作为思考过程展示,不作为正式回复、不
|
|
|
71
68
|
发送成功后继续本轮必要步骤,不重复发送同一正文或补发“已发送”回执。
|
|
72
69
|
{{?chatMode!=interactive}}
|
|
73
70
|
{{?chatMode!=proactive}}
|
|
74
|
-
{{?chatMode!=paactive}}
|
|
75
71
|
当前 chatMode 缺失或无效;说明运行时上下文不完整,不根据 peerType 或 chatType 猜测回复模式。
|
|
76
72
|
{{/}}
|
|
77
73
|
{{/}}
|
|
78
|
-
{{/}}
|
|
79
74
|
|
|
80
75
|
发送约束:
|
|
81
76
|
- 只能使用当前会话的 delegated sender,经 daemon IPC 发送;保留托管环境,不另建 SDK 连接。不为绕过限制改写身份、对端或 thread 路由。
|
|
@@ -14,29 +14,31 @@
|
|
|
14
14
|
ec agent list
|
|
15
15
|
|
|
16
16
|
# 2. 列出某 agent 有话题记录的所有对端
|
|
17
|
-
ec thread peers
|
|
17
|
+
ec thread peers
|
|
18
18
|
|
|
19
19
|
# 3. 列出与某对端的所有话题(默认10条/页,含消息统计和摘要)
|
|
20
|
-
ec thread list <peer>
|
|
20
|
+
ec thread list <peer>
|
|
21
21
|
|
|
22
|
-
# 4. 翻页(页脚自动给出完整翻页命令,含真实 peer
|
|
23
|
-
ec thread list <peer> --
|
|
22
|
+
# 4. 翻页(页脚自动给出完整翻页命令,含真实 peer)
|
|
23
|
+
ec thread list <peer> --page 2 --limit 10 --sort recent
|
|
24
24
|
|
|
25
25
|
# 5. 查看某话题的历史消息
|
|
26
|
-
ec thread history <peer>/<threadId> --
|
|
26
|
+
ec thread history <peer>/<threadId> --limit 20
|
|
27
27
|
|
|
28
28
|
# 6. 查看话题摘要(写摘要见下文「话题摘要维护」)
|
|
29
|
-
ec thread summary show <peer>/<threadId>
|
|
29
|
+
ec thread summary show <peer>/<threadId>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
> 本端身份由运行时注入,托管会话一律不写 `--self`;`--self` 只用于宿主终端(见下方改名示例)。
|
|
33
|
+
|
|
32
34
|
## 跨话题发送(联系当前对端以外的对象)
|
|
33
35
|
|
|
34
36
|
一个话题只有本端与对端两端。当前话题能直接回复的只有本话题的对端;要联系**其他**对象,必须换到与该对象的话题上发送:
|
|
35
37
|
|
|
36
38
|
```bash
|
|
37
39
|
# 1. 选中目标话题(没有就新建)
|
|
38
|
-
ec thread list <对方AID>
|
|
39
|
-
ec thread create <对方AID> --name '问题跟踪'
|
|
40
|
+
ec thread list <对方AID>
|
|
41
|
+
ec thread create <对方AID> --name '问题跟踪' # 返回 threadId
|
|
40
42
|
|
|
41
43
|
# 2. 带上话题发送;本端/对端由话题推断
|
|
42
44
|
ecmsg send '<text>' --thread <threadId> --check-every 5m
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evolcore",
|
|
3
|
-
"version": "0.0.43-test.
|
|
3
|
+
"version": "0.0.43-test.7",
|
|
4
4
|
"description": "AI Agent gateway connecting Claude, Codex, Gemini, and the bundled ecagent runner to messaging channels with multi-project session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -58,9 +58,6 @@
|
|
|
58
58
|
"test:owner-directory-authorization": "npm run test:owner-directory-cache && npm run test:owner-directory-admission",
|
|
59
59
|
"test:owner-directory-admission": "node --import tsx --test tests/owner-directory-admission.node.ts",
|
|
60
60
|
"test:contact-admission": "node --import tsx --test tests/contact-admission.node.ts",
|
|
61
|
-
"test:ownership-startup": "node --import tsx --test tests/ownership-startup.node.ts tests/ownership-refresh-memory.node.ts",
|
|
62
|
-
"test:initialization-diagnostics": "node --import tsx --test tests/initialization-diagnostics.node.ts",
|
|
63
|
-
"test:hooks": "vitest run tests/unit/codex-hook-diagnostics.test.ts",
|
|
64
61
|
"verify:request-identity": "npm run build && node scripts/verify-request-identity.mjs",
|
|
65
62
|
"prepublishOnly": "npm test"
|
|
66
63
|
},
|
|
@@ -73,7 +70,7 @@
|
|
|
73
70
|
"chokidar": "^5.0.0",
|
|
74
71
|
"cron-parser": "^5.5.0",
|
|
75
72
|
"dotenv": "^17.4.2",
|
|
76
|
-
"ec-web": "0.0.43-test.
|
|
73
|
+
"ec-web": "0.0.43-test.7",
|
|
77
74
|
"ignore": "7.0.5",
|
|
78
75
|
"image-type": "^6.0.0",
|
|
79
76
|
"partial-json": "0.1.7",
|
|
@@ -94,6 +91,7 @@
|
|
|
94
91
|
"pure-qqbot": "^2.0.0"
|
|
95
92
|
},
|
|
96
93
|
"overrides": {
|
|
94
|
+
"@agentunion/fastaun": "$@agentunion/fastaun",
|
|
97
95
|
"qs": "6.16.1",
|
|
98
96
|
"smol-toml": "$smol-toml"
|
|
99
97
|
},
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
|
-
import { authorizeLocalCommand } from './task-context.js';
|
|
5
|
-
import { bindPaWorkspace, paWorkspaceStore, readPaWorkspaceNavigation, updatePaWorkspaceNavigation } from '../core/command/pa-workspace-store.js';
|
|
6
|
-
import { getPackageRoot } from '../paths.js';
|
|
7
|
-
const USAGE = `用法: ec pa-workspace init --workspace <绝对路径> [--force] [--with-triggers]
|
|
8
|
-
ec pa-workspace bind --workspace <已有工作区绝对路径>
|
|
9
|
-
ec pa-workspace navigation show
|
|
10
|
-
ec pa-workspace navigation update --expected-revision <n> --entries-json <json>
|
|
11
|
-
|
|
12
|
-
所有子命令都只输出 JSON,--format json / --json 可省略。
|
|
13
|
-
仅限当前 Agent 的 AUN owner 私聊托管会话。`;
|
|
14
|
-
const MAX_SKILL_OUTPUT_CHARS = 2 * 1024 * 1024;
|
|
15
|
-
export class PaWorkspaceCommandError extends Error {
|
|
16
|
-
code;
|
|
17
|
-
details;
|
|
18
|
-
constructor(code, message, details) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.code = code;
|
|
21
|
-
this.details = details;
|
|
22
|
-
this.name = 'PaWorkspaceCommandError';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function sanitizedInitializationResult(value) {
|
|
26
|
-
const output = {};
|
|
27
|
-
for (const key of ['mode', 'version', 'created', 'errors', 'triggers', 'occupancy']) {
|
|
28
|
-
if (value[key] !== undefined)
|
|
29
|
-
output[key] = value[key];
|
|
30
|
-
}
|
|
31
|
-
return output;
|
|
32
|
-
}
|
|
33
|
-
function runSkillInitialization(args) {
|
|
34
|
-
const packageRoot = getPackageRoot();
|
|
35
|
-
const script = path.join(packageRoot, 'kits', 'skills', 'personal-assistant', 'scripts', 'init.mjs');
|
|
36
|
-
if (!fs.existsSync(script)) {
|
|
37
|
-
return Promise.reject(new PaWorkspaceCommandError('NOT_CONFIGURED', 'EvolCore personal-assistant initialization script is unavailable'));
|
|
38
|
-
}
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
const child = spawn(process.execPath, [script, ...args], {
|
|
41
|
-
cwd: packageRoot,
|
|
42
|
-
windowsHide: true,
|
|
43
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
44
|
-
});
|
|
45
|
-
let stdout = '';
|
|
46
|
-
let stderr = '';
|
|
47
|
-
let outputTooLarge = false;
|
|
48
|
-
const collect = (current, chunk) => {
|
|
49
|
-
if (current.length + chunk.length > MAX_SKILL_OUTPUT_CHARS) {
|
|
50
|
-
outputTooLarge = true;
|
|
51
|
-
child.kill();
|
|
52
|
-
return current;
|
|
53
|
-
}
|
|
54
|
-
return current + chunk;
|
|
55
|
-
};
|
|
56
|
-
child.stdout.setEncoding('utf8').on('data', chunk => { stdout = collect(stdout, String(chunk)); });
|
|
57
|
-
child.stderr.setEncoding('utf8').on('data', chunk => { stderr = collect(stderr, String(chunk)); });
|
|
58
|
-
child.once('error', error => reject(new PaWorkspaceCommandError('SKILL_INIT_FAILED', error.message)));
|
|
59
|
-
child.once('close', code => {
|
|
60
|
-
if (outputTooLarge) {
|
|
61
|
-
reject(new PaWorkspaceCommandError('SKILL_INIT_OUTPUT_TOO_LARGE', 'Personal-assistant initialization output exceeded its limit'));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
resolve({ code, stdout, stderr });
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/** Runs the unmodified Skill initializer and registers its exact workspace only after success. */
|
|
69
|
-
export async function initializePaWorkspace(input) {
|
|
70
|
-
if (!path.isAbsolute(input.workspacePath)) {
|
|
71
|
-
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', '--workspace must be an absolute path');
|
|
72
|
-
}
|
|
73
|
-
const workspacePath = path.resolve(input.workspacePath);
|
|
74
|
-
const args = [
|
|
75
|
-
'--workspace', workspacePath,
|
|
76
|
-
'--owner', input.ownerAid,
|
|
77
|
-
'--json',
|
|
78
|
-
...(input.force ? ['--force'] : []),
|
|
79
|
-
...(input.withTriggers ? ['--with-triggers', '--self', input.paAid] : []),
|
|
80
|
-
];
|
|
81
|
-
const result = await runSkillInitialization(args);
|
|
82
|
-
let initialized;
|
|
83
|
-
try {
|
|
84
|
-
initialized = JSON.parse(result.stdout);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
throw new PaWorkspaceCommandError('SKILL_INIT_FAILED', 'Personal-assistant Skill returned an invalid result', {
|
|
88
|
-
exitCode: result.code,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if ((result.code !== 0 && result.code !== 10) || initialized.ok !== true) {
|
|
92
|
-
throw new PaWorkspaceCommandError(typeof initialized.code === 'string' ? initialized.code : 'SKILL_INIT_FAILED', 'Personal-assistant initialization did not complete; no Core workspace binding was created', { exitCode: result.code, ...sanitizedInitializationResult(initialized) });
|
|
93
|
-
}
|
|
94
|
-
const state = bindPaWorkspace(input.paAid, input.ownerAid, workspacePath);
|
|
95
|
-
return {
|
|
96
|
-
workspaceId: state.workspaceId,
|
|
97
|
-
navigationRevision: state.navigationRevision,
|
|
98
|
-
initialization: sanitizedInitializationResult(initialized),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function value(args, flag) {
|
|
102
|
-
const index = args.indexOf(flag);
|
|
103
|
-
return index >= 0 ? args[index + 1] : undefined;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 摘掉输出格式参数。
|
|
107
|
-
*
|
|
108
|
-
* 本命令**只输出 JSON**,所以 `--format json` 和 `--json` 都不改变行为。
|
|
109
|
-
* 但别的命令(`ec thread`、`ec agent welcome show` …)都接受这两个参数,
|
|
110
|
-
* 调用方很容易顺手写上;直接报 INVALID_ARGUMENT 只会让人以为是用法错误。
|
|
111
|
-
* 这里统一接受,真正的非法值(如 `--format text`)才报错并说清原因。
|
|
112
|
-
*/
|
|
113
|
-
function normalizeFormatArgs(args) {
|
|
114
|
-
const out = [];
|
|
115
|
-
for (let index = 0; index < args.length; index++) {
|
|
116
|
-
const argument = args[index];
|
|
117
|
-
if (argument === '--json')
|
|
118
|
-
continue;
|
|
119
|
-
if (argument === '--format') {
|
|
120
|
-
const format = args[++index];
|
|
121
|
-
if (format !== 'json') {
|
|
122
|
-
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', `ec pa-workspace 只输出 JSON,--format 只能取 json(收到 ${format ?? '空'})`);
|
|
123
|
-
}
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (argument.startsWith('--format=')) {
|
|
127
|
-
const format = argument.slice('--format='.length);
|
|
128
|
-
if (format !== 'json') {
|
|
129
|
-
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', `ec pa-workspace 只输出 JSON,--format 只能取 json(收到 ${format || '空'})`);
|
|
130
|
-
}
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
out.push(argument);
|
|
134
|
-
}
|
|
135
|
-
return out;
|
|
136
|
-
}
|
|
137
|
-
function assertOwnerPrivateRuntime(context) {
|
|
138
|
-
if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner'
|
|
139
|
-
|| !context.selfAid || !context.peerId) {
|
|
140
|
-
throw Object.assign(new Error('PA workspace changes require the current Agent owner in an AUN private chat'), { code: 'NOT_ALLOWED' });
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function output(value) {
|
|
144
|
-
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
145
|
-
}
|
|
146
|
-
export async function cmdPaWorkspace(rawArgs) {
|
|
147
|
-
if (rawArgs.length === 0 || rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
148
|
-
console.log(USAGE);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
const args = normalizeFormatArgs(rawArgs);
|
|
153
|
-
const context = await authorizeLocalCommand(['pa-workspace', ...args]);
|
|
154
|
-
assertOwnerPrivateRuntime(context);
|
|
155
|
-
if (args[0] === 'init') {
|
|
156
|
-
let workspacePath;
|
|
157
|
-
let force = false;
|
|
158
|
-
let withTriggers = false;
|
|
159
|
-
for (let index = 1; index < args.length; index++) {
|
|
160
|
-
const argument = args[index];
|
|
161
|
-
if (argument === '--workspace')
|
|
162
|
-
workspacePath = args[++index];
|
|
163
|
-
else if (argument === '--force')
|
|
164
|
-
force = true;
|
|
165
|
-
else if (argument === '--with-triggers')
|
|
166
|
-
withTriggers = true;
|
|
167
|
-
else
|
|
168
|
-
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
169
|
-
}
|
|
170
|
-
if (!workspacePath)
|
|
171
|
-
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
172
|
-
output({ ok: true, ...await initializePaWorkspace({
|
|
173
|
-
paAid: context.selfAid,
|
|
174
|
-
ownerAid: context.peerId,
|
|
175
|
-
workspacePath,
|
|
176
|
-
force,
|
|
177
|
-
withTriggers,
|
|
178
|
-
}) });
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (args[0] === 'bind') {
|
|
182
|
-
if (args.length !== 3 || args[1] !== '--workspace' || !args[2])
|
|
183
|
-
throw Object.assign(new Error(USAGE), { code: 'INVALID_ARGUMENT' });
|
|
184
|
-
const state = bindPaWorkspace(context.selfAid, context.peerId, args[2]);
|
|
185
|
-
output({ ok: true, workspaceId: state.workspaceId, navigationRevision: state.navigationRevision });
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (args[0] === 'navigation' && args[1] === 'show' && args.length === 2) {
|
|
189
|
-
output({ ok: true, ...readPaWorkspaceNavigation(context.selfAid) });
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (args[0] === 'navigation' && args[1] === 'update') {
|
|
193
|
-
const expected = value(args, '--expected-revision');
|
|
194
|
-
const entriesJson = value(args, '--entries-json');
|
|
195
|
-
if (!expected || !entriesJson || args.length !== 6 || !/^\d+$/.test(expected))
|
|
196
|
-
throw Object.assign(new Error(USAGE), { code: 'INVALID_ARGUMENT' });
|
|
197
|
-
let entries;
|
|
198
|
-
try {
|
|
199
|
-
entries = JSON.parse(entriesJson);
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
throw Object.assign(new Error('--entries-json must contain valid JSON'), { code: 'INVALID_ARGUMENT' });
|
|
203
|
-
}
|
|
204
|
-
output({ ok: true, ...updatePaWorkspaceNavigation(context.selfAid, Number(expected), entries) });
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (args[0] === 'navigation' && args[1] === 'status' && args.length === 2) {
|
|
208
|
-
const state = paWorkspaceStore.require(context.selfAid);
|
|
209
|
-
output({ ok: true, workspaceId: state.workspaceId, navigationRevision: state.navigationRevision, entries: state.entries });
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
throw Object.assign(new Error(USAGE), { code: 'INVALID_ARGUMENT' });
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
const source = error;
|
|
216
|
-
const result = {
|
|
217
|
-
ok: false,
|
|
218
|
-
code: source.code ?? 'PA_WORKSPACE_FAILED',
|
|
219
|
-
error: error instanceof Error ? error.message : String(error),
|
|
220
|
-
...(error instanceof PaWorkspaceCommandError && error.details ? { details: error.details } : {}),
|
|
221
|
-
};
|
|
222
|
-
process.stderr.write(`${JSON.stringify(result)}\n`);
|
|
223
|
-
process.exitCode = 1;
|
|
224
|
-
}
|
|
225
|
-
}
|