@namewta/skills-hub 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +1 -1
- package/scripts/persistence/home.md +3 -0
- package/skills/home/home-doctor/SKILL.md +1 -1
- package/skills/home/home-doctor/references/diagnosis.md +1 -0
- package/skills/home/home-doctor/scripts/doctor.mjs +43 -1
- package/skills/home/home-project-changelog/SKILL.md +16 -0
- package/skills/home/home-project-changelog/assets/project-changelog.md +25 -0
- package/skills/home/home-project-changelog/assets/worker-brief.md +13 -0
- package/skills/home/home-project-changelog/references/git-ranges.md +41 -0
- package/skills/home/home-project-changelog/references/tools.md +83 -0
- package/skills/home/home-project-changelog/references/workflow.md +15 -0
- package/skills/home/home-project-changelog/references/writing.md +30 -0
- package/skills/home/home-project-changelog/scripts/changelog.mjs +253 -0
- package/skills/home/home-project-changelog/scripts/contract.mjs +149 -0
- package/skills/home/home-project-changelog/scripts/git.mjs +340 -0
- package/skills/home/home-project-changelog/scripts/storage.mjs +201 -0
- package/skills/home/home-project-changelog/scripts/summary.mjs +95 -0
- package/skills/home/home-route/SKILL.md +1 -1
- package/skills/home/home-route/references/routing.md +4 -0
- package/skills/home/home-route/scripts/route.mjs +21 -15
- package/skills/home/home-setup/SKILL.md +3 -3
- package/skills/home/home-setup/assets/repos.schema.json +5 -0
- package/skills/home/home-setup/references/git.md +4 -2
- package/skills/home/home-setup/references/registry.md +17 -1
- package/skills/home/home-setup/scripts/checkout-tools.mjs +73 -0
- package/skills/home/home-setup/scripts/git.mjs +1 -1
- package/skills/home/home-setup/scripts/refresh-branches.mjs +79 -0
- package/skills/home/home-setup/scripts/registry.mjs +9 -2
- package/skills/home/home-setup/scripts/restore.mjs +33 -72
- package/skills/home/home-workflow/SKILL.md +3 -0
- package/skills/home/home-workflow/references/delegation.md +2 -0
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
import { inspectRegistry, validateLocal } from './registry.mjs';
|
|
4
|
+
import { assertCheckoutState, checkoutTarget, readCheckoutState, realParent, routeRunner, verifyCheckout } from './checkout-tools.mjs';
|
|
6
5
|
import { entry, fail, git, gitRoot, homeRoot, inside, isDirectInvocation } from './git-tools.mjs';
|
|
7
6
|
|
|
8
7
|
const transports = ['file', 'https', 'http', 'ssh', 'git'];
|
|
9
8
|
|
|
10
|
-
function realParent(target) {
|
|
11
|
-
let parent = path.dirname(target);
|
|
12
|
-
while (!entry(parent)) {
|
|
13
|
-
const next = path.dirname(parent);
|
|
14
|
-
if (next === parent) fail('PATH_CONFLICT', '无法到达目标父目录。');
|
|
15
|
-
parent = next;
|
|
16
|
-
}
|
|
17
|
-
for (let current = parent; ; current = path.dirname(current)) {
|
|
18
|
-
if (!entry(current)?.isDirectory()) fail('PATH_CONFLICT', '目标父路径包含目录链接或非目录入口。');
|
|
19
|
-
if (current === path.dirname(current)) break;
|
|
20
|
-
}
|
|
21
|
-
return parent;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
9
|
function assertDestination(home, target) {
|
|
25
10
|
if (inside(target, home) || ['.git', '.agents', 'temp'].some(name => inside(path.join(home, name), target))) {
|
|
26
11
|
fail('PATH_CONFLICT', '目标与 Home 根或其管理目录重叠。');
|
|
@@ -37,48 +22,13 @@ function assertDestination(home, target) {
|
|
|
37
22
|
}
|
|
38
23
|
}
|
|
39
24
|
|
|
40
|
-
function readState(home) {
|
|
41
|
-
for (const relative of ['.agents', '.agents/home']) {
|
|
42
|
-
const directory = path.join(home, relative);
|
|
43
|
-
const stat = entry(directory);
|
|
44
|
-
if (stat && (!stat.isDirectory() || entry(path.join(directory, '.git')))) fail('HOME_BOUNDARY', '登记位置不是 Home 的真实资料目录。');
|
|
45
|
-
}
|
|
46
|
-
const { registry, registryRevision } = inspectRegistry(home, { includeMap: false });
|
|
47
|
-
if (registryRevision === 'absent') fail('MISSING_REGISTRY', '克隆项目需要已有项目登记 repos.json。');
|
|
48
|
-
const localFile = path.join(home, '.agents/home/local.json');
|
|
49
|
-
const stat = entry(localFile);
|
|
50
|
-
if (stat && !stat.isFile()) fail('UNSAFE_LOCAL', 'local.json 必须是同仓普通文件。');
|
|
51
|
-
const localText = stat ? fs.readFileSync(localFile, 'utf8') : null;
|
|
52
|
-
let localPaths = {};
|
|
53
|
-
if (localText !== null) {
|
|
54
|
-
let value;
|
|
55
|
-
try { value = JSON.parse(localText); }
|
|
56
|
-
catch { fail('INVALID_LOCAL', 'local.json 无法解析。'); }
|
|
57
|
-
localPaths = validateLocal(value, registry).paths;
|
|
58
|
-
}
|
|
59
|
-
return { registry, registryRevision, localPaths, localText };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function runRoute(home, args) {
|
|
63
|
-
const script = path.join(home, '.agents/skills/home-route/scripts/route.mjs');
|
|
64
|
-
if (gitRoot(realParent(script)) !== home) fail('UNSAFE_HOME_ROUTE', 'home-route 入口位于另一个 Git 仓库。');
|
|
65
|
-
if (!entry(script)?.isFile()) fail('MISSING_HOME_ROUTE', 'Home 基线缺少同仓 home-route 技能本体。');
|
|
66
|
-
const result = spawnSync(process.execPath, [script, '--home', home, ...args], {
|
|
67
|
-
cwd: home, encoding: 'utf8', timeout: 30_000, maxBuffer: 4 * 1024 * 1024, windowsHide: true,
|
|
68
|
-
});
|
|
69
|
-
let output;
|
|
70
|
-
try { output = JSON.parse(result.status === 0 ? result.stdout : result.stderr); } catch { /* Report an unusable tool response below. */ }
|
|
71
|
-
if (result.status !== 0 || !output) fail(output?.code || 'ROUTE_FAILED', 'home-route 未能核验目标身份。');
|
|
72
|
-
return output;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
25
|
function remoteConfig(repo) {
|
|
76
26
|
if (Object.hasOwn(repo, 'remote')) return repo.remote ? { name: 'origin', url: repo.remote } : null;
|
|
77
27
|
if (repo.primaryRemote === null) return null;
|
|
78
28
|
return { name: repo.primaryRemote, url: repo.remotes.find(remote => remote.name === repo.primaryRemote).urls[0] };
|
|
79
29
|
}
|
|
80
30
|
|
|
81
|
-
function checkRemote(home, source, repo) {
|
|
31
|
+
function checkRemote(home, source, repo, runRoute) {
|
|
82
32
|
const url = source.url;
|
|
83
33
|
const scheme = /^([a-z][a-z0-9+.-]*):\/\//iu.exec(url)?.[1].toLowerCase();
|
|
84
34
|
const local = path.isAbsolute(url) || path.win32.isAbsolute(url);
|
|
@@ -88,7 +38,7 @@ function checkRemote(home, source, repo) {
|
|
|
88
38
|
for (const name of repo.remotes?.map(remote => remote.name) || [source.name]) {
|
|
89
39
|
if (name.startsWith('-') || git(home, ['check-ref-format', `refs/remotes/${name}/HEAD`], { accept: [0, 1] }).status !== 0) fail('INVALID_REMOTE_NAME', '登记的 remote 名称无法用于 Git。');
|
|
90
40
|
}
|
|
91
|
-
if (runRoute(
|
|
41
|
+
if (runRoute(['--check-fetch', url]).status !== 'verified') fail('ROUTE_FAILED', '未确认主远端 URL 的实际身份。');
|
|
92
42
|
}
|
|
93
43
|
|
|
94
44
|
function configureRemotes(directory, repo, primary) {
|
|
@@ -103,12 +53,10 @@ function configureRemotes(directory, repo, primary) {
|
|
|
103
53
|
}
|
|
104
54
|
}
|
|
105
55
|
|
|
106
|
-
function inspectCheckout(
|
|
107
|
-
const result = runRoute
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
return { head: result.head, branch: result.branch, dirty: result.dirty, remoteDrift: result.remoteDrift?.map(({ name, change, fields }) => ({ name, change, fields })) || [] };
|
|
56
|
+
function inspectCheckout(runRoute, repo, checkout, explicit = false) {
|
|
57
|
+
const result = verifyCheckout(runRoute, repo, checkout, explicit ? ['--checkout', checkout] : []);
|
|
58
|
+
return { head: result.head, branch: result.branch, dirty: result.dirty, remoteDrift: result.remoteDrift?.map(({ name, change, fields }) => ({ name, change, fields })) || [],
|
|
59
|
+
...(typeof repo.activeBranch === 'string' ? { branchMatches: Boolean(result.head) && result.branch === repo.activeBranch } : {}) };
|
|
112
60
|
}
|
|
113
61
|
|
|
114
62
|
function publish(staged, target) {
|
|
@@ -125,7 +73,7 @@ function publish(staged, target) {
|
|
|
125
73
|
}
|
|
126
74
|
}
|
|
127
75
|
|
|
128
|
-
function cloneProject(home, repo, target, source, state) {
|
|
76
|
+
function cloneProject(home, repo, target, source, state, runRoute) {
|
|
129
77
|
const parent = path.dirname(target);
|
|
130
78
|
fs.mkdirSync(parent, { recursive: true });
|
|
131
79
|
assertDestination(home, target);
|
|
@@ -133,22 +81,32 @@ function cloneProject(home, repo, target, source, state) {
|
|
|
133
81
|
const staged = path.join(temporary, 'checkout');
|
|
134
82
|
try {
|
|
135
83
|
const protocolOptions = ['-c', 'protocol.allow=never', '-c', 'protocol.ext.allow=never', ...transports.flatMap(protocol => ['-c', `protocol.${protocol}.allow=always`])];
|
|
84
|
+
const safeConfig = [...protocolOptions, '-c', `core.hooksPath=${path.join(temporary, 'no-hooks')}`];
|
|
85
|
+
const branch = repo.activeBranch;
|
|
136
86
|
try {
|
|
137
|
-
git(home, [...
|
|
87
|
+
git(home, [...safeConfig, 'clone', '--template=', '--no-recurse-submodules', '--no-local', '--origin', source.name, ...(branch === undefined ? [] : ['--no-checkout']), '--', source.url, staged], { timeout: 300_000 });
|
|
138
88
|
} catch (error) {
|
|
139
89
|
fail('CLONE_FAILED', `${error.message} 请核对主远端可达性和新机凭据。`);
|
|
140
90
|
}
|
|
91
|
+
if (branch !== undefined) {
|
|
92
|
+
// Select an exact fetched branch, never a tag or a remote's HEAD alias.
|
|
93
|
+
const remoteRef = `refs/remotes/${source.name}/${branch}`;
|
|
94
|
+
if (git(staged, ['show-ref', '--verify', '--quiet', '--', remoteRef], { accept: [0, 1] }).status !== 0) {
|
|
95
|
+
fail('REMOTE_BRANCH_MISSING', `主远端未提供记录的分支 ${branch};不回退到默认分支或同名标签。`);
|
|
96
|
+
}
|
|
97
|
+
git(staged, [...safeConfig, 'checkout', '--no-recurse-submodules', '--track', '-B', branch, remoteRef]);
|
|
98
|
+
}
|
|
141
99
|
configureRemotes(staged, repo, source.name);
|
|
142
|
-
const checkout = inspectCheckout(
|
|
100
|
+
const checkout = inspectCheckout(runRoute, repo, staged, true);
|
|
101
|
+
if (branch !== undefined && !checkout.branchMatches) fail('BRANCH_MISMATCH', '新 checkout 未检出记录的分支。');
|
|
143
102
|
if (!checkout.head) fail('MISSING_REMOTE_HEAD', '主远端没有可检出的默认分支提交。');
|
|
144
103
|
if (checkout.remoteDrift.length) fail('REMOTE_CONFIG_CONFLICT', '新 checkout 的完整 remote 配置与登记不同。');
|
|
145
|
-
|
|
146
|
-
if (current.registryRevision !== state.registryRevision || current.localText !== state.localText) fail('STALE_REGISTRY', '恢复期间登记或本机路径已变化,请重新预览。');
|
|
104
|
+
assertCheckoutState(home, state);
|
|
147
105
|
assertDestination(home, target);
|
|
148
106
|
if (entry(target)) fail('PATH_CONFLICT', '下载期间目标路径已被占用。');
|
|
149
107
|
if (!inside(parent, staged) || !inside(parent, target)) fail('PATH_CONFLICT', '恢复路径超出目标父目录。');
|
|
150
108
|
publish(staged, target);
|
|
151
|
-
return inspectCheckout(
|
|
109
|
+
return inspectCheckout(runRoute, repo, target);
|
|
152
110
|
} finally {
|
|
153
111
|
const stat = entry(temporary);
|
|
154
112
|
if (stat?.isDirectory() && inside(parent, fs.realpathSync.native(temporary))) fs.rmSync(temporary, { recursive: true, force: true });
|
|
@@ -158,13 +116,15 @@ function cloneProject(home, repo, target, source, state) {
|
|
|
158
116
|
export function restore(home, { apply = false, ids = [] } = {}) {
|
|
159
117
|
home = homeRoot(home);
|
|
160
118
|
if (gitRoot(home) !== home) fail('MISSING_HOME_GIT', '请从已建立的 Home Git 工作树执行恢复。');
|
|
161
|
-
const state =
|
|
162
|
-
const targets = state.registry.repos.map(repo => ({ repo, target:
|
|
119
|
+
const state = readCheckoutState(home);
|
|
120
|
+
const targets = state.registry.repos.map(repo => ({ repo, target: checkoutTarget(home, repo, state) }));
|
|
121
|
+
let runner;
|
|
122
|
+
const runRoute = args => (runner ??= routeRunner(home))(args);
|
|
163
123
|
if (ids.some(id => !targets.some(({ repo }) => repo.id === id))) fail('UNKNOWN_REPO', '请求包含未登记的 repo ID。');
|
|
164
124
|
const projects = [];
|
|
165
125
|
for (const { repo, target } of targets) {
|
|
166
126
|
if (ids.length && !ids.includes(repo.id)) continue;
|
|
167
|
-
const project = { id: repo.id, target };
|
|
127
|
+
const project = { id: repo.id, target, ...(Object.hasOwn(repo, 'activeBranch') ? { requestedBranch: repo.activeBranch } : {}) };
|
|
168
128
|
try {
|
|
169
129
|
if (targets.some(other => other.repo.id !== repo.id && (inside(target, other.target) || inside(other.target, target)))) fail('PATH_CONFLICT', '目标与另一个登记项目路径重叠。');
|
|
170
130
|
assertDestination(home, target);
|
|
@@ -172,12 +132,13 @@ export function restore(home, { apply = false, ids = [] } = {}) {
|
|
|
172
132
|
if (stat) {
|
|
173
133
|
const marker = stat.isDirectory() && entry(path.join(target, '.git'));
|
|
174
134
|
if (!marker || !(marker.isDirectory() || marker.isFile())) fail('PATH_CONFLICT', '目标已存在且不是可复用的独立 checkout。');
|
|
175
|
-
Object.assign(project, { status: 'reused', ...inspectCheckout(
|
|
135
|
+
Object.assign(project, { status: 'reused', ...inspectCheckout(runRoute, repo, target) });
|
|
176
136
|
} else {
|
|
177
137
|
const source = remoteConfig(repo);
|
|
178
138
|
if (!source) fail('LOCAL_ONLY', '项目仅存于旧机器,需要独立迁移其 Git 数据。');
|
|
179
|
-
|
|
180
|
-
|
|
139
|
+
if (repo.activeBranch === null) fail('NO_RECORDED_BRANCH', '记录显示旧机没有可恢复的已提交分支;先由项目 owner 核实再恢复。');
|
|
140
|
+
checkRemote(home, source, repo, runRoute);
|
|
141
|
+
Object.assign(project, apply ? { status: 'cloned', ...cloneProject(home, repo, target, source, state, runRoute) } : { status: 'planned' });
|
|
181
142
|
}
|
|
182
143
|
} catch (error) {
|
|
183
144
|
Object.assign(project, { status: 'blocked', code: error.code || 'IO_FAILED', message: error.message });
|
|
@@ -190,7 +151,7 @@ export function restore(home, { apply = false, ids = [] } = {}) {
|
|
|
190
151
|
export function main(argv = process.argv.slice(2)) {
|
|
191
152
|
try {
|
|
192
153
|
if (!argv.length || (argv.length === 1 && argv[0] === '--help')) {
|
|
193
|
-
console.log('restore.mjs --home HOME [--repo ID ...] [--apply]\n默认只预览;--apply
|
|
154
|
+
console.log('restore.mjs --home HOME [--repo ID ...] [--apply]\n默认只预览;--apply 按登记分支克隆缺失项目,已匹配的 checkout 原地复用、不切分支。');
|
|
194
155
|
return 0;
|
|
195
156
|
}
|
|
196
157
|
let home, apply = false;
|
|
@@ -7,6 +7,8 @@ description: 从 Home 向一个或多个已登记项目派发工作、查询项
|
|
|
7
7
|
|
|
8
8
|
完成用户的当前目标,保留已有决定、授权、实际目录与证据。Home 保存项目基本背景、定位、项目管理和跨项目知识;项目内部知识、SKILL、源码和运行材料由项目当地 Agent 获取与维护。
|
|
9
9
|
|
|
10
|
+
已授权的项目变更日志可由当前执行者按项目规则读取冻结区间的 Git 证据。由 `home-project-changelog` 负责正式日志和游标。
|
|
11
|
+
|
|
10
12
|
主入口已在当前上下文读取且 Home 根和版本相同时可复用;新会话、压缩后缺失、入口更新或换根时重读。入口读不到先核对根、路径和安装状态,再调用可用的 `home-doctor`;未装该技能仍可做最小只读检查,继续不依赖缺项的工作。
|
|
11
13
|
|
|
12
14
|
## 按意图选择方法
|
|
@@ -17,6 +19,7 @@ description: 从 Home 向一个或多个已登记项目派发工作、查询项
|
|
|
17
19
|
| 确认 repo ID、实际 checkout、身份或资料入口 | home-route |
|
|
18
20
|
| 查当前背景、长期决定,整理入口、知识或合作风格 | home-knowledge |
|
|
19
21
|
| 查过去事件、会话摘要、当时理由或接续线索 | home-history |
|
|
22
|
+
| 查看或按 Git 提交范围更新已登记项目的变更日志 | home-project-changelog |
|
|
20
23
|
| 管理派发消息、回复、占用和状态,查询任务或重建视图 | home-tasks |
|
|
21
24
|
| 确认项目关系、契约 owner 和影响集合 | home-map |
|
|
22
25
|
| 验证多个项目共同工作的版本组合 | home-integrate |
|
|
@@ -27,6 +27,8 @@ Home 的默认只约束 Home 发起的直接任务。A/B 进入自己的项目
|
|
|
27
27
|
|
|
28
28
|
先用 `home-route` 确认 repo ID、身份和实际 checkout。Home 自己的协调根不是代码 cwd;项目基本背景可以从 Home 提供,项目内部细节要让当地 Agent 调查。
|
|
29
29
|
|
|
30
|
+
用户授权更新 Home Git 变更日志时,`home-project-changelog` 可由当前执行者逐项目只读采集,也可使用已有方式派遣。取证前核对实际 cwd、登记身份、项目规则、占用与冻结节点。读取本区间所需的 Git 元数据和差异,正式产物写入 Home。发生真实派遣时沿用本节的任务、占用和回执规则。
|
|
31
|
+
|
|
30
32
|
使用[项目任务简报](../assets/project-brief.md),按实际规模保留这些内容:
|
|
31
33
|
|
|
32
34
|
- 目标、范围、只读/修改性质与完成条件;已有授权继续适用。
|