@namewta/skills-hub 0.1.47 → 0.1.49

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.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +3 -3
  3. package/package.json +1 -1
  4. package/scripts/persistence/home.md +1 -0
  5. package/skills/dev/dev-archive/references/change-closure.md +4 -0
  6. package/skills/home/home-project-changelog/SKILL.md +5 -5
  7. package/skills/home/home-project-changelog/assets/project-changelog.md +7 -7
  8. package/skills/home/home-project-changelog/assets/worker-brief.md +1 -1
  9. package/skills/home/home-project-changelog/references/git-ranges.md +3 -0
  10. package/skills/home/home-project-changelog/references/tools.md +20 -2
  11. package/skills/home/home-project-changelog/references/workflow.md +5 -2
  12. package/skills/home/home-project-changelog/references/writing.md +20 -2
  13. package/skills/home/home-project-changelog/scripts/changelog.mjs +47 -5
  14. package/skills/home/home-project-changelog/scripts/contract.mjs +46 -2
  15. package/skills/home/home-project-changelog/scripts/git.mjs +15 -0
  16. package/skills/home/home-project-changelog/scripts/revision.mjs +231 -0
  17. package/skills/home/home-project-changelog/scripts/storage.mjs +32 -8
  18. package/skills/home/home-project-changelog/scripts/summary.mjs +17 -3
  19. package/skills/home/home-project-changelog/scripts/tasks.mjs +40 -0
  20. package/skills/home/home-setup/SKILL.md +1 -1
  21. package/skills/home/home-setup/references/registry.md +4 -0
  22. package/skills/home/home-setup/scripts/git.mjs +2 -0
  23. package/skills/home/home-website/SKILL.md +20 -0
  24. package/skills/home/home-website/assets/website/gitignore.tmpl +4 -0
  25. package/skills/home/home-website/assets/website/package-lock.json +2376 -0
  26. package/skills/home/home-website/assets/website/package.json +11 -0
  27. package/skills/home/home-website/assets/website/scripts/artifact.mjs +84 -0
  28. package/skills/home/home-website/assets/website/scripts/inputs.mjs +251 -0
  29. package/skills/home/home-website/assets/website/scripts/preview.mjs +50 -0
  30. package/skills/home/home-website/assets/website/scripts/render.mjs +97 -0
  31. package/skills/home/home-website/assets/website/scripts/site.mjs +173 -0
  32. package/skills/home/home-website/assets/website/site/.vitepress/theme/index.js +3 -0
  33. package/skills/home/home-website/assets/website/site/public/home-assets/app.js +262 -0
  34. package/skills/home/home-website/assets/website/site/public/home-assets/site.css +330 -0
  35. package/skills/home/home-website/assets/website/site/public/home-assets/start.js +7 -0
  36. package/skills/home/home-website/assets/website/site/templates/layout.mjs +93 -0
  37. package/skills/home/home-website/assets/website/site/templates/ledger.mjs +69 -0
  38. package/skills/home/home-website/assets/website/site/templates/model.mjs +104 -0
  39. package/skills/home/home-website/assets/website/site/templates/pages.mjs +75 -0
  40. package/skills/home/home-website/assets/website/site/templates/project-logs.mjs +130 -0
  41. package/skills/home/home-website/assets/website/site.config.json +6 -0
  42. package/skills/home/home-website/references/website.md +82 -0
  43. package/skills/home/home-website/scripts/init.mjs +57 -0
  44. package/skills/home/home-workflow/SKILL.md +1 -0
@@ -0,0 +1,231 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import {
3
+ categories, dateAt, documentStamp, isDigest, requireThat, revisionOf,
4
+ } from './contract.mjs';
5
+ import { firstCommitAt, listCommits, point, shallowBoundaries } from './git.mjs';
6
+ import { section } from './summary.mjs';
7
+ import { commitCalendar } from './tasks.mjs';
8
+
9
+ export function revisionSnapshot(view, frozen, git, rangeId) {
10
+ requireThat(!view.project?.pending, 'PENDING', '该项目存在待恢复写入,先执行 recover。');
11
+ requireThat(isDigest(rangeId), 'ARGUMENT', '提供完整的成功区间 ID。');
12
+ const record = view.project?.ranges.find(range => range.rangeId === rangeId);
13
+ requireThat(record, 'RANGE_NOT_FOUND', '项目中没有该成功区间。');
14
+ requireThat(view.document !== null, 'DOCUMENT_MISSING', '成功记录对应的 Markdown 丢失,先恢复正文。');
15
+ requireThat(record.sourceIdentity === frozen.binding.sourceIdentity, 'SOURCE_CHANGED', '当前已核实的项目来源与历史区间不同。');
16
+ for (const saved of [record.from, record.to].filter(Boolean)) {
17
+ requireThat(isDeepStrictEqual(saved, point(git, saved.commit, saved.observedAt)), 'GIT_RANGE_CHANGED', '历史提交与成功记录不同。');
18
+ }
19
+ const commits = record.coverage === 'complete'
20
+ ? listCommits(git, record.from?.commit, record.to.commit, shallowBoundaries(git)) : [];
21
+ const historyStart = record.kind === 'full-history' ? firstCommitAt(git, record.to.commit) : null;
22
+ requireThat(commits.length === record.stats.rangeCommitCount && (!record.firstCommitAt || historyStart === record.firstCommitAt),
23
+ 'GIT_RANGE_CHANGED', '历史区间的提交数或首提交已变化。');
24
+ if (record.ledger) {
25
+ const { days, commitMonths } = commitCalendar(git, record, commits);
26
+ requireThat(isDeepStrictEqual(commitMonths, record.ledger.commitMonths)
27
+ && record.ledger.tasks.every(task => days.get(task.deliveredBy) === task.date && task.commits.every(commit => days.has(commit))),
28
+ 'GIT_RANGE_CHANGED', '任务证据与历史区间的提交或日期不同。');
29
+ }
30
+ return {
31
+ status: 'ready', purpose: 'revision', repoId: frozen.repoId, record, commits, frozen, historyStart,
32
+ expected: { projectRevision: revisionOf(view.project), document: documentStamp(view.document) },
33
+ };
34
+ }
35
+
36
+ const titleFor = record => section(record, []).split('\n', 1)[0];
37
+ const emptyNotice = '本次没有需单列的变更。';
38
+ const failDocument = () => requireThat(false, 'DOCUMENT_FORMAT', '无法唯一识别历史区间的生成内容,保留 Markdown 和成功记录。');
39
+
40
+ function markdownLines(text) {
41
+ let fence = null;
42
+ let comment = false;
43
+ const frontmatter = text.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/u)?.[0].length ?? 0;
44
+ return [...text.matchAll(/([^\r\n]*)(\r\n|\n|\r|$)/gu)].filter(match => match[0]).map(match => {
45
+ const [, content, newline] = match;
46
+ const line = { content, newline, start: match.index, end: match.index + match[0].length };
47
+ if (match.index < frontmatter) return { ...line, visible: false };
48
+ if (!fence && (comment || /^ {0,3}<!--/u.test(content))) {
49
+ comment = !content.includes('-->');
50
+ return { ...line, visible: false };
51
+ }
52
+ const delimiter = content.match(/^ {0,3}(`{3,}|~{3,})(.*)$/u);
53
+ const visible = fence === null && delimiter === null;
54
+ if (delimiter) {
55
+ const [, token, rest] = delimiter;
56
+ if (!fence) fence = token;
57
+ else if (fence[0] === token[0] && token.length >= fence.length && !rest.trim()) fence = null;
58
+ }
59
+ return { ...line, visible };
60
+ });
61
+ }
62
+
63
+ function tableAt(lines, index, headers) {
64
+ const signatures = [headers, headers.map((header, offset) => `${header} ${offset ? '---:' : '新增'} |`)];
65
+ const signature = signatures.find(pair => pair.every((header, offset) => lines[index + offset]?.visible && lines[index + offset].content === header));
66
+ if (!signature) return null;
67
+ const row = lines[index + headers.length];
68
+ if (!row?.visible || !row.content.startsWith('|') || !row.content.endsWith('|')) return null;
69
+ const cells = row.content.slice(1,-1).split('|').map(value => value.trim());
70
+ if (!cells.every(value => /^(?:\d+|\d{1,3}(?:,\d{3})+)$/u.test(value))) return null;
71
+ const values = cells.map(value => Number(value.replaceAll(',', '')));
72
+ const commitIndex = categories.length + 1;
73
+ if (values.length !== signature[0].split('|').length - 2 || !values.every(Number.isSafeInteger)
74
+ || values[0] !== values.slice(1, commitIndex).reduce((sum, value) => sum + value, 0)
75
+ || values[commitIndex + 1] > values[1]) return null;
76
+ return { index, end: index + headers.length, values, row };
77
+ }
78
+
79
+ function parseGenerated(record, entries) {
80
+ const lines = section(record, entries).split('\n');
81
+ const tableIndex = lines.findIndex(line => line.startsWith('| '));
82
+ const groups = new Map();
83
+ let category;
84
+ for (const content of lines.slice(tableIndex + 3)) {
85
+ if (content.startsWith('### ')) {
86
+ category = content.slice(4);
87
+ groups.set(category, []);
88
+ } else if (content.startsWith('- ')) groups.get(category).push(content);
89
+ }
90
+ return { headers: lines.slice(tableIndex, tableIndex + 2), row: lines[tableIndex + 2], groups };
91
+ }
92
+
93
+ function locateRanges(lines, ranges, oldRecord, upgraded, headers) {
94
+ const headings = lines.flatMap((line, index) => line.visible && /^ {0,3}#{1,2}(?:\s|$)/u.test(line.content) ? [index] : []);
95
+ const blocks = headings.flatMap((index, order) => {
96
+ const end = headings[order + 1] ?? lines.length;
97
+ const title = lines[index].content;
98
+ if (!/^## \d{4}-\d{2}-\d{2}(?: 至 \d{4}-\d{2}-\d{2})?$/u.test(title)) return [];
99
+ const tables = [];
100
+ for (let position = index + 1; position < end - 2; position++) {
101
+ const table = tableAt(lines, position, headers);
102
+ if (table) tables.push(table);
103
+ }
104
+ return tables.length ? [{ index, end, title, tables }] : [];
105
+ });
106
+ function matches(block, range) {
107
+ const legacy = range.kind === 'full-history' && !range.firstCommitAt;
108
+ const isTarget = range.rangeId === oldRecord.rangeId;
109
+ const legacyTitle = legacy && (isTarget ? block.title === titleFor(upgraded)
110
+ : block.title.endsWith(` 至 ${range.displayDates.to}`));
111
+ return (block.title === titleFor(range) || legacyTitle) && block.tables.length === 1
112
+ && block.tables[0].values[categories.length + 1] === range.stats.rangeCommitCount;
113
+ }
114
+ // Both directions must select the same block. Unrelated hand-written ranges may sit between saved ones.
115
+ function locate(records, candidates) {
116
+ let position = 0;
117
+ for (const range of records) {
118
+ while (position < candidates.length && !matches(candidates[position], range)) position++;
119
+ if (position === candidates.length) failDocument();
120
+ if (range.rangeId === oldRecord.rangeId) return candidates[position];
121
+ position++;
122
+ }
123
+ failDocument();
124
+ }
125
+ const earliest = locate(ranges, [...blocks].reverse());
126
+ const latest = locate([...ranges].reverse(), blocks);
127
+ if (earliest !== latest) failDocument();
128
+ return { ...earliest, table: earliest.tables[0] };
129
+ }
130
+
131
+ export function rewriteRange(before, ranges, oldRecord, record) {
132
+ let text;
133
+ try { text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(before); }
134
+ catch { failDocument(); }
135
+ const bom = text.startsWith('\uFEFF') ? '\uFEFF' : '';
136
+ text = text.slice(bom.length);
137
+ const lines = markdownLines(text);
138
+ const old = parseGenerated(oldRecord, oldRecord.ledger?.tasks ?? []);
139
+ const next = parseGenerated(record, record.ledger.tasks);
140
+ const target = locateRanges(lines, ranges, oldRecord, record, parseGenerated(oldRecord, []).headers);
141
+ const table = target.table;
142
+ const newline = table.row.newline || lines[target.index].newline || '\n';
143
+ const edits = [];
144
+ const replaceLine = (line, replacement) => edits.push({ start: line.start, end: line.end,
145
+ value: replacement === null ? '' : `${replacement}${line.newline}` });
146
+ const insertAfter = (line, contents) => edits.push({ start: line.end, end: line.end,
147
+ value: `${line.newline ? '' : newline}${newline}${contents.join(newline)}${newline}` });
148
+ if (lines[target.index].content !== titleFor(record)) replaceLine(lines[target.index], titleFor(record));
149
+ for (const [offset, content] of next.headers.entries()) {
150
+ const line = lines[table.index + offset];
151
+ if (line.content !== content) replaceLine(line, content);
152
+ }
153
+ if (table.row.content !== next.row) replaceLine(table.row, next.row);
154
+
155
+ const groups = new Map();
156
+ const notices = [];
157
+ let group;
158
+ for (const line of lines.slice(table.end + 1, target.end)) {
159
+ if (!line.visible) continue;
160
+ const heading = line.content.match(/^ {0,3}#{3,6}(?:\s|$)/u);
161
+ if (heading) {
162
+ const category = line.content.startsWith('### ') ? line.content.slice(4) : null;
163
+ group = null;
164
+ if (categories.includes(category)) {
165
+ if (groups.has(category)) failDocument();
166
+ group = { heading: line, bullets: [] };
167
+ groups.set(category, group);
168
+ }
169
+ } else if (line.content === emptyNotice) notices.push(line);
170
+ else if (group && line.content.startsWith('- ')) group.bullets.push(line);
171
+ }
172
+
173
+ let insertion = table.row;
174
+ for (const [index, category] of categories.entries()) {
175
+ const group = groups.get(category);
176
+ const count = table.values[index + 1];
177
+ // The ledger identifies generated lines exactly. Legacy sections only supply their category counts.
178
+ const generated = oldRecord.ledger ? group?.bullets.filter(line => old.groups.get(category)?.includes(line.content)) ?? []
179
+ : count ? group?.bullets ?? [] : [];
180
+ if (generated.length !== count || oldRecord.ledger && !isDeepStrictEqual(generated.map(line => line.content), old.groups.get(category) ?? [])) failDocument();
181
+ if (oldRecord.ledger && group?.bullets.some(line => /^- \d{4}-\d{2}-\d{2} · .* · /u.test(line.content) && !generated.includes(line))) failDocument();
182
+ if (group && group.heading.start < insertion.start) failDocument();
183
+ const replacements = next.groups.get(category) ?? [];
184
+ if (!group && replacements.length) {
185
+ insertAfter(insertion, [`### ${category}`, '', ...replacements]);
186
+ continue;
187
+ }
188
+ if (!group) continue;
189
+ for (const [slot, line] of generated.entries()) {
190
+ if (replacements[slot] !== line.content) replaceLine(line, replacements[slot] ?? null);
191
+ }
192
+ insertion = generated.at(-1) ?? group.heading;
193
+ if (replacements.length > generated.length) {
194
+ const extra = replacements.slice(generated.length);
195
+ if (generated.length && insertion.newline) {
196
+ edits.push({ start: insertion.end, end: insertion.end, value: `${extra.join(newline)}${newline}` });
197
+ } else insertAfter(insertion, extra);
198
+ }
199
+ if (count && replacements.length === 0) {
200
+ const following = lines.slice(lines.indexOf(group.heading) + 1, target.end);
201
+ const attached = following.findIndex(line => line.visible && /^ {0,3}#{3,6}(?:\s|$)/u.test(line.content));
202
+ const body = following.slice(0, attached === -1 ? following.length : attached);
203
+ if (body.every(line => !line.content.trim() || generated.includes(line))) replaceLine(group.heading, null);
204
+ }
205
+ }
206
+ const hadNotice = oldRecord.coverage === 'complete' && table.values[0] === 0;
207
+ const needsNotice = record.coverage === 'complete' && record.ledger.tasks.length === 0;
208
+ if (hadNotice && notices.length !== 1) failDocument();
209
+ if (hadNotice && !needsNotice) replaceLine(notices[0], null);
210
+ if (!hadNotice && needsNotice) {
211
+ if (notices.length) failDocument();
212
+ insertAfter(insertion, [emptyNotice]);
213
+ }
214
+ edits.sort((a, b) => a.start - b.start || a.end - b.end);
215
+ // Keep all bytes outside the original generated lines and the insertion points.
216
+ let cursor = 0;
217
+ const chunks = [bom];
218
+ for (const edit of edits) {
219
+ if (edit.start < cursor) failDocument();
220
+ chunks.push(text.slice(cursor, edit.start), edit.value);
221
+ cursor = edit.end;
222
+ }
223
+ chunks.push(text.slice(cursor));
224
+ return Buffer.from(chunks.join(''));
225
+ }
226
+
227
+ export function upgradeRange(record, historyStart) {
228
+ if (!historyStart || record.firstCommitAt) return record;
229
+ return { ...record, firstCommitAt: historyStart,
230
+ displayDates: { ...record.displayDates, from: dateAt(historyStart, record.displayDates.timezone) } };
231
+ }
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { randomUUID } from 'node:crypto';
5
+ import { isDeepStrictEqual } from 'node:util';
5
6
  import {
6
7
  documentStamp, expectId, hasOwn, isId, requireThat, revisionOf, sameStamp, validateState,
7
8
  } from './contract.mjs';
@@ -10,6 +11,12 @@ const stateName = 'state.json';
10
11
  const lockName = '.state.lock';
11
12
  const emptyState = () => ({ formatVersion: 1, projects: {} });
12
13
 
14
+ function sameFile(first, second) {
15
+ // Node 22 on Windows may report dev=0 when looking up the same file by path.
16
+ const sameDevice = first.dev === second.dev || process.platform === 'win32' && (!first.dev || !second.dev);
17
+ return first.ino === second.ino && sameDevice;
18
+ }
19
+
13
20
  export function openStore(home, filesystem = fs) {
14
21
  requireThat(typeof home === 'string' && home.length > 0, 'ARGUMENT', '显式传入 Home 根目录。');
15
22
  const requested = path.resolve(home);
@@ -49,11 +56,11 @@ export function openStore(home, filesystem = fs) {
49
56
  const fd = filesystem.openSync(target, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
50
57
  try {
51
58
  const opened = filesystem.fstatSync(fd);
52
- requireThat(opened.isFile() && opened.ino === entry.ino && opened.dev === entry.dev,
59
+ requireThat(opened.isFile() && sameFile(opened, entry),
53
60
  'UNSAFE_PATH', `${name} 已被替换。`);
54
61
  const bytes = filesystem.readFileSync(fd);
55
62
  const current = filename(name) === target && info(target);
56
- requireThat(current && !current.isSymbolicLink() && current.ino === opened.ino && current.dev === opened.dev,
63
+ requireThat(current?.isFile() && sameFile(current, opened),
57
64
  'READ_CONFLICT', `${name} 在读取期间发生变化。`);
58
65
  return bytes;
59
66
  } finally { filesystem.closeSync(fd); }
@@ -132,36 +139,53 @@ export function openStore(home, filesystem = fs) {
132
139
  function confirm(id, state, stateBytes, project, record) {
133
140
  const { pending, ...success } = project;
134
141
  const saved = { ...record, savedAt: new Date().toISOString() };
135
- const next = { ...success, ranges: [...success.ranges, saved], lastSuccessfulRangeId: saved.rangeId };
142
+ const ranges = pending.operation === 'revision'
143
+ ? success.ranges.map(range => range.rangeId === saved.rangeId ? saved : range)
144
+ : [...success.ranges, saved];
145
+ const next = { ...success, ranges, lastSuccessfulRangeId: ranges.at(-1).rangeId };
136
146
  const hasExpectedDocument = () => requireThat(sameStamp(documentStamp(read(documentName(id))), pending.afterDocument),
137
147
  'DOCUMENT_CHANGED', 'Markdown 在最终确认前已变化,保留 pending。');
138
148
  saveState({ ...state, projects: { ...state.projects, [id]: next } }, stateBytes, hasExpectedDocument);
139
149
  const result = view(id);
140
- requireThat(result.previous?.rangeId === saved.rangeId && !result.project.pending
150
+ const persisted = result.project?.ranges.find(range => range.rangeId === saved.rangeId);
151
+ requireThat(isDeepStrictEqual(persisted, saved) && !result.project.pending
141
152
  && sameStamp(documentStamp(result.document), pending.afterDocument), 'READ_CONFLICT', '成功记录或 Markdown 回读不一致。');
142
- return result.previous;
153
+ return persisted;
143
154
  }
144
155
 
145
- function commit(id, expected, record, document) {
156
+ function commit(id, expected, record, document, { revision = false } = {}) {
146
157
  return withLock(() => {
147
158
  const current = view(id);
148
159
  requireThat(!current.project?.pending, 'PENDING', '该项目存在待恢复写入,先执行 recover。');
149
- if (current.previous?.rangeId === record.rangeId) {
160
+ const prior = current.project?.ranges.find(range => range.rangeId === record.rangeId);
161
+ if (revision && prior && prior.revisionRequest === record.revisionRequest
162
+ && sameStamp(documentStamp(current.document), documentStamp(document))) {
163
+ return { status: 'already-saved', record: prior };
164
+ }
165
+ if (!revision && current.previous?.rangeId === record.rangeId) {
150
166
  requireThat(current.document !== null, 'DOCUMENT_MISSING', '成功记录对应的 Markdown 丢失,先恢复正文。');
151
167
  return { status: 'already-saved', record: current.previous };
152
168
  }
153
169
  requireThat(revisionOf(current.project) === expected.projectRevision
154
170
  && sameStamp(documentStamp(current.document), expected.document), 'STALE_CANDIDATE', '项目状态或 Markdown 已变化,重读后重新生成。');
171
+ if (revision && prior && prior.firstCommitAt === record.firstCommitAt
172
+ && isDeepStrictEqual(prior.displayDates, record.displayDates) && isDeepStrictEqual(prior.ledger, record.ledger)
173
+ && sameStamp(expected.document, documentStamp(document))) {
174
+ return { status: 'already-saved', record: prior };
175
+ }
155
176
  const pending = {
156
177
  transactionId: randomUUID(), rangeId: record.rangeId, expectedProjectRevision: expected.projectRevision,
157
178
  beforeDocument: expected.document, afterDocument: documentStamp(document), nextRecord: record,
179
+ ...(revision ? { operation: 'revision' } : {}),
158
180
  };
159
181
  const project = {
160
182
  ...(current.project ?? { initialization: record.initialization, ranges: [], lastSuccessfulRangeId: null }), pending,
161
183
  };
162
184
  const state = { ...current.state, projects: { ...current.state.projects, [id]: project } };
163
185
  const intentBytes = saveState(state, current.stateBytes);
164
- replace(documentName(id), document, pending.beforeDocument, 'DOCUMENT_CHANGED');
186
+ if (!sameStamp(pending.beforeDocument, pending.afterDocument)) {
187
+ replace(documentName(id), document, pending.beforeDocument, 'DOCUMENT_CHANGED');
188
+ }
165
189
  requireThat(sameStamp(documentStamp(read(documentName(id))), pending.afterDocument), 'DOCUMENT_CHANGED', 'Markdown 写入回读不一致,保留 pending。');
166
190
  return { status: 'saved', record: confirm(id, state, intentBytes, project, record) };
167
191
  });
@@ -27,11 +27,19 @@ export function candidateEntries(candidate, snapshot, git) {
27
27
  requireThat(!commits.length || candidate.entries.length > 0 || candidate.noSignificantChanges === true,
28
28
  'CANDIDATE', '没有需单列的变更时,在候选中确认已复核范围。');
29
29
  for (const entry of candidate.entries) {
30
- expectKeys(entry, ['category', 'text', 'commits', 'markers', 'relatedCommits'], 'CANDIDATE', '条目需提供分类、描述和主要证据。');
30
+ expectKeys(entry, ['category', 'area', 'text', 'commits', 'deliveredBy', 'markers', 'relatedCommits', 'added'],
31
+ 'CANDIDATE', '条目需提供分类、描述和主要证据。');
31
32
  requireThat(categories.includes(entry.category) && displayLine(entry.text),
32
33
  'DISPLAY', '条目使用精简分类和单行描述,证据身份单独提供。');
33
34
  requireThat(Array.isArray(entry.commits) && entry.commits.length > 0 && entry.commits.every(oid => wanted.has(oid)),
34
35
  'COVERAGE', '条目的主要证据须在冻结范围内。');
36
+ requireThat((entry.deliveredBy !== undefined || !entry.area || entry.commits.length === 1)
37
+ && (entry.deliveredBy === undefined || entry.commits.includes(entry.deliveredBy)),
38
+ 'COVERAGE', '任务完成节点须属于该条目的主要证据。');
39
+ requireThat(entry.area === undefined || displayLine(entry.area) && entry.area.trim() !== '—' && !/[·*`]/u.test(entry.area),
40
+ 'DISPLAY', '模块使用可公开的单行名称,避开 Markdown 标记和中点分隔符。');
41
+ requireThat(entry.added === undefined || entry.category === '功能' && typeof entry.added === 'boolean',
42
+ 'CANDIDATE', '仅功能条目可标明是否新增能力。');
35
43
  requireThat(entry.markers === undefined || Array.isArray(entry.markers) && entry.markers.every(marker => markers.includes(marker)),
36
44
  'DISPLAY', '使用已定义的影响标识。');
37
45
  requireThat(entry.relatedCommits === undefined || Array.isArray(entry.relatedCommits)
@@ -45,7 +53,7 @@ function oneLine(text) {
45
53
  return text.trim().replace(/[[\]]/gu, '\\$&');
46
54
  }
47
55
 
48
- function section(record, entries) {
56
+ export function section(record, entries) {
49
57
  const { displayDates: { from, to }, kind, stats } = record;
50
58
  const parts = [`## ${from ? `${from} 至 ${to}` : to}`];
51
59
  if (kind === 'delta') {
@@ -60,6 +68,11 @@ function section(record, entries) {
60
68
  for (const entry of entries) byCategory.get(entry.category).push(entry);
61
69
  const columns = ['变更总数', ...categories, '本次提交'];
62
70
  const counts = [entries.length, ...categories.map(category => byCategory.get(category).length), stats.rangeCommitCount];
71
+ const features = byCategory.get('功能');
72
+ if (features.length && features.every(entry => typeof entry.added === 'boolean')) {
73
+ columns.push('新增');
74
+ counts.push(features.filter(entry => entry.added).length);
75
+ }
63
76
  const row = cells => `| ${cells.join(' | ')} |`;
64
77
  parts.push([
65
78
  row(columns),
@@ -69,7 +82,8 @@ function section(record, entries) {
69
82
  for (const [category, group] of byCategory) {
70
83
  const items = group.map(entry => {
71
84
  const impacts = [...new Set(entry.markers)].map(marker => `**[${marker}]**`).join(' ');
72
- return `- ${impacts ? `${impacts} ` : ''}${oneLine(entry.text)}`;
85
+ const source = entry.date ? `${entry.date} · ${entry.area ? oneLine(entry.area) : '—'} · ` : '';
86
+ return `- ${source}${impacts ? `${impacts} ` : ''}${oneLine(entry.text)}`;
73
87
  });
74
88
  if (items.length) parts.push(`### ${category}`, items.join('\n'));
75
89
  }
@@ -0,0 +1,40 @@
1
+ import { categories, dateAt, digest, requireThat } from './contract.mjs';
2
+ import { commitDates } from './git.mjs';
3
+
4
+ export function commitCalendar(git, record, commits) {
5
+ const times = commitDates(git, record);
6
+ requireThat(times.size === commits.length && commits.every(oid => times.has(oid)), 'COVERAGE', '日期证据与冻结提交集合不一致。');
7
+ const days = new Map();
8
+ const commitMonths = {};
9
+ for (const [oid, time] of times) {
10
+ const day = dateAt(time, record.displayDates.timezone);
11
+ days.set(oid, day);
12
+ const month = day.slice(0, 7);
13
+ commitMonths[month] = (commitMonths[month] ?? 0) + 1;
14
+ }
15
+ return { days, commitMonths };
16
+ }
17
+
18
+ export function taskLedger({ repoId, record, commits }, entries, git) {
19
+ const { days, commitMonths } = commitCalendar(git, record, commits);
20
+ const ids = new Set();
21
+ const tasks = entries.map(entry => {
22
+ // For a result with several supporting commits the writer identifies the one that delivers it.
23
+ const deliveredBy = entry.deliveredBy ?? entry.commits[0];
24
+ const area = entry.area?.trim() || null;
25
+ const text = entry.text.trim();
26
+ const identity = [repoId, record.rangeId, entry.category, area, text];
27
+ const id = 'task-' + digest(JSON.stringify(identity)).slice(0, 16);
28
+ requireThat(!ids.has(id), 'CANDIDATE', '同一区间有重复的模块、类别和任务描述:' + text);
29
+ ids.add(id);
30
+ return {
31
+ id, category: entry.category, area, text, date: days.get(deliveredBy),
32
+ markers: [...new Set(entry.markers)], commits: [...new Set(entry.commits)], deliveredBy,
33
+ ...(entry.relatedCommits?.length ? { relatedCommits: [...new Set(entry.relatedCommits)] } : {}),
34
+ ...(entry.added !== undefined ? { added: entry.added } : {}),
35
+ };
36
+ });
37
+ tasks.sort((a, b) => categories.indexOf(a.category) - categories.indexOf(b.category) ||
38
+ b.date.localeCompare(a.date) || (a.area ?? '').localeCompare(b.area ?? '', 'zh-CN'));
39
+ return { version: 1, commitMonths, tasks };
40
+ }
@@ -29,7 +29,7 @@ description: 初始化 Home 及其主要入口、给已有 Home 补 Git 或白
29
29
  2. 登记项目时按准确名称调用 `home-route`,核实既有 clone、实际 checkout 与全部 remote。新登记采用 v2,保存名称、完整 URL 列表和明确的主 remote,路径写成 Home 根相对的 `./` 或 `../` 形式;记录经现场核实的 `activeBranch`,供换机恢复。旧 v1 继续读取,改写前按现场核查结果迁移。项目内部知识仍由进入项目的 Agent 读取;不移动仓库、不重新 clone、不切分支。
30
30
  3. 按本次范围维护 Git、登记或 context。完整初始化包含根短入口的合并或复用,保留用户已有规则。领域 AGENTS 缺失时由安装器创建,已有入口的内容编辑归 `home-knowledge`。重新初始化 team 时按当前模板和用户选择重建指定团队,只询问仍待确定的默认派遣方式或 team。仅补 Git、登记、偏好或换机恢复沿用既有入口与配置。
31
31
  4. 将用户的配置意图、现场能力观察和本次实际运行证据分开。CLI、模型、推理设置和派遣技能不设固定候选枚举;未知值不传入工具。
32
- 5. 用包内工具校验、保存,再回读所改字段、路径和作用范围。地图按需从登记生成,显式导出时才保存 `repos.md`。
32
+ 5. 用包内工具校验、保存,再回读所改字段、路径和作用范围。地图按需从登记生成,显式导出时才保存 `repos.md`。完整初始化中用户选用项目展示站时,调用已安装的 home-website;已有展示站的登记改动按[刷新已启用的展示站](references/registry.md#刷新已启用的展示站)收尾。
33
33
  6. 按 Git 分支验证真实仓库根、跟踪状态和随仓技能,或从同仓技能恢复登记项目。初始化时回读根指针与其实际目标,核对当前所选宿主的发现能力;当前运行宿主是已选环境,无须再问品牌。报告文件保存、宿主发现、暂存、提交与项目恢复各自的实际结果。保存配置只表达用户选择,执行时再核对能力。
34
34
 
35
35
  当前 Home 会话是使用 team 的主会话,可直接完成定位、依赖梳理与综合。team 内的模型与推理覆盖只用于直接派出的执行者。需要派遣时,先确定派遣方式,再选择 Home team,最后应用 repo ID 对应的执行者配置与本次覆盖。Home 默认只约束 Home 发出的直接任务,项目再派遣按当地规则,除非用户明确指定全链范围。
@@ -152,3 +152,7 @@ node <本技能目录>/scripts/registry.mjs map --home "<Home 根>" --write --ex
152
152
  相对链接按包含它的文档解析。Home 的规则和资料不会因为根指针而覆盖目标项目的有效指令;项目 Agent 仍在当地读取对应知识与技能。
153
153
 
154
154
  交付登记变更、身份与路径依据、保留的既有资料、未知或冲突项。请求地图时交付本次输出,显式导出时另给文件位置。只查询或验证时零写入;只登记时不安装 CLI、不创建项目 hooks、不启动 Agent。
155
+
156
+ ## 刷新已启用的展示站
157
+
158
+ 登记实际新增、删除或变更后,如果真实 Home 已初始化 `.agents/home/website/`,整批保存并回读后,从 Home 根运行一次 `node .agents/home/website/scripts/site.mjs refresh`。同一请求也更新日志时,两个 owner 共同完成后由当前执行者调用一次。查询、只导出地图及无变化时结束于原步骤。展示站缺依赖或刷新失败时,报告登记已保存和网站待刷新,附同一重试命令。初始化网站和核对公开制品交给 home-website。
@@ -11,6 +11,7 @@ const rules = [
11
11
  '/temp/', '/.agents/**/temp/', '/.agents/**/node_modules/', '/.agents/dev/worktree/',
12
12
  '/.agents/.skills-*-backups/', '/.agents/.skills-*-install.lock/', '/.agents/home/local.json',
13
13
  '/.agents/**/.env', '/.agents/**/.env.*', '/.agents/**/.npmrc', '/.agents/ops/**/env.md',
14
+ '/.agents/home/website/.cache/', '/.agents/home/website/dist/',
14
15
  '/.agents/**/*.log', '/.agents/**/*.log.*', '/.agents/**/*.tmp', '/.agents/**/*.lock',
15
16
  '/.agents/home/**/*.png', '/.agents/home/**/*.jpg', '/.agents/home/**/*.jpeg',
16
17
  '/.agents/home/**/*.mp4', '/.agents/home/**/*.webm', end,
@@ -20,6 +21,7 @@ const noTrack = [
20
21
  /(?:^|\/)(?:temp|node_modules)(?:\/|$)/u,
21
22
  /^\.agents\/(?:dev\/worktree|\.skills-[^/]+-(?:backups|install\.lock))(?:\/|$)/u,
22
23
  /^\.agents\/home\/local\.json$/u,
24
+ /^\.agents\/home\/website\/(?:\.cache|dist)(?:\/|$)/u,
23
25
  /(?:^|\/)\.(?:env(?:\..*)?|npmrc)$/u,
24
26
  /^\.agents\/ops\/(?:.*\/)?env\.md$/u,
25
27
  /(?:\.log(?:\.[^/]*)?|\.tmp|\.lock)(?:\/|$)/u,
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: home-website
3
+ description: 把 Home 中已登记项目的 Git changelog 生成可部署的静态展示站,按项目、月份、模块关键词和类别查看任务及提交统计。用于创建、刷新、预览或部署多项目变更展示,承接 home-project-changelog 已保存的日志。
4
+ ---
5
+
6
+ # Home 项目展示站
7
+
8
+ 先确认实际 Home 根,读取其 `.agents/home/AGENTS.md` 和本次相关设置。按[网站操作](references/website.md)选择入口。只要求查看或定位项目时使用现有 Home 方法。
9
+
10
+ | 要做的事 | 入口 |
11
+ | --- | --- |
12
+ | 显式启用网站或完整初始化时选用网站 | `node <本技能目录>/scripts/init.mjs --home "<实际 Home 根>"`,然后在生成的网站工程安装锁定依赖、构建并预览 |
13
+ | 重新生成最新页面,或接续登记与日志批次 | 从实际 Home 根运行 `node .agents/home/website/scripts/site.mjs refresh` |
14
+ | 浏览已构建的网站 | 打开 `dist/index.html` 离线浏览,或运行 `npm run preview` 并访问输出的 HTTP 地址。按构建回执核对公开项目、条目数、排除项和诊断 |
15
+ | 上次构建中断或启动失败 | 按[修复本地刷新](references/website.md#修复本地刷新)核对进程、恢复已有产物并重试 |
16
+ | 发布到指定目标 | 使用已验证的 `dist/`,按实际托管目标回读线上版本 |
17
+
18
+ 首页突出公开项目、任务及 Git 提交。项目卡直接给出累计提交和任务量,详情与跨仓时间线默认显示每月的任务正文。构建时按登记、成功记录和展示设置选取公开项目,核对结构化任务与 Markdown 后导出 `dist/data/`。[公开字段与统计](references/website.md#公开字段与数据来源) · [更新已有模板](references/website.md#更新已有模板)
19
+
20
+ 任务结束时说明构建状态、地址或制品位置、未纳入的项目和诊断。Home 更新成功但站点待刷新时分别报告,重试网站命令即可。
@@ -0,0 +1,4 @@
1
+ /node_modules/
2
+ /.cache/
3
+ /dist/
4
+ /.refresh.lock/