evolcore 0.0.43-test.5 → 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 +95 -0
- package/bin/ecmsg.js +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- 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 +58 -16
- 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 +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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 +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- 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 +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- 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 +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- 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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -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 +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- 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 +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- 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-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- 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/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
|
@@ -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
|
-
}
|