evolcore 0.0.43-test.1 → 0.0.43-test.3
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 +31 -1
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +39 -15
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/aid/agentmd.js +21 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +7 -2
- package/dist/channels/aun.js +522 -50
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/daemon.js +4 -0
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +20 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +18 -19
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +149 -91
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +3 -2
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/builtin-role-templates.js +2 -2
- package/dist/config/builtin-roles.js +2 -1
- package/dist/config/config-field-policy.js +7 -2
- package/dist/config/config-manager.js +32 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +29 -4
- package/dist/config/role-service.js +12 -7
- package/dist/config/role-store.js +30 -8
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +17 -11
- package/dist/core/auth/operation-catalog.js +5 -13
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +47 -40
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +16 -2
- package/dist/core/command/menu-handler.js +107 -14
- package/dist/core/command/menu-protocol.js +28 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +139 -51
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/daemon-lifecycle.js +9 -1
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +10 -12
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +35 -2
- package/dist/core/message/contact-admission.js +530 -0
- package/dist/core/message/im-renderer.js +111 -16
- package/dist/core/message/message-admission.js +29 -54
- package/dist/core/message/message-bridge.js +62 -8
- package/dist/core/message/message-utils.js +9 -5
- package/dist/core/message/peer-mode.js +55 -13
- package/dist/core/message/response-engine.js +298 -78
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/ownership/owner-resolver.js +72 -34
- package/dist/core/permission/ec-command-parser.js +25 -38
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/relation/pa-team.js +127 -0
- package/dist/core/role/runtime-policy.js +18 -5
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +125 -29
- package/dist/directory/owner-directory-cache.js +554 -58
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +154 -58
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +399 -90
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-request-operation.js +76 -0
- package/dist/directory/owner-directory-scope.js +35 -4
- package/dist/directory/owner-directory-search.js +118 -33
- package/dist/directory/owner-directory-store.js +117 -30
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +18 -8
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +28 -16
- package/dist/index.js +20 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +29 -1
- package/dist/product.js +1 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +2 -1
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +7 -4
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +12 -7
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/README.md +18 -0
- package/ecagent/dist/agent-loop.js +43 -1
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/compaction.js +3 -0
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +4 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +227 -0
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +265 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +64 -7
- package/kits/eck_manifest.memory.json +93 -4
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +44 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/agent-config.schema.20.json +925 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/schemas/role-config.schema.3.json +1038 -0
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +39 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/personal-assistant.md +50 -0
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +3 -2
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* 2. 写 README / INDEX(已有 README 不覆盖,改名保留)
|
|
13
13
|
* 3. 写 .assistant/state.json
|
|
14
14
|
* 4. 可选:安装触发器
|
|
15
|
-
* 5.
|
|
15
|
+
* 5. 写 soul「工作方式」分册的工作区入口(备份 → 重建)
|
|
16
|
+
* 6. 绑定 Core 的 PA 工作区(App 入口靠它,不做就等于没装完)
|
|
17
|
+
* 7. 输出验收清单
|
|
16
18
|
*
|
|
17
19
|
* 退出码:
|
|
18
20
|
* 0 成功(含"已是最新,无需改动"——没活干也是成功)
|
|
@@ -28,6 +30,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
28
30
|
import { join, resolve } from 'node:path';
|
|
29
31
|
import { SKILL_DIR, latestVersion, loadSchema, readWorkspaceVersion } from './lib/schema.mjs';
|
|
30
32
|
import { ensureStructure, readState, writeState } from './lib/apply.mjs';
|
|
33
|
+
import { applyPersona, formatTriggers } from './lib/persona.mjs';
|
|
31
34
|
|
|
32
35
|
// ── 参数 ────────────────────────────────────────────────────────
|
|
33
36
|
function parseArgs(argv) {
|
|
@@ -228,7 +231,7 @@ if (args.withTriggers && !args.dryRun) {
|
|
|
228
231
|
|
|
229
232
|
// ── 4. state.json ──────────────────────────────────────────────
|
|
230
233
|
// 必须放在触发器之后:triggers 清单来自上一步的实际结果,
|
|
231
|
-
// 否则
|
|
234
|
+
// 否则 soul 分册和后续会话会以为没装过,重复创建。
|
|
232
235
|
const installedTriggers = triggerReport
|
|
233
236
|
? [...triggerReport.ok, ...triggerReport.skipped]
|
|
234
237
|
: (existingState?.triggers || []);
|
|
@@ -244,6 +247,25 @@ if (!args.dryRun) {
|
|
|
244
247
|
});
|
|
245
248
|
}
|
|
246
249
|
|
|
250
|
+
// ── 4.5 soul「工作方式」分册(先备份,再重建) ────────────────────
|
|
251
|
+
// 工作区路径只存在 .assistant/ 和 Core 导航状态里,两者都不进上下文;
|
|
252
|
+
// soul 分册是唯一保证每轮注入的位置。这一步不做,新会话发现不了工作区。
|
|
253
|
+
let personaReport = null;
|
|
254
|
+
{
|
|
255
|
+
const selfAid = args.self || process.env.EVOLCORE_SELF_AID || '';
|
|
256
|
+
if (!selfAid) {
|
|
257
|
+
personaReport = { ok: false, action: 'skipped', reason: '缺少 --self <AID>,无法定位 soul「工作方式」分册' };
|
|
258
|
+
} else {
|
|
259
|
+
personaReport = applyPersona({
|
|
260
|
+
selfAid,
|
|
261
|
+
workspace,
|
|
262
|
+
owner: args.owner || existingState?.owner || '',
|
|
263
|
+
triggers: formatTriggers(installedTriggers),
|
|
264
|
+
dryRun: args.dryRun,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
247
269
|
/** 触发器定义文件名 → 实际 trigger ID(定义里的 id 是 pa-<name>) */
|
|
248
270
|
function triggerIdOf(name) {
|
|
249
271
|
return `pa-${name}`;
|
|
@@ -306,6 +328,7 @@ if (args.json) {
|
|
|
306
328
|
errors: result.errors,
|
|
307
329
|
readmeBackup,
|
|
308
330
|
triggers: triggerReport,
|
|
331
|
+
persona: personaReport,
|
|
309
332
|
occupancy: { state: occ.state, foreign: occ.foreign.length },
|
|
310
333
|
}, null, 2));
|
|
311
334
|
process.exit(exitCode);
|
|
@@ -351,6 +374,22 @@ if (triggerReport) {
|
|
|
351
374
|
console.log('');
|
|
352
375
|
}
|
|
353
376
|
|
|
377
|
+
if (personaReport) {
|
|
378
|
+
if (personaReport.ok) {
|
|
379
|
+
const word = personaReport.action === 'created' ? '创建' : '更新';
|
|
380
|
+
console.log(`soul 工作方式:${args.dryRun ? '将' : '已'}${word}(工作区入口${args.dryRun ? '将' : '已'}写入)`);
|
|
381
|
+
if (personaReport.backupCreated) {
|
|
382
|
+
console.log(` · 原文件已备份:${personaReport.backupPath.split(/[\\/]/).pop()}`);
|
|
383
|
+
} else if (personaReport.backupPath) {
|
|
384
|
+
console.log(` · 已有备份保留未动:${personaReport.backupPath.split(/[\\/]/).pop()}`);
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
console.log(`soul 工作方式:⚠️ 跳过 —— ${personaReport.reason}`);
|
|
388
|
+
console.log(' · 新会话将无法发现这个工作区,补上 --self 后重跑');
|
|
389
|
+
}
|
|
390
|
+
console.log('');
|
|
391
|
+
}
|
|
392
|
+
|
|
354
393
|
if (exitCode !== 0) console.log('⚠️ 部分完成,见上面失败项');
|
|
355
394
|
else if (noop) console.log('✅ 已是最新,无需改动');
|
|
356
395
|
else console.log('✅ 完成');
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* persona.mjs —— 把工作区入口写进 agent 的 soul「工作方式」分册
|
|
3
|
+
* (`$AGENT_DIR/personal/soul/04-working-style.md`)
|
|
4
|
+
*
|
|
5
|
+
* 设计原则:
|
|
6
|
+
* - 调用方只传 workspace / selfAid / owner,本模块负责其余全部细节
|
|
7
|
+
* - 先备份,再重建;旧内容原样保留在新文件里
|
|
8
|
+
* - 用标记块包围本技能写入的部分,重复执行只替换块内,不产生重复段落
|
|
9
|
+
* - 清理时优先恢复备份;没有备份就只摘掉标记块
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, renameSync, unlinkSync,
|
|
13
|
+
} from 'node:fs';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { join, dirname } from 'node:path';
|
|
16
|
+
import { SKILL_DIR } from './schema.mjs';
|
|
17
|
+
|
|
18
|
+
export const BACKUP_NAME = '04-working-style.before-personal-assistant.md';
|
|
19
|
+
export const MARK_BEGIN = '<!-- personal-assistant:begin -->';
|
|
20
|
+
export const MARK_END = '<!-- personal-assistant:end -->';
|
|
21
|
+
|
|
22
|
+
/** 解析 EVOLCORE_HOME:环境变量 → ~/.evolcore */
|
|
23
|
+
export function evolcoreHome() {
|
|
24
|
+
const fromEnv = process.env.EVOLCORE_HOME;
|
|
25
|
+
return fromEnv ? fromEnv : join(homedir(), '.evolcore');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** agent 的 soul「工作方式」分册绝对路径(每轮注入 system prompt 的稳定位置) */
|
|
29
|
+
export function personaPath(selfAid) {
|
|
30
|
+
return join(evolcoreHome(), 'agents', selfAid, 'personal', 'soul', '04-working-style.md');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 渲染 persona 段落模板 */
|
|
34
|
+
export function renderSection({ workspace, owner, skillDir, triggers }) {
|
|
35
|
+
const tplPath = join(SKILL_DIR, 'templates', 'persona-section.md');
|
|
36
|
+
const tpl = readFileSync(tplPath, 'utf8')
|
|
37
|
+
.replaceAll('{{workspace}}', workspace)
|
|
38
|
+
.replaceAll('{{owner}}', owner || '主人')
|
|
39
|
+
.replaceAll('{{skillDir}}', skillDir || SKILL_DIR)
|
|
40
|
+
.replaceAll('{{triggers}}', triggers);
|
|
41
|
+
// 模板头部的用法注释不进入正文
|
|
42
|
+
return tpl.replace(/^<!--[\s\S]*?-->\s*/, '').trim();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 摘掉旧的标记块,返回块外内容 */
|
|
46
|
+
export function stripBlock(text) {
|
|
47
|
+
const start = text.indexOf(MARK_BEGIN);
|
|
48
|
+
if (start === -1) return text;
|
|
49
|
+
const end = text.indexOf(MARK_END, start);
|
|
50
|
+
if (end === -1) return text;
|
|
51
|
+
return (text.slice(0, start) + text.slice(end + MARK_END.length)).replace(/\n{3,}/g, '\n\n');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 从「工作方式」分册的标记块里取出当初写入的工作区路径(取不到返回 null) */
|
|
55
|
+
export function parseWorkspaceFromPersona(text) {
|
|
56
|
+
const start = text.indexOf(MARK_BEGIN);
|
|
57
|
+
if (start === -1) return null;
|
|
58
|
+
const end = text.indexOf(MARK_END, start);
|
|
59
|
+
const block = text.slice(start, end === -1 ? undefined : end);
|
|
60
|
+
const m = /个人助理工作区[::]\s*`([^`]+)`/.exec(block);
|
|
61
|
+
return m ? m[1].trim() : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 路径比较用的归一化:统一分隔符、去尾斜杠、Windows 忽略大小写 */
|
|
65
|
+
export function normalizePath(p) {
|
|
66
|
+
let s = String(p || '').replace(/\\/g, '/').replace(/\/+$/, '');
|
|
67
|
+
if (process.platform === 'win32') s = s.toLowerCase();
|
|
68
|
+
return s;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 写入「工作方式」分册:备份 → 重建
|
|
73
|
+
* @returns {{ok:boolean, action:string, path:string, backupPath:string|null, error?:string}}
|
|
74
|
+
*/
|
|
75
|
+
export function applyPersona({ selfAid, workspace, owner, triggers, dryRun = false }) {
|
|
76
|
+
if (!selfAid) {
|
|
77
|
+
return { ok: false, action: 'skipped', path: '', backupPath: null, error: '缺少 selfAid' };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const path = personaPath(selfAid);
|
|
81
|
+
const backupPath = join(dirname(path), BACKUP_NAME);
|
|
82
|
+
const section = `${MARK_BEGIN}\n${renderSection({ workspace, owner, triggers })}\n${MARK_END}`;
|
|
83
|
+
|
|
84
|
+
let old = '';
|
|
85
|
+
const existed = existsSync(path);
|
|
86
|
+
if (existed) {
|
|
87
|
+
try {
|
|
88
|
+
old = readFileSync(path, 'utf8');
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return { ok: false, action: 'failed', path, backupPath: null, error: `读取失败:${e.message}` };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const base = stripBlock(old).trimEnd();
|
|
95
|
+
const next = base ? `${base}\n\n${section}\n` : `${section}\n`;
|
|
96
|
+
|
|
97
|
+
// 备份:已存在不覆盖——最早那份才是真正的原始状态
|
|
98
|
+
const needBackup = existed && !existsSync(backupPath);
|
|
99
|
+
|
|
100
|
+
if (!dryRun) {
|
|
101
|
+
try {
|
|
102
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
103
|
+
if (needBackup) copyFileSync(path, backupPath);
|
|
104
|
+
writeFileSync(path, next, 'utf8');
|
|
105
|
+
} catch (e) {
|
|
106
|
+
return { ok: false, action: 'failed', path, backupPath: null, error: `写入失败:${e.message}` };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
ok: true,
|
|
112
|
+
action: existed ? 'updated' : 'created',
|
|
113
|
+
path,
|
|
114
|
+
backupPath: needBackup || existsSync(backupPath) ? backupPath : null,
|
|
115
|
+
backupCreated: needBackup,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 清理:优先恢复备份,没有备份就只摘掉标记块
|
|
121
|
+
*
|
|
122
|
+
* workspace 必传:用来校验"要清理的入口,确实是这个工作区写进去的"。
|
|
123
|
+
* 校验不过就拒绝,避免 A 工作区的清理命令把 B 工作区的入口摘掉。
|
|
124
|
+
*
|
|
125
|
+
* @returns {{ok:boolean, action:string, path:string, workspace?:string, recorded?:string, error?:string}}
|
|
126
|
+
*/
|
|
127
|
+
export function restorePersona({ selfAid, workspace, dryRun = false }) {
|
|
128
|
+
if (!selfAid) return { ok: false, action: 'skipped', path: '', error: '缺少 selfAid' };
|
|
129
|
+
if (!workspace) return { ok: false, action: 'need-workspace', path: '', error: '缺少 workspace,无法确认要清理哪个工作区' };
|
|
130
|
+
|
|
131
|
+
const path = personaPath(selfAid);
|
|
132
|
+
const backupPath = join(dirname(path), BACKUP_NAME);
|
|
133
|
+
|
|
134
|
+
let old = null;
|
|
135
|
+
if (existsSync(path)) {
|
|
136
|
+
try {
|
|
137
|
+
old = readFileSync(path, 'utf8');
|
|
138
|
+
} catch (e) {
|
|
139
|
+
return { ok: false, action: 'failed', path, error: `读取失败:${e.message}` };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 校验:persona 里记录的路径必须和传入的一致
|
|
144
|
+
const recorded = old ? parseWorkspaceFromPersona(old) : null;
|
|
145
|
+
if (recorded && normalizePath(recorded) !== normalizePath(workspace)) {
|
|
146
|
+
return {
|
|
147
|
+
ok: false,
|
|
148
|
+
action: 'mismatch',
|
|
149
|
+
path,
|
|
150
|
+
workspace,
|
|
151
|
+
recorded,
|
|
152
|
+
error: `persona 里登记的是另一个工作区:${recorded}`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (existsSync(backupPath)) {
|
|
157
|
+
if (!dryRun) {
|
|
158
|
+
try {
|
|
159
|
+
renameSync(backupPath, path);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
return { ok: false, action: 'failed', path, error: `恢复失败:${e.message}` };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { ok: true, action: 'restored-from-backup', path, workspace };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!old) return { ok: true, action: 'noop', path, workspace };
|
|
168
|
+
|
|
169
|
+
const base = stripBlock(old).trimEnd();
|
|
170
|
+
if (!dryRun) {
|
|
171
|
+
try {
|
|
172
|
+
if (base) writeFileSync(path, `${base}\n`, 'utf8');
|
|
173
|
+
else unlinkSync(path);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
return { ok: false, action: 'failed', path, error: `清理失败:${e.message}` };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { ok: true, action: base ? 'block-removed' : 'deleted', path, workspace };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** 把 state.json 里的触发器清单渲染成给人看的一行 */
|
|
182
|
+
export function formatTriggers(triggers) {
|
|
183
|
+
if (!triggers || !triggers.length) return '(尚未安装)';
|
|
184
|
+
return triggers.map(t => `\`${t}\``).join('、');
|
|
185
|
+
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* migrate.mjs —— 把工作区结构修正到当前 schema 版本(幂等、只做加法)
|
|
4
4
|
*
|
|
5
5
|
* 用法:
|
|
6
|
-
* node "<技能目录>/scripts/migrate.mjs" --workspace "<路径>" [--
|
|
6
|
+
* node "<技能目录>/scripts/migrate.mjs" --workspace "<路径>" [--self <AID>]
|
|
7
|
+
* [--owner <AID>] [--dry-run] [--json]
|
|
7
8
|
*
|
|
8
9
|
* 硬规则:
|
|
9
10
|
* 1. 只做加法:建目录、补生成物。永不删用户数据。
|
|
@@ -21,12 +22,15 @@ import {
|
|
|
21
22
|
SKILL_DIR, loadSchema, listVersions, latestVersion,
|
|
22
23
|
readWorkspaceVersion, readCapabilities, diff,
|
|
23
24
|
} from './lib/schema.mjs';
|
|
25
|
+
import { applyPersona, formatTriggers } from './lib/persona.mjs';
|
|
24
26
|
|
|
25
27
|
function parseArgs(argv) {
|
|
26
28
|
const out = { json: false, dryRun: false };
|
|
27
29
|
for (let i = 2; i < argv.length; i++) {
|
|
28
30
|
const a = argv[i];
|
|
29
31
|
if (a === '--workspace' || a === '-w') out.workspace = argv[++i];
|
|
32
|
+
else if (a === '--self') out.self = argv[++i];
|
|
33
|
+
else if (a === '--owner') out.owner = argv[++i];
|
|
30
34
|
else if (a === '--json') out.json = true;
|
|
31
35
|
else if (a === '--dry-run') out.dryRun = true;
|
|
32
36
|
else if (a === '--help' || a === '-h') out.help = true;
|
|
@@ -36,9 +40,10 @@ function parseArgs(argv) {
|
|
|
36
40
|
|
|
37
41
|
const args = parseArgs(process.argv);
|
|
38
42
|
if (args.help || !args.workspace) {
|
|
39
|
-
console.log(`用法:node migrate.mjs --workspace <路径> [--dry-run] [--json]
|
|
43
|
+
console.log(`用法:node migrate.mjs --workspace <路径> [--self <AID>] [--owner <AID>] [--dry-run] [--json]
|
|
40
44
|
|
|
41
|
-
把工作区修正到当前 schema
|
|
45
|
+
把工作区修正到当前 schema 版本。幂等、只做加法、不删数据。
|
|
46
|
+
传 --self 时同时刷新 soul「工作方式」分册里的工作区入口(备份 → 重建 → 替换标记块)。`);
|
|
42
47
|
process.exit(args.help ? 0 : 30);
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -82,15 +87,38 @@ const report = {
|
|
|
82
87
|
// 快照是"改动前"的可回滚依据;没有改动就不该留快照,否则每次空跑都堆一份垃圾。
|
|
83
88
|
const versions = listVersions().filter(v => v > from);
|
|
84
89
|
if (!versions.length && from >= target) {
|
|
90
|
+
// 结构不用动,但给了 --self 仍然刷新 soul 工作方式入口(技能升级可能改了模板/触发器清单)
|
|
91
|
+
const persona = args.self ? refreshPersona() : null;
|
|
85
92
|
if (args.json) {
|
|
86
|
-
console.log(JSON.stringify({ ...report, ok: true, noop: true }, null, 2));
|
|
93
|
+
console.log(JSON.stringify({ ...report, ok: true, noop: true, persona }, null, 2));
|
|
87
94
|
} else {
|
|
88
95
|
console.log(`✅ 已是 v${target},无需迁移`);
|
|
96
|
+
if (persona) console.log(persona.ok
|
|
97
|
+
? `soul 工作方式:${args.dryRun ? '将被更新' : '已更新'}(工作区入口已刷新)`
|
|
98
|
+
: `soul 工作方式:⚠️ 跳过 —— ${persona.reason || persona.error}`);
|
|
89
99
|
}
|
|
90
100
|
// 无需迁移是成功,不是失败——非 0 会让 && 链和 CI 误判
|
|
91
101
|
process.exit(0);
|
|
92
102
|
}
|
|
93
103
|
|
|
104
|
+
/** 用当前 state.json 的触发器清单刷新 soul 工作方式入口 */
|
|
105
|
+
function refreshPersona() {
|
|
106
|
+
try {
|
|
107
|
+
const statePath = join(workspace, '.assistant', 'state.json');
|
|
108
|
+
let state = {};
|
|
109
|
+
if (existsSync(statePath)) state = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
110
|
+
return applyPersona({
|
|
111
|
+
selfAid: args.self,
|
|
112
|
+
workspace,
|
|
113
|
+
owner: args.owner || state.owner || '',
|
|
114
|
+
triggers: formatTriggers(state.triggers || []),
|
|
115
|
+
dryRun: args.dryRun,
|
|
116
|
+
});
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return { ok: false, action: 'failed', error: e.message };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
94
122
|
// ── 快照(可回滚依据) ──────────────────────────────────────────
|
|
95
123
|
if (!args.dryRun && from > 0) {
|
|
96
124
|
const logDir = join(workspace, '.assistant', 'logs');
|
|
@@ -171,6 +199,24 @@ if (!args.dryRun && !report.errors.length) {
|
|
|
171
199
|
}
|
|
172
200
|
}
|
|
173
201
|
|
|
202
|
+
// ── soul 工作方式入口(技能升级可能改了模板或触发器清单) ────────────
|
|
203
|
+
if (args.self) {
|
|
204
|
+
try {
|
|
205
|
+
const statePath = join(workspace, '.assistant', 'state.json');
|
|
206
|
+
let state = {};
|
|
207
|
+
if (existsSync(statePath)) state = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
208
|
+
report.persona = applyPersona({
|
|
209
|
+
selfAid: args.self,
|
|
210
|
+
workspace,
|
|
211
|
+
owner: args.owner || state.owner || '',
|
|
212
|
+
triggers: formatTriggers(state.triggers || []),
|
|
213
|
+
dryRun: args.dryRun,
|
|
214
|
+
});
|
|
215
|
+
} catch (e) {
|
|
216
|
+
report.persona = { ok: false, action: 'failed', error: e.message };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
174
220
|
report.ok = report.errors.length === 0;
|
|
175
221
|
const exitCode = report.errors.length ? 20 : 0;
|
|
176
222
|
|
|
@@ -193,5 +239,10 @@ if (report.errors.length) {
|
|
|
193
239
|
} else if (!args.dryRun) {
|
|
194
240
|
console.log(`\n✅ 完成,工作区现在是 v${target}`);
|
|
195
241
|
}
|
|
242
|
+
if (report.persona) {
|
|
243
|
+
console.log(report.persona.ok
|
|
244
|
+
? `soul 工作方式:${args.dryRun ? '将被更新' : '已更新'}(工作区入口已刷新)`
|
|
245
|
+
: `soul 工作方式:⚠️ 跳过 —— ${report.persona.reason || report.persona.error}`);
|
|
246
|
+
}
|
|
196
247
|
|
|
197
248
|
process.exit(exitCode);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* pa.mjs —— 个人助理的唯一入口(三种操作)
|
|
4
|
+
*
|
|
5
|
+
* 契约:
|
|
6
|
+
* 调用方(程序或 Agent)只负责传「工作区路径 + AID」,其余全部由脚本完成。
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* node pa.mjs init --workspace <路径> --self <AID> [--owner <AID>] [--force] [--with-triggers]
|
|
10
|
+
* node pa.mjs clean --workspace <路径> --self <AID> [--yes]
|
|
11
|
+
* node pa.mjs uninstall --workspace <路径> --self <AID> [--remove-triggers]
|
|
12
|
+
* node pa.mjs update --workspace <路径> --self <AID> [--owner <AID>]
|
|
13
|
+
*
|
|
14
|
+
* 四种操作都支持 --dry-run / --json,参数原样透传给对应实现脚本。
|
|
15
|
+
*
|
|
16
|
+
* clean 与 uninstall 的区别:
|
|
17
|
+
* clean —— 删工作区目录 + 触发器 + persona 入口 + Core 登记,不可逆
|
|
18
|
+
* uninstall —— 只恢复 persona、删触发器,工作区档案全部保留
|
|
19
|
+
*
|
|
20
|
+
* 退出码沿用子脚本:0 成功 / 20 部分失败 / 30 前置条件不满足 / 40 目录被占用
|
|
21
|
+
*/
|
|
22
|
+
import { spawnSync, execFileSync } from 'node:child_process';
|
|
23
|
+
import { existsSync, readFileSync, unlinkSync } from 'node:fs';
|
|
24
|
+
import { homedir } from 'node:os';
|
|
25
|
+
import { dirname, join, resolve } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
|
|
30
|
+
const OPS = {
|
|
31
|
+
init: {
|
|
32
|
+
script: 'init.mjs',
|
|
33
|
+
desc: '初始化工作区:建目录、装触发器、写 state.json 和 persona 入口',
|
|
34
|
+
requirement: '全新环境,或在已有工作区上做幂等修复',
|
|
35
|
+
},
|
|
36
|
+
clean: {
|
|
37
|
+
script: 'clean.mjs',
|
|
38
|
+
desc: '彻底清理:删工作区目录 + 触发器 + persona 入口 + Core 登记',
|
|
39
|
+
requirement: '不可逆,默认只预览;要清空重来时加 --yes',
|
|
40
|
+
},
|
|
41
|
+
uninstall: {
|
|
42
|
+
script: 'uninstall.mjs',
|
|
43
|
+
desc: '撤销初始化:恢复 persona、删 pa-* 触发器,工作区档案全部保留',
|
|
44
|
+
requirement: '要拆掉自动化但保住档案时用这个,别用 clean',
|
|
45
|
+
},
|
|
46
|
+
update: {
|
|
47
|
+
script: 'migrate.mjs',
|
|
48
|
+
desc: '更新:把结构升到当前 schema 版本,并按新模板刷新 persona 入口',
|
|
49
|
+
requirement: '技能升级后,或想重刷 persona 里的工作区入口',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const [op, ...rest] = process.argv.slice(2);
|
|
54
|
+
|
|
55
|
+
if (!op || op === '--help' || op === '-h' || !OPS[op]) {
|
|
56
|
+
console.log(`个人助理入口 —— 四种操作
|
|
57
|
+
|
|
58
|
+
node pa.mjs init --workspace <路径> --self <AID> [--owner <AID>] [--force] [--with-triggers]
|
|
59
|
+
node pa.mjs clean --workspace <路径> --self <AID> [--yes]
|
|
60
|
+
node pa.mjs uninstall --workspace <路径> --self <AID> [--remove-triggers]
|
|
61
|
+
node pa.mjs update --workspace <路径> --self <AID> [--owner <AID>]
|
|
62
|
+
|
|
63
|
+
通用选项(透传给实现脚本):
|
|
64
|
+
--dry-run 只报告会做什么,不落盘
|
|
65
|
+
--json 机器可读输出
|
|
66
|
+
|
|
67
|
+
⚠️ clean 会删掉整个工作区目录;只想撤装、保住档案请用 uninstall。
|
|
68
|
+
|
|
69
|
+
操作说明:`);
|
|
70
|
+
for (const [name, info] of Object.entries(OPS)) {
|
|
71
|
+
console.log(` ${name.padEnd(9)} ${info.desc}`);
|
|
72
|
+
console.log(` ${info.requirement}`);
|
|
73
|
+
}
|
|
74
|
+
console.log(`
|
|
75
|
+
约定:调用方只传工作区路径和 AID,剩下的事都由脚本做完。
|
|
76
|
+
|
|
77
|
+
初始化前先体检(只读,不改任何东西):
|
|
78
|
+
node "<技能目录>/scripts/check.mjs" --workspace <路径>`);
|
|
79
|
+
process.exit(op && !OPS[op] ? 30 : 0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 从命令行参数里取某个选项的值 */
|
|
83
|
+
function argValue(name) {
|
|
84
|
+
const i = rest.indexOf(name);
|
|
85
|
+
return i !== -1 ? rest[i + 1] : undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Core 的 PA 工作区绑定。
|
|
90
|
+
*
|
|
91
|
+
* 少了它,App 里就没有「个人助理」入口,`ec pa-workspace navigation show` 报
|
|
92
|
+
* NOT_CONFIGURED。绑定属于初始化的一部分,不是事后补的独立动作。
|
|
93
|
+
*/
|
|
94
|
+
function coreBinding() {
|
|
95
|
+
const workspace = argValue('--workspace');
|
|
96
|
+
const self = argValue('--self') || process.env.EVOLCORE_SELF_AID;
|
|
97
|
+
const dryRun = rest.includes('--dry-run');
|
|
98
|
+
if (!workspace || !self) {
|
|
99
|
+
return { ok: false, reason: '缺少 --workspace 或 --self,无法绑定 Core' };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const statePath = join(process.env.EVOLCORE_HOME || join(homedir(), '.evolcore'),
|
|
103
|
+
'agents', self, 'data', 'pa-workspace-state.json');
|
|
104
|
+
|
|
105
|
+
if (op === 'clean') {
|
|
106
|
+
// 预览模式(没有 --yes)绝不能动登记:clean.mjs 预览时也返回 0,
|
|
107
|
+
// 光看退出码分不出来,所以这里必须自己判断工作区是否真的已经删掉。
|
|
108
|
+
if (!existsSync(resolve(workspace))) {
|
|
109
|
+
if (!existsSync(statePath)) return { ok: true, action: 'none' };
|
|
110
|
+
} else if (!rest.includes('--yes')) {
|
|
111
|
+
return { ok: true, action: 'preview' };
|
|
112
|
+
}
|
|
113
|
+
if (!existsSync(statePath)) return { ok: true, action: 'none' };
|
|
114
|
+
let bound = null;
|
|
115
|
+
try { bound = JSON.parse(readFileSync(statePath, 'utf8')).rootPath; } catch { /* 损坏也照删 */ }
|
|
116
|
+
// 指向别的工作区就不动它——那是别的 Agent 的登记
|
|
117
|
+
if (bound && resolve(bound) !== resolve(workspace)) {
|
|
118
|
+
return { ok: false, reason: `Core 登记指向另一个工作区:${bound}` };
|
|
119
|
+
}
|
|
120
|
+
if (dryRun) return { ok: true, action: 'remove' };
|
|
121
|
+
try {
|
|
122
|
+
unlinkSync(statePath);
|
|
123
|
+
return { ok: true, action: 'removed' };
|
|
124
|
+
} catch (e) {
|
|
125
|
+
return { ok: false, reason: String(e.message).slice(0, 200) };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// init / uninstall / update:已绑到同一个工作区就跳过
|
|
130
|
+
if (existsSync(statePath)) {
|
|
131
|
+
try {
|
|
132
|
+
const bound = JSON.parse(readFileSync(statePath, 'utf8')).rootPath;
|
|
133
|
+
if (bound && resolve(bound) === resolve(workspace)) return { ok: true, action: 'already' };
|
|
134
|
+
} catch { /* 损坏则重新绑定 */ }
|
|
135
|
+
}
|
|
136
|
+
if (dryRun) return { ok: true, action: 'bind' };
|
|
137
|
+
try {
|
|
138
|
+
execFileSync('ec', ['pa-workspace', 'bind', '--workspace', workspace], {
|
|
139
|
+
stdio: 'pipe', encoding: 'utf8', shell: process.platform === 'win32',
|
|
140
|
+
});
|
|
141
|
+
return { ok: true, action: 'bound' };
|
|
142
|
+
} catch (e) {
|
|
143
|
+
const detail = String(e.stderr || e.message);
|
|
144
|
+
return { ok: false, reason: detail.trim().slice(0, 200) };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const script = join(HERE, OPS[op].script);
|
|
149
|
+
const result = spawnSync(process.execPath, [script, ...rest], { stdio: 'inherit' });
|
|
150
|
+
|
|
151
|
+
if (result.error) {
|
|
152
|
+
console.error(`无法执行 ${OPS[op].script}:${result.error.message}`);
|
|
153
|
+
process.exit(30);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 子脚本成功后才动 Core 绑定;失败了就别把登记改来改去
|
|
157
|
+
if (result.status === 0 || op === 'clean') {
|
|
158
|
+
const bind = coreBinding();
|
|
159
|
+
const label = {
|
|
160
|
+
bound: '已绑定',
|
|
161
|
+
already: '已绑定(未改动)',
|
|
162
|
+
preview: '预览模式,未改动(真正清理时才解绑)',
|
|
163
|
+
bind: '将绑定',
|
|
164
|
+
remove: '将解绑',
|
|
165
|
+
removed: '已解绑',
|
|
166
|
+
none: '无需处理',
|
|
167
|
+
}[bind.action];
|
|
168
|
+
|
|
169
|
+
if (bind.ok) console.log(`\nCore 绑定:${label || bind.action}`);
|
|
170
|
+
else console.log(`\nCore 绑定:⚠️ ${bind.reason}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
process.exit(result.status ?? 30);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* uninstall.mjs —— 撤销个人助理初始化
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* node "<技能目录>/scripts/uninstall.mjs" --self <AID> [--workspace <路径>]
|
|
7
|
+
* [--remove-triggers] [--dry-run] [--json]
|
|
8
|
+
*
|
|
9
|
+
* 做什么:
|
|
10
|
+
* 1. soul「工作方式」分册(personal/soul/04-working-style.md):有备份就恢复备份,
|
|
11
|
+
* 没有备份就只摘掉本技能写入的标记块
|
|
12
|
+
* 2. 可选:删除本技能安装的 pa-* 触发器
|
|
13
|
+
* 3. 工作区文件一律不动(数据是用户的,撤装不等于删档)
|
|
14
|
+
*
|
|
15
|
+
* 退出码:
|
|
16
|
+
* 0 成功
|
|
17
|
+
* 20 部分失败
|
|
18
|
+
* 30 前置条件不满足
|
|
19
|
+
*/
|
|
20
|
+
import { existsSync } from 'node:fs';
|
|
21
|
+
import { execFileSync } from 'node:child_process';
|
|
22
|
+
import { restorePersona, personaPath, BACKUP_NAME } from './lib/persona.mjs';
|
|
23
|
+
|
|
24
|
+
function parseArgs(argv) {
|
|
25
|
+
const out = { json: false, dryRun: false, removeTriggers: false };
|
|
26
|
+
for (let i = 2; i < argv.length; i++) {
|
|
27
|
+
const a = argv[i];
|
|
28
|
+
if (a === '--self') out.self = argv[++i];
|
|
29
|
+
else if (a === '--workspace' || a === '-w') out.workspace = argv[++i];
|
|
30
|
+
else if (a === '--remove-triggers') out.removeTriggers = true;
|
|
31
|
+
else if (a === '--dry-run') out.dryRun = true;
|
|
32
|
+
else if (a === '--json') out.json = true;
|
|
33
|
+
else if (a === '--help' || a === '-h') out.help = true;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const args = parseArgs(process.argv);
|
|
39
|
+
const selfAid = args.self || process.env.EVOLCORE_SELF_AID || '';
|
|
40
|
+
|
|
41
|
+
if (args.help || !selfAid || !args.workspace) {
|
|
42
|
+
console.log(`用法:node uninstall.mjs --self <AID> --workspace <路径> [选项]
|
|
43
|
+
|
|
44
|
+
--self <AID> 必填,用来定位 soul「工作方式」分册(也可用 EVOLCORE_SELF_AID 注入)
|
|
45
|
+
--workspace <路径> 必填,校验分册里登记的确实是这个工作区
|
|
46
|
+
--remove-triggers 一并删除 pa-* 触发器
|
|
47
|
+
--dry-run 只报告会做什么,不落盘
|
|
48
|
+
--json 机器可读输出
|
|
49
|
+
|
|
50
|
+
撤销只影响 soul「工作方式」分册和触发器;工作区里的档案一律保留,不会被删除。
|
|
51
|
+
|
|
52
|
+
--workspace 不是摆设:分册里登记的是另一个路径时会直接拒绝,
|
|
53
|
+
避免 A 工作区的清理命令把 B 工作区的入口摘掉。`);
|
|
54
|
+
process.exit(args.help ? 0 : 30);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const TRIGGERS = ['pa-ingest-daily', 'pa-report-daily', 'pa-report-weekly', 'pa-memory-consolidate'];
|
|
58
|
+
|
|
59
|
+
const persona = restorePersona({ selfAid, workspace: args.workspace, dryRun: args.dryRun });
|
|
60
|
+
|
|
61
|
+
// 路径对不上就整体中止,连触发器也不动——说明调用方搞错了工作区
|
|
62
|
+
let triggerReport = null;
|
|
63
|
+
if (persona.action === 'mismatch') {
|
|
64
|
+
triggerReport = { removed: [], failed: [], aborted: true };
|
|
65
|
+
} else if (args.removeTriggers) {
|
|
66
|
+
const removed = [];
|
|
67
|
+
const failed = [];
|
|
68
|
+
for (const id of TRIGGERS) {
|
|
69
|
+
if (args.dryRun) { removed.push(id); continue; }
|
|
70
|
+
try {
|
|
71
|
+
execFileSync('ec', ['trigger', 'delete', id], {
|
|
72
|
+
stdio: 'pipe', encoding: 'utf8', shell: process.platform === 'win32',
|
|
73
|
+
});
|
|
74
|
+
removed.push(id);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
const detail = String(e.stderr || e.message);
|
|
77
|
+
// 不存在不算失败:本来就没装
|
|
78
|
+
if (/not found|不存在/i.test(detail)) continue;
|
|
79
|
+
failed.push({ id, reason: detail.slice(0, 200) });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
triggerReport = { removed, failed };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const exitCode = (!persona.ok || triggerReport?.failed.length) ? 20 : 0;
|
|
86
|
+
|
|
87
|
+
if (args.json) {
|
|
88
|
+
console.log(JSON.stringify({
|
|
89
|
+
ok: exitCode === 0,
|
|
90
|
+
persona,
|
|
91
|
+
triggers: triggerReport,
|
|
92
|
+
workspace: args.workspace || null,
|
|
93
|
+
note: '工作区文件未改动',
|
|
94
|
+
}, null, 2));
|
|
95
|
+
process.exit(exitCode);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log(`${args.dryRun ? '[dry-run] ' : ''}撤销个人助理初始化`);
|
|
99
|
+
console.log(`工作区:${args.workspace}`);
|
|
100
|
+
console.log('');
|
|
101
|
+
|
|
102
|
+
if (persona.action === 'mismatch') {
|
|
103
|
+
console.log('❌ 拒绝执行:路径对不上');
|
|
104
|
+
console.log(` · 传入:${args.workspace}`);
|
|
105
|
+
console.log(` · 分册登记:${persona.recorded}`);
|
|
106
|
+
console.log(' · 确认要清理的是哪个工作区,用正确路径重跑');
|
|
107
|
+
} else if (persona.ok) {
|
|
108
|
+
const label = {
|
|
109
|
+
'restored-from-backup': `从备份恢复:${BACKUP_NAME}`,
|
|
110
|
+
'block-removed': '摘掉工作区入口段落,原有人格内容保留',
|
|
111
|
+
'deleted': '原本没有备份,删除本次创建的 soul「工作方式」分册',
|
|
112
|
+
'noop': 'soul「工作方式」分册不存在,无需处理',
|
|
113
|
+
}[persona.action] || persona.action;
|
|
114
|
+
console.log(`soul 工作方式:${args.dryRun ? '将' : '已'}${label}`);
|
|
115
|
+
} else {
|
|
116
|
+
console.log(`soul 工作方式:⚠️ ${persona.error}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (triggerReport?.aborted) {
|
|
120
|
+
console.log('触发器:未处理(路径校验未通过)');
|
|
121
|
+
} else if (triggerReport) {
|
|
122
|
+
console.log(`触发器:已删除 ${triggerReport.removed.length} 个`);
|
|
123
|
+
for (const f of triggerReport.failed) console.log(` · ${f.id}:${f.reason}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log('');
|
|
127
|
+
console.log('ℹ️ 工作区文件未改动。要删档案请手动处理,本脚本不碰用户数据。');
|
|
128
|
+
if (exitCode !== 0) console.log('⚠️ 部分完成,见上面失败项');
|
|
129
|
+
|
|
130
|
+
process.exit(exitCode);
|