@givolt/i3-composer-agent 2.2.1 → 2.2.2
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +38 -17
- package/bin/asset-fingerprint.cjs +3 -5
- package/bin/i3-composer-agent.cjs +9 -5
- package/bin/install.cjs +42 -66
- package/bin/legacy-native-files.json +329 -0
- package/bin/native-command-validation.cjs +27 -0
- package/bin/native-content.cjs +0 -1
- package/bin/native-layout.cjs +135 -0
- package/bin/native-migration.cjs +93 -0
- package/bin/native-runtime.cjs +57 -0
- package/bin/native-version-validation.cjs +8 -0
- package/bin/wizard.cjs +3 -1
- package/docs/codebuddy-setup.md +4 -3
- package/docs/codex-setup.md +5 -3
- package/docs/workbuddy-setup.md +8 -6
- package/evals/README.md +31 -22
- package/evals/skill-impact.md +6 -0
- package/package.json +3 -1
- package/plugin.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# i3 Composer Agent v2.2.
|
|
1
|
+
# i3 Composer Agent v2.2.2
|
|
2
2
|
|
|
3
3
|
**Intelligence. Integration. Innovation.**
|
|
4
4
|
|
|
@@ -26,8 +26,9 @@ WorkBuddy 在第 2 项。上下键移动,空格勾选/取消,回车确认;
|
|
|
26
26
|
确认工具后选择项目/全局范围并确认安装。
|
|
27
27
|
|
|
28
28
|
全部目标均安装 25 个技能、共享参考资料,以及完整评测/Hook/脚本配套。
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
全部目标同时提供 9 个命令和 4 个 Agent 角色提示。
|
|
30
|
+
CodeBuddy、WorkBuddy、Claude Code 使用原生命令入口;其他工具通过 Skills 机制使用,
|
|
31
|
+
命令和角色文件可作为资料读取,是否自动发现取决于宿主。
|
|
31
32
|
目录预设来自固定的 [Skills CLI 工具登记](https://github.com/vercel-labs/skills/blob/48dc9e8eb8aa19040e91cb90ba0b642c9cbad57e/src/agents.ts)
|
|
32
33
|
并增加 WorkBuddy。目录预设验证与每个宿主的实际执行验收分别记录。
|
|
33
34
|
|
|
@@ -53,41 +54,61 @@ CodeBuddy 和 WorkBuddy 的项目安装共用 `.codebuddy/`,相同目标只安
|
|
|
53
54
|
同版本、同范围的清单所属未修改内容会复用,新增客户端合并到清单。
|
|
54
55
|
升级、修改过的内容及未登记同名冲突需确认替换;非交互使用 `--force` 前可先看 dry-run。
|
|
55
56
|
安装成功后清理替换掉的旧内容及本安装器所属历史备份,失败则恢复原文件。
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
升级按文件归属清理旧副本,保留用户新增文件;旧评测结果迁入新的 evals 分组。
|
|
58
|
+
同名结果内容不同时会在写入前停止;未归属本包的资料冲突也需先处理,`--force` 不会接管。
|
|
59
|
+
成功后不保留临时备份。`npx -y` 确认 npm 下载;包的 `--yes` 确认安装计划。
|
|
58
60
|
|
|
59
61
|
## 安装内容与可选功能
|
|
60
62
|
|
|
61
63
|
| 内容 | 默认安装 | 用途 |
|
|
62
64
|
| --- | --- | --- |
|
|
63
65
|
| `skills/`(含技能内部的 `scripts/` 等资源) | 是 | 工程工作流及运行辅助文件 |
|
|
64
|
-
| `references/` | 是 | 技能引用的检查清单与参考资料 |
|
|
65
|
-
| `commands/`、`agents/` |
|
|
66
|
+
| `references/i3-composer-agent/` | 是 | 技能引用的检查清单与参考资料 |
|
|
67
|
+
| `commands/`、`agents/` | 是;发现与调用依宿主支持 | 短命令与专业角色提示 |
|
|
66
68
|
| `hooks/` | 是,文件安装后按宿主方式启用 | 会话注入、文档缓存和代码块保护 |
|
|
67
69
|
| `scripts/` | 是 | 评测运行器、五项校验脚本及其共享库 |
|
|
68
70
|
| `evals/` | 是 | 中英文触发/行为用例、测试项目样例及插件评分规则 |
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
`.codebuddy/i3-composer-agent/` 或 `~/.workbuddy/i3-composer-agent/`。
|
|
72
|
-
其中保留对应的技能、命令、角色、参考资料与清单,供评测、校验和 Hook 的相对路径使用;
|
|
73
|
-
宿主调用入口继续安装在其原生目录。该配套与技能一起升级、复用和失败恢复。
|
|
72
|
+
以项目安装的 `.codebuddy/` 为例,默认目录为:
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
```text
|
|
75
|
+
.codebuddy/
|
|
76
|
+
├─ skills/ # 宿主和评测共用的实际技能
|
|
77
|
+
├─ commands/ # 一份命令
|
|
78
|
+
├─ agents/ # 一份角色提示
|
|
79
|
+
├─ references/i3-composer-agent/
|
|
80
|
+
├─ evals/i3-composer-agent/ # 用例、样例、插件评测与运行结果
|
|
81
|
+
├─ hooks/i3-composer-agent/
|
|
82
|
+
├─ scripts/i3-composer-agent/ # .cjs 入口及 lib/
|
|
83
|
+
├─ docs/i3-composer-agent/
|
|
84
|
+
└─ .i3-composer-agent.json # 版本、布局、能力与文件归属清单
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
每个宿主基址只有一份技能;公共资料按插件名称分组。技能内部的 scripts/references 保留。
|
|
88
|
+
WorkBuddy 全局安装将基址换为 `~/.workbuddy/`,Codex 项目安装为 `.agents/`。
|
|
89
|
+
评测、校验和适用的 Hook 读取宿主使用的实际内容,不生成第二份完整插件。
|
|
90
|
+
|
|
91
|
+
从业务项目目录运行以下检查,不调用模型;也可用脚本绝对路径从任意目录运行:
|
|
76
92
|
|
|
77
93
|
```bash
|
|
78
|
-
|
|
79
|
-
node scripts/
|
|
94
|
+
node .codebuddy/scripts/i3-composer-agent/validate-skills.cjs
|
|
95
|
+
node .codebuddy/scripts/i3-composer-agent/validate-versions.cjs
|
|
96
|
+
node .codebuddy/scripts/i3-composer-agent/validate-commands.cjs
|
|
97
|
+
node .codebuddy/scripts/i3-composer-agent/validate-reference-links.cjs
|
|
98
|
+
node .codebuddy/scripts/i3-composer-agent/validate-artifact-paths.cjs
|
|
99
|
+
node .codebuddy/scripts/i3-composer-agent/run-evals.cjs --locale zh-CN --min-rank1 95
|
|
80
100
|
```
|
|
81
101
|
|
|
82
102
|
模型行为评测需要主动运行并消耗模型额度,详见 [评测说明](evals/README.md)。
|
|
83
|
-
|
|
103
|
+
原生脚本按安装清单检查本包内容,支持业务项目的 ESM/CommonJS 设置。
|
|
104
|
+
独立插件导出目录仍可执行 `npm test`;上述检查均不能代替业务项目测试或宿主执行验收。
|
|
84
105
|
评测结果不进入安装替换清单。安装过程不执行评测,也不自动启用 Hook。
|
|
85
106
|
|
|
86
107
|
可选 Hook 不影响普通技能和命令的使用,默认中文交互也不依赖 Hook。
|
|
87
108
|
未配置 Hook 时,自动注入、缓存和代码块保护这些增强功能不会运行。
|
|
88
109
|
会话注入仅适合缺少原生技能路由的宿主;已有原生路由时不应重复注入元技能。
|
|
89
|
-
|
|
90
|
-
`
|
|
110
|
+
缓存与代码块保护的配置说明位于 `hooks/i3-composer-agent/` 下的 `SDD-CACHE.md`、
|
|
111
|
+
`SIMPLIFY-IGNORE.md`,当前示例针对 Claude Code,其他宿主需适配自己的事件协议。
|
|
91
112
|
脚本依赖 Bash、jq;缓存还需 curl 和哈希工具,代码块保护还需其文档列出的工具。
|
|
92
113
|
Windows PowerShell 本身不会自动提供这些脚本依赖。
|
|
93
114
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const crypto = require('node:crypto');
|
|
6
|
-
const {
|
|
6
|
+
const { renderAsset } = require('./native-layout.cjs');
|
|
7
7
|
|
|
8
8
|
// Compare the complete tree without following links. When asset is provided,
|
|
9
9
|
// hash the source as it will be rendered by the native installer.
|
|
@@ -21,13 +21,11 @@ function fingerprint(file, asset) {
|
|
|
21
21
|
if (stat.isDirectory()) {
|
|
22
22
|
for (const entry of fs.readdirSync(current).sort()) {
|
|
23
23
|
if (asset && entry === '.DS_Store') continue;
|
|
24
|
-
if (asset?.kind === 'support' && ['results', 'node_modules', '.git'].includes(entry)) continue;
|
|
25
24
|
if (!visit(path.join(current, entry), path.join(relative, entry))) return false;
|
|
26
25
|
}
|
|
27
26
|
} else {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
: fs.readFileSync(current);
|
|
27
|
+
const bytes = fs.readFileSync(current);
|
|
28
|
+
const content = asset ? renderAsset(bytes, asset) : bytes;
|
|
31
29
|
hash.update(String(content.length) + '\n');
|
|
32
30
|
hash.update(content);
|
|
33
31
|
}
|
|
@@ -46,7 +46,8 @@ ${pkg.name}
|
|
|
46
46
|
上下键移动/跨页,空格勾选/取消,回车确认;列表下实时显示已选,q/Esc 退出。
|
|
47
47
|
CodeBuddy、WorkBuddy、Claude Code 同时安装短命令和 Agent 角色。
|
|
48
48
|
其他工具通过 Skills 调用,短命令支持取决于宿主。
|
|
49
|
-
|
|
49
|
+
所有工具默认安装单份 skills、commands、agents;资料按 references/evals/hooks/scripts/docs 分组。
|
|
50
|
+
评测、脚本和 Hook 读取同一份已安装技能。--prepare 用于另行导出标准插件并按宿主方式注册。
|
|
50
51
|
WorkBuddy 桌面版建议全局安装,便于技能列表和输入补全发现。
|
|
51
52
|
评测需主动运行;Hook 文件已提供,需按宿主事件协议单独启用。
|
|
52
53
|
--prepare 仅供插件管理器安装方式使用,不自动注册插件或启用 Hook。
|
|
@@ -201,12 +202,15 @@ async function main() {
|
|
|
201
202
|
if (plan.reused.length) console.log(`已复用同版本的 ${plan.reused.length} 个未修改内容。`);
|
|
202
203
|
for (const target of plan.targets) {
|
|
203
204
|
console.log(`已为 ${target.agents.join(', ')} 安装技能:${target.skillsDirectory}`);
|
|
204
|
-
if (target.
|
|
205
|
-
console.log(
|
|
206
|
-
console.log(
|
|
205
|
+
if (target.nativeCommands) console.log(`命令:/i3-spec、/i3-plan、/i3-build、/i3-ship(共 ${target.catalog.commands.length} 个工作流):${target.commandsDirectory}`);
|
|
206
|
+
else console.log(`命令和角色资料已提供;是否自动发现取决于宿主:${target.commandsDirectory}、${target.personasDirectory}`);
|
|
207
|
+
console.log(`评测资料:${target.evalsDirectory}`);
|
|
208
|
+
console.log(`中文评测:node "${path.join(target.scriptsDirectory, 'run-evals.cjs')}" --locale zh-CN --min-rank1 95`);
|
|
209
|
+
console.log(`Hook:${target.hooksDirectory}(尚未启用)`);
|
|
207
210
|
}
|
|
211
|
+
for (const directory of plan.preserved || []) console.log(`旧目录中保留了用户文件:${directory}`);
|
|
208
212
|
console.log('请重新加载 IDE 窗口或新建宿主会话以发现安装内容。');
|
|
209
213
|
if (plan.agents.some(id => !['codebuddy', 'workbuddy', 'claude-code'].includes(id))) console.log('这些工具通过技能 ID 调用;生命周期短命令支持取决于宿主。');
|
|
210
|
-
console.log('
|
|
214
|
+
console.log('安装完成。评测说明见 evals/i3-composer-agent/README.md;Hook 需按宿主事件协议启用。');
|
|
211
215
|
}
|
|
212
216
|
main().catch(error => { console.error(`${name}: ${error.message}`); process.exitCode = 1; });
|
package/bin/install.cjs
CHANGED
|
@@ -6,7 +6,8 @@ const os = require('node:os');
|
|
|
6
6
|
const crypto = require('node:crypto');
|
|
7
7
|
const registry = require('./agent-targets.json');
|
|
8
8
|
const { cleanupBackups } = require('./cleanup-backups.cjs');
|
|
9
|
-
const {
|
|
9
|
+
const { nativeAssets, renderAsset } = require('./native-layout.cjs');
|
|
10
|
+
const { migrationAssets, pruneRetiredDirectories } = require('./native-migration.cjs');
|
|
10
11
|
const { fingerprint } = require('./asset-fingerprint.cjs');
|
|
11
12
|
const root = path.resolve(__dirname, '..');
|
|
12
13
|
const name = 'i3-composer-agent';
|
|
@@ -49,8 +50,10 @@ function checkDestination(file) {
|
|
|
49
50
|
}
|
|
50
51
|
function assetPath(base, file) { return path.relative(base, file).split(path.sep).join('/'); }
|
|
51
52
|
function manifestContent(plan, asset) {
|
|
52
|
-
return JSON.stringify({ name, version, entryPrefix: 'i3-', scope: plan.scope, agents: asset.target.agents,
|
|
53
|
-
|
|
53
|
+
return JSON.stringify({ name, version, layoutVersion: 2, entryPrefix: 'i3-', scope: plan.scope, agents: asset.target.agents,
|
|
54
|
+
capabilities: { nativeCommands: !!asset.target.nativeCommands, nativeAgents: !!asset.target.nativeCommands, hooks: 'manual' },
|
|
55
|
+
catalog: asset.target.catalog, resources: asset.target.resources,
|
|
56
|
+
assets: plan.assets.filter(item => item.base === asset.base && !['legacy', 'result'].includes(item.kind)).map(item => assetPath(asset.base, item.destination)) }, null, 2) + '\n';
|
|
54
57
|
}
|
|
55
58
|
function planInstallation({ agents, scope, projectDir = process.cwd(), home = os.homedir(), env = process.env }) {
|
|
56
59
|
agents = selectAgents(agents);
|
|
@@ -61,24 +64,17 @@ function planInstallation({ agents, scope, projectDir = process.cwd(), home = os
|
|
|
61
64
|
const agent = registry.agents.find(item => item.id === id);
|
|
62
65
|
const skillsDirectory = destination(scope === 'project' ? path.resolve(projectDir, agent.projectSkillsDir) : globalSkillsDir(agent, home, env));
|
|
63
66
|
const base = path.dirname(skillsDirectory);
|
|
64
|
-
if (!targets.has(skillsDirectory)) targets.set(skillsDirectory, { agents: [], skillsDirectory, referencesDirectory: path.join(base, 'references'
|
|
67
|
+
if (!targets.has(skillsDirectory)) targets.set(skillsDirectory, { agents: [], skillsDirectory, referencesDirectory: path.join(base, 'references', name),
|
|
68
|
+
commandsDirectory: path.join(base, 'commands'), personasDirectory: path.join(base, 'agents'),
|
|
69
|
+
evalsDirectory: path.join(base, 'evals', name), scriptsDirectory: path.join(base, 'scripts', name),
|
|
70
|
+
hooksDirectory: path.join(base, 'hooks', name), docsDirectory: path.join(base, 'docs', name), base });
|
|
65
71
|
const target = targets.get(skillsDirectory);
|
|
66
72
|
target.agents.push(id);
|
|
67
73
|
if (['codebuddy', 'workbuddy', 'claude-code'].includes(id)) {
|
|
68
|
-
target.
|
|
69
|
-
target.personasDirectory = path.join(base, 'agents');
|
|
74
|
+
target.nativeCommands = true;
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
const assets = [];
|
|
73
|
-
function addDirectory(sourceDirectory, destinationDirectory, kind) {
|
|
74
|
-
if (exists(destinationDirectory) && fs.lstatSync(destinationDirectory).isSymbolicLink()) {
|
|
75
|
-
throw new Error(`安装目录是符号链接(symlink): ${destinationDirectory}. 请选择其真实目录。`);
|
|
76
|
-
}
|
|
77
|
-
for (const entry of fs.readdirSync(path.join(root, sourceDirectory)).sort()) {
|
|
78
|
-
if (entry === '.DS_Store') continue;
|
|
79
|
-
assets.push({ source: path.join(root, sourceDirectory, entry), destination: destination(path.join(destinationDirectory, entry)), kind });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
78
|
for (const target of targets.values()) {
|
|
83
79
|
const manifestFile = path.join(target.base, `.${name}.json`);
|
|
84
80
|
const previous = exists(manifestFile) && !fs.lstatSync(manifestFile).isSymbolicLink()
|
|
@@ -87,7 +83,7 @@ function planInstallation({ agents, scope, projectDir = process.cwd(), home = os
|
|
|
87
83
|
// Earlier Windows installs persisted backslashes. Normalize before lookup
|
|
88
84
|
// and containment checks so owned upgrades work across both manifest forms.
|
|
89
85
|
if (owned) previous.assets = previous.assets.map(relative => typeof relative === 'string' ? relative.replaceAll('\\', '/') : relative);
|
|
90
|
-
const sameVersion = owned && previous.version === version && previous.scope === scope && previous.entryPrefix === 'i3-';
|
|
86
|
+
const sameVersion = owned && previous.layoutVersion === 2 && previous.version === version && previous.scope === scope && previous.entryPrefix === 'i3-';
|
|
91
87
|
if (owned && previous.scope === scope && Array.isArray(previous.agents)) {
|
|
92
88
|
const applicable = previous.agents.filter(id => {
|
|
93
89
|
const agent = registry.agents.find(item => item.id === id);
|
|
@@ -97,47 +93,24 @@ function planInstallation({ agents, scope, projectDir = process.cwd(), home = os
|
|
|
97
93
|
});
|
|
98
94
|
target.agents = [...new Set([...applicable, ...target.agents])];
|
|
99
95
|
}
|
|
96
|
+
target.nativeCommands = target.agents.some(id => ['codebuddy', 'workbuddy', 'claude-code'].includes(id));
|
|
100
97
|
const start = assets.length;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
assets.push({ source: path.join(root, 'LICENSE'), destination: destination(path.join(licenseDirectory, 'LICENSE')), kind: 'attribution' });
|
|
113
|
-
// Keep the canonical plugin layout for eval fixtures, validators and Hook
|
|
114
|
-
// relative paths. Native entry points above remain host-adapted copies.
|
|
115
|
-
for (const relative of pluginFiles) {
|
|
116
|
-
const file = path.join(target.supportDirectory, relative);
|
|
117
|
-
if (destination(file) !== file) throw new Error(`配套目录包含符号链接(symlink): ${file}`);
|
|
118
|
-
assets.push({ source: path.join(root, relative), destination: file, kind: 'support' });
|
|
119
|
-
}
|
|
120
|
-
if (owned) {
|
|
121
|
-
const legacy = fs.readdirSync(path.join(root, 'skills')).filter(id => id.startsWith('i3-')).map(id => `skills/${id.slice(3)}`);
|
|
122
|
-
if (target.commandsDirectory) legacy.push(...fs.readdirSync(path.join(root, '.claude/commands')).filter(file => file.startsWith('i3-') && file.endsWith('.md')).map(file => `commands/${file.slice(3)}`));
|
|
123
|
-
legacy.push(`${name}-LICENSE`, `${name}-NOTICE.md`);
|
|
124
|
-
const current = new Set(assets.slice(start).map(asset => assetPath(target.base, asset.destination)));
|
|
125
|
-
for (const relative of previous.assets) {
|
|
126
|
-
// Retire only owned native entries or entries inside this package's
|
|
127
|
-
// companion directory. Never let a manifest extend the deletion scope.
|
|
128
|
-
if (typeof relative !== 'string' || relative.includes('\0') || relative.includes(':')
|
|
129
|
-
|| relative.split('/').some(part => ['', '.', '..'].includes(part))) continue;
|
|
130
|
-
if (!/^(skills|commands|agents|references)\/[^/]+$/.test(relative) && !relative.startsWith(`${name}/`)) continue;
|
|
131
|
-
if (relative.startsWith(`${name}/`) && destination(path.join(target.base, relative)) !== path.join(target.base, relative)) continue;
|
|
132
|
-
if (!current.has(relative)) legacy.push(relative);
|
|
133
|
-
}
|
|
134
|
-
for (const relative of new Set(legacy)) {
|
|
135
|
-
const file = destination(path.join(target.base, relative));
|
|
136
|
-
if (previous.assets.includes(relative) && exists(file)) assets.push({ destination: file, kind: 'legacy' });
|
|
98
|
+
const additions = nativeAssets(root, target, pluginFiles, version);
|
|
99
|
+
const current = new Set(additions.map(asset => asset.relative));
|
|
100
|
+
assets.push(...additions, ...migrationAssets(target, owned ? previous : undefined, current));
|
|
101
|
+
for (const asset of additions) {
|
|
102
|
+
// A new grouped resource must not take ownership of an unrelated file,
|
|
103
|
+
// even when --force confirms replacement of a previous installation.
|
|
104
|
+
const previousOwned = owned && previous.assets.some(relative => relative === asset.relative
|
|
105
|
+
|| (previous.layoutVersion !== 2 && asset.relative.startsWith(relative + '/')));
|
|
106
|
+
asset.protectedResource = /^(references|evals|hooks|scripts|docs)\//.test(asset.relative);
|
|
107
|
+
if (exists(asset.destination) && !previousOwned && asset.protectedResource) {
|
|
108
|
+
throw new Error(`未归属本包的同名资源,不能覆盖,请先处理:${asset.destination}`);
|
|
137
109
|
}
|
|
138
110
|
}
|
|
139
111
|
assets.push({ target, destination: destination(manifestFile), kind: 'manifest', mergeable: sameVersion });
|
|
140
112
|
for (const asset of assets.slice(start)) {
|
|
113
|
+
if (destination(asset.destination) !== asset.destination) throw new Error(`安装目录包含符号链接(symlink):${asset.destination}`);
|
|
141
114
|
asset.base = target.base;
|
|
142
115
|
asset.buddyCommand = asset.kind === 'command' && target.agents.some(id => ['codebuddy', 'workbuddy'].includes(id));
|
|
143
116
|
asset.scope = scope;
|
|
@@ -149,6 +122,9 @@ function planInstallation({ agents, scope, projectDir = process.cwd(), home = os
|
|
|
149
122
|
}
|
|
150
123
|
}
|
|
151
124
|
for (const asset of assets) { checkDestination(asset.destination); asset.existing = exists(asset.destination); }
|
|
125
|
+
for (const asset of assets.filter(item => item.existing)) {
|
|
126
|
+
if (!fs.lstatSync(asset.destination).isFile()) throw new Error(`目标文件被目录或符号链接占用(symlink):${asset.destination}`);
|
|
127
|
+
}
|
|
152
128
|
const plan = { mode: 'install', scope, agents, targets: [...targets.values()], assets };
|
|
153
129
|
for (const asset of assets.filter(item => item.kind === 'manifest' && item.mergeable)) {
|
|
154
130
|
asset.observedFingerprint = fingerprint(asset.destination);
|
|
@@ -172,13 +148,6 @@ function executeInstallation(plan, { force = false } = {}) {
|
|
|
172
148
|
fs.mkdirSync(directory);
|
|
173
149
|
createdDirectories.push(directory);
|
|
174
150
|
}
|
|
175
|
-
function portable(file, asset, markdown = false) {
|
|
176
|
-
if (fs.statSync(file).isDirectory()) {
|
|
177
|
-
for (const entry of fs.readdirSync(file)) portable(path.join(file, entry), asset);
|
|
178
|
-
} else if (markdown || file.endsWith('.md')) {
|
|
179
|
-
fs.writeFileSync(file, nativeContent(fs.readFileSync(file, 'utf8'), asset));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
151
|
try {
|
|
183
152
|
// Stage every target before replacing the first installed asset.
|
|
184
153
|
for (const [index, asset] of plan.assets.entries()) {
|
|
@@ -192,17 +161,22 @@ function executeInstallation(plan, { force = false } = {}) {
|
|
|
192
161
|
if (asset.kind === 'manifest') {
|
|
193
162
|
fs.writeFileSync(asset.staged, manifestContent(plan, asset));
|
|
194
163
|
} else {
|
|
195
|
-
fs.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
} });
|
|
200
|
-
portable(asset.staged, asset, asset.source.endsWith('.md'));
|
|
164
|
+
if (!fs.lstatSync(asset.source).isFile()) throw new Error(`包内容不是普通文件:${asset.source}`);
|
|
165
|
+
const bytes = fs.readFileSync(asset.source);
|
|
166
|
+
fs.writeFileSync(asset.staged, asset.kind === 'result' ? bytes : renderAsset(bytes, asset));
|
|
167
|
+
fs.chmodSync(asset.staged, fs.statSync(asset.source).mode & 0o777);
|
|
201
168
|
}
|
|
202
169
|
}
|
|
203
170
|
for (const asset of plan.assets) {
|
|
204
171
|
const context = contexts.get(asset.base);
|
|
172
|
+
if (destination(asset.destination) !== asset.destination) throw new Error(`安装期间目录变成符号链接(symlink):${asset.destination}`);
|
|
205
173
|
mkdir(path.dirname(asset.destination));
|
|
174
|
+
if (exists(asset.destination) && !fs.lstatSync(asset.destination).isFile()) throw new Error(`安装期间目标不再是普通文件:${asset.destination}`);
|
|
175
|
+
if (!asset.existing && exists(asset.destination) && (asset.protectedResource || asset.kind === 'result')) {
|
|
176
|
+
throw new Error(`安装期间出现未归属文件:${asset.destination}`);
|
|
177
|
+
}
|
|
178
|
+
if (asset.kind === 'result' && fingerprint(asset.source) !== asset.expectedFingerprint) throw new Error(`安装期间评测结果已改变:${asset.source}`);
|
|
179
|
+
if (asset.kind === 'result' && asset.existing && fingerprint(asset.destination) !== asset.expectedFingerprint) throw new Error(`安装期间目标评测结果已改变:${asset.destination}`);
|
|
206
180
|
if (asset.reusable) {
|
|
207
181
|
const unchanged = fingerprint(asset.destination) === asset.expectedFingerprint
|
|
208
182
|
&& fingerprint(asset.staged) === asset.expectedFingerprint;
|
|
@@ -225,12 +199,14 @@ function executeInstallation(plan, { force = false } = {}) {
|
|
|
225
199
|
change.written = true;
|
|
226
200
|
}
|
|
227
201
|
}
|
|
202
|
+
pruneRetiredDirectories(plan.assets);
|
|
228
203
|
completed = true;
|
|
204
|
+
plan.preserved = plan.targets.map(target => path.join(target.base, name)).filter(file => exists(file));
|
|
229
205
|
return [];
|
|
230
206
|
} catch (error) {
|
|
231
207
|
for (const change of committed.reverse()) {
|
|
232
208
|
if (change.written) fs.rmSync(change.destination, { recursive: true, force: true });
|
|
233
|
-
if (change.backup) fs.renameSync(change.backup, change.destination);
|
|
209
|
+
if (change.backup) { mkdir(path.dirname(change.destination)); fs.renameSync(change.backup, change.destination); }
|
|
234
210
|
}
|
|
235
211
|
rolledBack = true;
|
|
236
212
|
throw error;
|