@namewta/skills-hub 0.1.49 → 0.1.52
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 +4 -1
- package/THIRD_PARTY_NOTICES.md +19 -7
- package/cli.mjs +2 -2
- package/install.mjs +11 -4
- package/package.json +1 -1
- package/scripts/persistence/home.md +1 -1
- package/skills/dev/dev-build/SKILL.md +2 -0
- package/skills/dev/dev-build/references/implement-request.md +7 -2
- package/skills/dev/dev-formal-verify/SKILL.md +2 -1
- package/skills/dev/dev-formal-verify/references/create-check.md +3 -1
- package/skills/dev/dev-formal-verify/references/example.md +1 -1
- package/skills/dev/dev-formal-verify/references/tool-choice.md +1 -1
- package/skills/dev/dev-help/references/capabilities.md +6 -6
- package/skills/dev/dev-help/references/guide-verification.md +7 -1
- package/skills/dev/dev-help/references/help-method.md +7 -1
- package/skills/dev/dev-issue/SKILL.md +1 -0
- package/skills/dev/dev-issue/references/github-operations.md +8 -0
- package/skills/dev/dev-plan/references/plan-template.md +1 -0
- package/skills/dev/dev-plan/references/vertical-slicing.md +2 -0
- package/skills/dev/dev-pr/references/pull-request-evidence.md +2 -0
- package/skills/dev/dev-review/references/host-parity.md +12 -0
- package/skills/dev/dev-review/references/review-baseline.md +2 -0
- package/skills/dev/dev-setup/references/formal-options.md +1 -1
- package/skills/dev/dev-statechart/SKILL.md +17 -19
- package/skills/dev/dev-statechart/agents/openai.yaml +3 -3
- package/skills/dev/dev-statechart/assets/theme.css +135 -0
- package/skills/dev/dev-statechart/references/lean-proof.md +47 -0
- package/skills/dev/dev-statechart/references/render.md +15 -83
- package/skills/dev/dev-statechart/references/runtime.md +21 -1
- package/skills/dev/dev-statechart/scripts/lean/backends/lemma-chart.mjs +285 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/mermaid.mjs +174 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/proof-chart.mjs +540 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/report.mjs +242 -0
- package/skills/dev/dev-statechart/scripts/lean/frontends/facts.mjs +234 -0
- package/skills/dev/dev-statechart/scripts/lean/frontends/view.mjs +217 -0
- package/skills/dev/dev-statechart/scripts/lean/ir.mjs +226 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/attribute.mjs +148 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/blocks.mjs +32 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/budget.mjs +167 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/check.mjs +70 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/contract.mjs +160 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/fold.mjs +206 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/inline.mjs +84 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/mark.mjs +432 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/reduce.mjs +73 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/trust.mjs +111 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/view-lemmas.mjs +155 -0
- package/skills/dev/dev-statechart/scripts/lean/pipeline.mjs +164 -0
- package/skills/dev/dev-statechart/scripts/lean/run.mjs +168 -0
- package/skills/dev/dev-statechart/scripts/statechart.mjs +42 -23
- package/skills/dev/dev-statechart/scripts/worker.mjs +33 -7
- package/skills/dev/dev-ui-design/SKILL.md +2 -2
- package/skills/dev/dev-ui-design/references/interaction-review.md +9 -0
- package/skills/dev/dev-verify/SKILL.md +1 -1
- package/skills/dev/dev-verify/references/evidence-storage.md +12 -0
- package/skills/dev/dev-workflow/SKILL.md +6 -6
- package/skills/dev/dev-workflow/references/method-handoffs.md +7 -1
- package/skills/dev/dev-writing/SKILL.md +2 -0
- package/skills/dev/dev-writing/references/library-docs.md +37 -0
- package/skills/home/home-doctor/references/diagnosis.md +2 -2
- package/skills/home/home-doctor/scripts/doctor.mjs +68 -38
- package/skills/home/home-project-changelog/SKILL.md +7 -7
- package/skills/home/home-project-changelog/assets/project-changelog.example.json +188 -0
- package/skills/home/home-project-changelog/assets/project-changelog.schema.json +156 -0
- package/skills/home/home-project-changelog/assets/worker-brief.md +1 -1
- package/skills/home/home-project-changelog/references/git-ranges.md +2 -2
- package/skills/home/home-project-changelog/references/schema.md +61 -0
- package/skills/home/home-project-changelog/references/tools.md +28 -22
- package/skills/home/home-project-changelog/references/workflow.md +12 -9
- package/skills/home/home-project-changelog/references/writing.md +5 -3
- package/skills/home/home-project-changelog/scripts/changelog.mjs +42 -38
- package/skills/home/home-project-changelog/scripts/contract.mjs +40 -3
- package/skills/home/home-project-changelog/scripts/legacy-markdown.mjs +116 -0
- package/skills/home/home-project-changelog/scripts/migrate.mjs +122 -0
- package/skills/home/home-project-changelog/scripts/revision.mjs +2 -196
- package/skills/home/home-project-changelog/scripts/storage.mjs +120 -125
- package/skills/home/home-project-changelog/scripts/summary.mjs +0 -60
- package/skills/home/home-route/SKILL.md +2 -2
- package/skills/home/home-route/references/routing.md +3 -1
- package/skills/home/home-route/scripts/route.mjs +79 -11
- package/skills/home/home-setup/SKILL.md +2 -1
- package/skills/home/home-setup/assets/repos.schema.json +10 -0
- package/skills/home/home-setup/references/registry.md +18 -1
- package/skills/home/home-setup/scripts/registry.mjs +67 -7
- package/skills/home/home-website/SKILL.md +13 -9
- package/skills/home/home-website/assets/website/scripts/inputs.mjs +143 -128
- package/skills/home/home-website/assets/website/scripts/render.mjs +8 -6
- package/skills/home/home-website/assets/website/scripts/site.mjs +21 -10
- package/skills/home/home-website/assets/website/site/public/home-assets/app.js +81 -34
- package/skills/home/home-website/assets/website/site/public/home-assets/site.css +92 -70
- package/skills/home/home-website/assets/website/site/templates/favicon.png +0 -0
- package/skills/home/home-website/assets/website/site/templates/layout.mjs +13 -10
- package/skills/home/home-website/assets/website/site/templates/ledger.mjs +51 -46
- package/skills/home/home-website/assets/website/site/templates/model.mjs +58 -14
- package/skills/home/home-website/assets/website/site/templates/pages.mjs +28 -30
- package/skills/home/home-website/assets/website/site/templates/project-logs.mjs +3 -107
- package/skills/home/home-website/assets/website/site.config.json +1 -1
- package/skills/home/home-website/references/website.md +64 -46
- package/skills/home/home-website/scripts/activate.mjs +106 -0
- package/skills/home/home-website/scripts/init.mjs +98 -11
- package/skills/home/home-workflow/SKILL.md +6 -4
- package/skills/system/system-clash-proxy-config/SKILL.md +21 -0
- package/skills/system/system-clash-proxy-config/agents/openai.yaml +4 -0
- package/skills/system/system-clash-proxy-config/assets/clash-override.js +328 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/browser-privacy.md +2 -2
- package/skills/system/{system-config → system-clash-proxy-config}/references/changes.md +2 -2
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/clash-verge.md +1 -1
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/diagnosis.md +1 -1
- package/skills/system/system-clash-proxy-config/references/dns-workflow.md +42 -0
- package/skills/system/system-clash-proxy-config/references/egress-macos.md +31 -0
- package/skills/system/system-clash-proxy-config/references/egress-windows.md +37 -0
- package/skills/system/system-clash-proxy-config/references/egress.md +12 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/flclash.md +1 -1
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/index.md +1 -1
- package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/linux-cutover.md +29 -0
- package/skills/system/system-clash-proxy-config/references/locale-workflow.md +9 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/mihomo.md +1 -25
- package/skills/system/system-clash-proxy-config/references/session.md +34 -0
- package/skills/system/system-clash-proxy-config/references/subscription.md +29 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/troubleshooting.md +7 -7
- package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/verification.md +2 -0
- package/skills/system/system-clash-proxy-config/scripts/prepare-session.mjs +155 -0
- package/skills/system/system-clash-proxy-config/scripts/run-session.mjs +138 -0
- package/skills/system/system-inspect/SKILL.md +1 -1
- package/skills/system/system-inspect/references/health-audit.md +1 -1
- package/upstream-skills/zh-archify/SKILL.md +11 -11
- package/upstream-skills/zh-archify/assets/template.html +6 -3
- package/upstream-skills/zh-archify/bin/archify.mjs +67 -4
- package/upstream-skills/zh-archify/modules/code-analysis/ARCHITECTURE.md +7 -1
- package/upstream-skills/zh-archify/modules/code-analysis/bin/analyze-run.mjs +2 -1
- package/upstream-skills/zh-archify/modules/code-analysis/bin/check.mjs +29 -15
- package/upstream-skills/zh-archify/modules/code-analysis/bin/drift.mjs +3 -3
- package/upstream-skills/zh-archify/modules/code-analysis/bin/prepare.mjs +5 -6
- package/upstream-skills/zh-archify/modules/code-analysis/bin/serve.mjs +66 -36
- package/upstream-skills/zh-archify/modules/code-analysis/bin/verify-change.mjs +43 -13
- package/upstream-skills/zh-archify/modules/code-analysis/docs/TECH-GUIDE.md +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/docs/USAGE.md +37 -4
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/functions.mjs +7 -5
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/index.mjs +4 -1
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/snapshot-host.mjs +9 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/architecture-drift.mjs +28 -7
- package/upstream-skills/zh-archify/modules/code-analysis/lib/drift-capture.mjs +4 -3
- package/upstream-skills/zh-archify/modules/code-analysis/lib/git-sources.mjs +5 -3
- package/upstream-skills/zh-archify/modules/code-analysis/lib/output.mjs +272 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/pull-request.mjs +34 -4
- package/upstream-skills/zh-archify/modules/code-analysis/lib/task.mjs +4 -2
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-context.mjs +13 -1
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-history.mjs +112 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification.mjs +6 -2
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/atlas.mjs +71 -5
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.css +16 -2
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.js +121 -5
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas3d.js +38 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.css +14 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.js +187 -27
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/verification.js +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/i18n.mjs +9 -0
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/inject.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/page.mjs +11 -6
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/pull-request.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/schemas/ai-task.schema.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/atlas.test.mjs +88 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/duplicates.test.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/external-workflow.test.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.missing.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.valid.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.changed.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/module-cycle.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/function-source-range.test.mjs +10 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/output-recovery.test.mjs +626 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/pull-request.test.mjs +98 -2
- package/upstream-skills/zh-archify/modules/code-analysis/test/review.test.mjs +37 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/source-panel.test.mjs +2 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/task.test.mjs +3 -2
- package/upstream-skills/zh-archify/modules/code-analysis/test/verification-history.test.mjs +216 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/verification.test.mjs +122 -0
- package/upstream-skills/zh-archify/package-lock.json +2 -2
- package/upstream-skills/zh-archify/package.json +1 -1
- package/upstream-skills/zh-archify/references/authoring-contract.md +2 -0
- package/upstream-skills/zh-archify/references/explainer-authoring.md +1 -1
- package/upstream-skills/zh-archify/renderers/architecture/render-architecture.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/class/render-class.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/dataflow/render-dataflow.mjs +2 -1
- package/upstream-skills/zh-archify/renderers/erd/render-erd.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/lifecycle/render-lifecycle.mjs +4 -2
- package/upstream-skills/zh-archify/renderers/sequence/render-sequence.mjs +4 -2
- package/upstream-skills/zh-archify/renderers/shared/cli.mjs +7 -1
- package/upstream-skills/zh-archify/renderers/timeline/render-timeline.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/tree/render-tree.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/waterfall/render-waterfall.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/workflow/render-workflow.mjs +3 -2
- package/upstream-skills/zh-archify/renderers/workflow/workflow-compiler.mjs +68 -7
- package/upstream-skills/zh-archify/skill-release.json +1 -1
- package/upstream-skills/zh-modern-web-guidance/SKILL.md +4 -11
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-detection.md +20 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-model.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/prompt-api.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/summarizer.md +20 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/translator.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/custom-ml-model-inference.md +342 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/data-parallel-computation.md +337 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/improve-next-page-load-performance.md +4 -1
- package/upstream-skills/zh-modern-web-guidance/guides/performance/large-scene-rendering.md +350 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/position-aware-tooltips.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/viewport-aware-dropdowns.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/animate-to-from-top-layer.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/declarative-dialog-popover-control.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/interest-triggered-tooltips.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/scroll-target-on-load.md +29 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/sortable-table.md +1 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/app-menus.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/context-menu.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/copy-button.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/dialog.md +10 -1
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/hovercard.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/menu.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/navbar.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-app-tours.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-toast-notifications.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/toolbar.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/user-experience/content-first-noise-reduction.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/user-experience/natural-interactions.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/webmcp/agentic-javascript-tools.md +27 -0
- package/skills/home/home-project-changelog/assets/project-changelog.md +0 -35
- package/skills/system/system-clash-tun-egress/SKILL.md +0 -22
- package/skills/system/system-clash-tun-egress/agents/openai.yaml +0 -4
- package/skills/system/system-config/SKILL.md +0 -37
- package/skills/system/system-config/agents/openai.yaml +0 -4
- package/skills/system/system-config/references/ai-cli-config.md +0 -75
- package/skills/system/system-config/references/ai-cli-optimization.md +0 -37
- package/skills/system/system-config/references/index.md +0 -12
- package/skills/system/system-config/references/locale-workflow.md +0 -33
- package/skills/system/system-config/references/locale.md +0 -50
- package/skills/system/system-proxy/SKILL.md +0 -40
- package/skills/system/system-proxy/agents/openai.yaml +0 -4
- package/skills/system/system-proxy/assets/protected-rules.yaml +0 -7
- package/skills/system/system-proxy/references/dns-workflow.md +0 -152
- /package/skills/system/{system-config → system-clash-proxy-config}/assets/configuration.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/assets/network.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/acceptance.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-fields.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-misconceptions.md +0 -0
- /package/skills/system/{system-clash-tun-egress/references/troubleshooting.md → system-clash-proxy-config/references/egress-troubleshooting.md} +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-linux.md +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-macos.md +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-windows.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/network-performance.md +0 -0
- /package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/nodes-and-dns.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platform-dns.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platforms.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/tun-dns.md +0 -0
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
dateAt, isDigest, requireThat, revisionOf,
|
|
4
4
|
} from './contract.mjs';
|
|
5
5
|
import { firstCommitAt, listCommits, point, shallowBoundaries } from './git.mjs';
|
|
6
|
-
import { section } from './summary.mjs';
|
|
7
6
|
import { commitCalendar } from './tasks.mjs';
|
|
8
7
|
|
|
9
8
|
export function revisionSnapshot(view, frozen, git, rangeId) {
|
|
10
|
-
requireThat(!view.project?.pending, 'PENDING', '该项目存在待恢复写入,先执行 recover。');
|
|
11
9
|
requireThat(isDigest(rangeId), 'ARGUMENT', '提供完整的成功区间 ID。');
|
|
12
10
|
const record = view.project?.ranges.find(range => range.rangeId === rangeId);
|
|
13
11
|
requireThat(record, 'RANGE_NOT_FOUND', '项目中没有该成功区间。');
|
|
14
|
-
requireThat(view.document !== null, 'DOCUMENT_MISSING', '成功记录对应的 Markdown 丢失,先恢复正文。');
|
|
15
12
|
requireThat(record.sourceIdentity === frozen.binding.sourceIdentity, 'SOURCE_CHANGED', '当前已核实的项目来源与历史区间不同。');
|
|
16
13
|
for (const saved of [record.from, record.to].filter(Boolean)) {
|
|
17
14
|
requireThat(isDeepStrictEqual(saved, point(git, saved.commit, saved.observedAt)), 'GIT_RANGE_CHANGED', '历史提交与成功记录不同。');
|
|
@@ -29,201 +26,10 @@ export function revisionSnapshot(view, frozen, git, rangeId) {
|
|
|
29
26
|
}
|
|
30
27
|
return {
|
|
31
28
|
status: 'ready', purpose: 'revision', repoId: frozen.repoId, record, commits, frozen, historyStart,
|
|
32
|
-
expected: { projectRevision: revisionOf(view.project)
|
|
29
|
+
expected: { projectRevision: revisionOf(view.project) },
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
|
|
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
33
|
export function upgradeRange(record, historyStart) {
|
|
228
34
|
if (!historyStart || record.firstCommitAt) return record;
|
|
229
35
|
return { ...record, firstCommitAt: historyStart,
|
|
@@ -3,13 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { isDeepStrictEqual } from 'node:util';
|
|
6
|
-
import {
|
|
7
|
-
documentStamp, expectId, hasOwn, isId, requireThat, revisionOf, sameStamp, validateState,
|
|
8
|
-
} from './contract.mjs';
|
|
9
|
-
|
|
10
|
-
const stateName = 'state.json';
|
|
11
|
-
const lockName = '.state.lock';
|
|
12
|
-
const emptyState = () => ({ formatVersion: 1, projects: {} });
|
|
6
|
+
import { expectId, isId, requireThat, revisionOf, validateProjectFile } from './contract.mjs';
|
|
13
7
|
|
|
14
8
|
function sameFile(first, second) {
|
|
15
9
|
// Node 22 on Windows may report dev=0 when looking up the same file by path.
|
|
@@ -25,11 +19,11 @@ export function openStore(home, filesystem = fs) {
|
|
|
25
19
|
requireThat(regularDirectory(info(requested)), 'UNSAFE_HOME', 'Home 根必须是已有普通目录。');
|
|
26
20
|
const root = filesystem.realpathSync.native(requested);
|
|
27
21
|
|
|
28
|
-
function directory(create = false) {
|
|
22
|
+
function directory(create = false, segments = ['.agents', 'home', 'website', 'changelogs']) {
|
|
29
23
|
requireThat(regularDirectory(info(requested)) && filesystem.realpathSync.native(requested) === root,
|
|
30
24
|
'UNSAFE_HOME', 'Home 根在操作期间发生变化。');
|
|
31
25
|
let current = root;
|
|
32
|
-
for (const segment of
|
|
26
|
+
for (const segment of segments) {
|
|
33
27
|
current = path.join(current, segment);
|
|
34
28
|
let entry = info(current);
|
|
35
29
|
if (!entry) {
|
|
@@ -43,48 +37,39 @@ export function openStore(home, filesystem = fs) {
|
|
|
43
37
|
return current;
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
return
|
|
40
|
+
function projectName(id) {
|
|
41
|
+
expectId(id);
|
|
42
|
+
return id + '.json';
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
function read(name) {
|
|
52
|
-
const
|
|
53
|
-
|
|
45
|
+
function read(name, segments) {
|
|
46
|
+
const base = directory(false, segments);
|
|
47
|
+
if (base === null) return null;
|
|
48
|
+
const target = path.join(base, name);
|
|
49
|
+
const entry = info(target);
|
|
54
50
|
if (!entry) return null;
|
|
55
|
-
requireThat(entry.isFile() && !entry.isSymbolicLink(), 'UNSAFE_PATH',
|
|
51
|
+
requireThat(entry.isFile() && !entry.isSymbolicLink(), 'UNSAFE_PATH', name + ' 必须是同仓普通文件。');
|
|
56
52
|
const fd = filesystem.openSync(target, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
|
|
57
53
|
try {
|
|
58
54
|
const opened = filesystem.fstatSync(fd);
|
|
59
|
-
requireThat(opened.isFile() && sameFile(opened, entry),
|
|
60
|
-
'UNSAFE_PATH', `${name} 已被替换。`);
|
|
55
|
+
requireThat(opened.isFile() && sameFile(opened, entry), 'UNSAFE_PATH', name + ' 已被替换。');
|
|
61
56
|
const bytes = filesystem.readFileSync(fd);
|
|
62
|
-
const current =
|
|
57
|
+
const current = directory(false, segments) === base && info(target);
|
|
63
58
|
requireThat(current?.isFile() && sameFile(current, opened),
|
|
64
|
-
'READ_CONFLICT',
|
|
59
|
+
'READ_CONFLICT', name + ' 在读取期间发生变化。');
|
|
65
60
|
return bytes;
|
|
66
61
|
} finally { filesystem.closeSync(fd); }
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
function readState() {
|
|
70
|
-
const bytes = read(stateName);
|
|
71
|
-
if (bytes === null) return { state: emptyState(), bytes };
|
|
72
|
-
let state;
|
|
73
|
-
try { state = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)); }
|
|
74
|
-
catch { requireThat(false, 'STATE_FORMAT', 'state.json 无法解析,保留现场并暂停写入。'); }
|
|
75
|
-
return { state: validateState(state), bytes };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function documentName(id) {
|
|
79
|
-
expectId(id);
|
|
80
|
-
return `${id}.md`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
64
|
function view(id) {
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
65
|
+
const name = projectName(id);
|
|
66
|
+
const bytes = read(name);
|
|
67
|
+
if (bytes === null) return { project: null, previous: null, bytes };
|
|
68
|
+
let data;
|
|
69
|
+
try { data = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)); }
|
|
70
|
+
catch { requireThat(false, 'PROJECT_FORMAT', name + ' 无法解析,保留原件。'); }
|
|
71
|
+
const project = validateProjectFile(data, id);
|
|
72
|
+
return { project, previous: project.ranges.at(-1), bytes };
|
|
88
73
|
}
|
|
89
74
|
|
|
90
75
|
function putFile(target, bytes) {
|
|
@@ -95,17 +80,27 @@ export function openStore(home, filesystem = fs) {
|
|
|
95
80
|
} finally { filesystem.closeSync(fd); }
|
|
96
81
|
}
|
|
97
82
|
|
|
98
|
-
function withLock(action) {
|
|
83
|
+
function withLock(id, action) {
|
|
84
|
+
expectId(id);
|
|
99
85
|
const base = directory(true);
|
|
86
|
+
const lockName = '.' + id + '.lock';
|
|
100
87
|
const lock = path.join(base, lockName);
|
|
101
88
|
const token = JSON.stringify({ pid: process.pid, host: os.hostname(), startedAt: new Date().toISOString(), token: randomUUID() });
|
|
102
|
-
|
|
89
|
+
const stagedLock = path.join(base, '.' + id + '-lock-' + randomUUID() + '.tmp');
|
|
90
|
+
try {
|
|
91
|
+
putFile(stagedLock, token);
|
|
92
|
+
requireThat(directory() === base, 'UNSAFE_PATH', 'Home 日志目录在加锁期间变化。');
|
|
93
|
+
filesystem.linkSync(stagedLock, lock);
|
|
94
|
+
}
|
|
103
95
|
catch (error) {
|
|
104
96
|
if (error.code !== 'EEXIST') throw error;
|
|
105
97
|
const lockBytes = read(lockName);
|
|
106
98
|
let holder;
|
|
107
|
-
try { holder = JSON.parse(lockBytes?.toString('utf8')); } catch { /*
|
|
108
|
-
requireThat(false, 'LOCK_BUSY', '
|
|
99
|
+
try { holder = JSON.parse(lockBytes?.toString('utf8')); } catch { /* A writer may still be writing the lock. */ }
|
|
100
|
+
requireThat(false, 'LOCK_BUSY', '另一写入者占用此项目的短锁,先核实持锁运行。', { lock: holder ?? null });
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
if (directory() === base && info(stagedLock)?.isFile()) filesystem.unlinkSync(stagedLock);
|
|
109
104
|
}
|
|
110
105
|
try { return action(); }
|
|
111
106
|
finally {
|
|
@@ -113,113 +108,113 @@ export function openStore(home, filesystem = fs) {
|
|
|
113
108
|
}
|
|
114
109
|
}
|
|
115
110
|
|
|
116
|
-
function
|
|
111
|
+
function save(id, project, before) {
|
|
112
|
+
const name = projectName(id);
|
|
113
|
+
validateProjectFile(project, id);
|
|
114
|
+
const bytes = Buffer.from(JSON.stringify(project, null, 2) + '\n');
|
|
117
115
|
const base = directory();
|
|
118
116
|
requireThat(base, 'UNSAFE_PATH', 'Home 日志目录在更新期间消失。');
|
|
119
|
-
const
|
|
117
|
+
const directoryInfo = info(base);
|
|
118
|
+
const temporary = path.join(base, '.' + id + '-' + randomUUID() + '.tmp');
|
|
119
|
+
const target = path.join(base, name);
|
|
120
|
+
const sameDirectory = () => {
|
|
121
|
+
const current = directory() === base && info(base);
|
|
122
|
+
return current && sameFile(current, directoryInfo);
|
|
123
|
+
};
|
|
120
124
|
try {
|
|
121
125
|
putFile(temporary, bytes);
|
|
122
|
-
requireThat(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
requireThat(isDeepStrictEqual(read(name), before), 'STALE_CANDIDATE', name + ' 已变化,重新读取后再处理。');
|
|
127
|
+
requireThat(sameDirectory(), 'UNSAFE_PATH', 'Home 日志目录在更新期间变化。');
|
|
128
|
+
if (before === null) {
|
|
129
|
+
// Publishing a hard link to the flushed file cannot overwrite an existing destination.
|
|
130
|
+
try { filesystem.linkSync(temporary, target); }
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (error.code !== 'EEXIST') throw error;
|
|
133
|
+
requireThat(false, 'STALE_CANDIDATE', name + ' 已由另一写入者创建。');
|
|
134
|
+
}
|
|
135
|
+
} else filesystem.renameSync(temporary, target);
|
|
136
|
+
requireThat(isDeepStrictEqual(read(name), bytes), 'READ_CONFLICT', name + ' 写入回读不一致。');
|
|
126
137
|
} finally {
|
|
127
|
-
if (
|
|
138
|
+
if (sameDirectory() && info(temporary)?.isFile()) filesystem.unlinkSync(temporary);
|
|
128
139
|
}
|
|
129
140
|
}
|
|
130
141
|
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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 };
|
|
146
|
-
const hasExpectedDocument = () => requireThat(sameStamp(documentStamp(read(documentName(id))), pending.afterDocument),
|
|
147
|
-
'DOCUMENT_CHANGED', 'Markdown 在最终确认前已变化,保留 pending。');
|
|
148
|
-
saveState({ ...state, projects: { ...state.projects, [id]: next } }, stateBytes, hasExpectedDocument);
|
|
149
|
-
const result = view(id);
|
|
150
|
-
const persisted = result.project?.ranges.find(range => range.rangeId === saved.rangeId);
|
|
151
|
-
requireThat(isDeepStrictEqual(persisted, saved) && !result.project.pending
|
|
152
|
-
&& sameStamp(documentStamp(result.document), pending.afterDocument), 'READ_CONFLICT', '成功记录或 Markdown 回读不一致。');
|
|
153
|
-
return persisted;
|
|
142
|
+
function createProject(project) {
|
|
143
|
+
const id = project?.repoId;
|
|
144
|
+
validateProjectFile(project, id);
|
|
145
|
+
return withLock(id, () => {
|
|
146
|
+
const current = view(id);
|
|
147
|
+
if (current.project !== null) {
|
|
148
|
+
requireThat(isDeepStrictEqual(current.project, project), 'PROJECT_EXISTS', '此项目已有内容,保留当前 JSON。');
|
|
149
|
+
return { status: 'already-saved', project: current.project };
|
|
150
|
+
}
|
|
151
|
+
save(id, project, null);
|
|
152
|
+
return { status: 'saved', project };
|
|
153
|
+
});
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
function commit(id, expected, record,
|
|
157
|
-
return withLock(() => {
|
|
156
|
+
function commit(id, expected, record, { revision = false, displayName } = {}) {
|
|
157
|
+
return withLock(id, () => {
|
|
158
158
|
const current = view(id);
|
|
159
|
-
requireThat(!current.project?.pending, 'PENDING', '该项目存在待恢复写入,先执行 recover。');
|
|
160
159
|
const prior = current.project?.ranges.find(range => range.rangeId === record.rangeId);
|
|
161
|
-
if (revision && prior
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
}
|
|
176
|
-
const pending = {
|
|
177
|
-
transactionId: randomUUID(), rangeId: record.rangeId, expectedProjectRevision: expected.projectRevision,
|
|
178
|
-
beforeDocument: expected.document, afterDocument: documentStamp(document), nextRecord: record,
|
|
179
|
-
...(revision ? { operation: 'revision' } : {}),
|
|
160
|
+
if (!revision && prior) return { status: 'already-saved', record: prior };
|
|
161
|
+
if (revision && prior?.revisionRequest && prior.revisionRequest === record.revisionRequest
|
|
162
|
+
&& isDeepStrictEqual(prior.ledger, record.ledger)) return { status: 'already-saved', record: prior };
|
|
163
|
+
requireThat(revisionOf(current.project) === expected.projectRevision,
|
|
164
|
+
'STALE_CANDIDATE', '项目 JSON 已变化,重读后重新生成。');
|
|
165
|
+
if (revision) requireThat(prior, 'RANGE_NOT_FOUND', '项目中没有该成功区间。');
|
|
166
|
+
const saved = { ...record, savedAt: new Date().toISOString() };
|
|
167
|
+
const project = current.project ?? {
|
|
168
|
+
schemaVersion: 1, repoId: id, initialization: record.initialization, ranges: [],
|
|
169
|
+
...(displayName === undefined ? {} : { displayName }),
|
|
180
170
|
};
|
|
181
|
-
const
|
|
182
|
-
...
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const intentBytes = saveState(state, current.stateBytes);
|
|
186
|
-
if (!sameStamp(pending.beforeDocument, pending.afterDocument)) {
|
|
187
|
-
replace(documentName(id), document, pending.beforeDocument, 'DOCUMENT_CHANGED');
|
|
188
|
-
}
|
|
189
|
-
requireThat(sameStamp(documentStamp(read(documentName(id))), pending.afterDocument), 'DOCUMENT_CHANGED', 'Markdown 写入回读不一致,保留 pending。');
|
|
190
|
-
return { status: 'saved', record: confirm(id, state, intentBytes, project, record) };
|
|
171
|
+
const ranges = revision ? project.ranges.map(range => range.rangeId === saved.rangeId ? saved : range)
|
|
172
|
+
: [...project.ranges, saved];
|
|
173
|
+
save(id, { ...project, ranges, lastSuccessfulRangeId: ranges.at(-1).rangeId }, current.bytes);
|
|
174
|
+
return { status: 'saved', record: saved };
|
|
191
175
|
});
|
|
192
176
|
}
|
|
193
177
|
|
|
194
178
|
function recover(id) {
|
|
195
179
|
expectId(id);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const { pending, ...success } = project;
|
|
201
|
-
const stamp = documentStamp(document);
|
|
202
|
-
if (sameStamp(stamp, pending.afterDocument)) {
|
|
203
|
-
return { status: 'confirmed', record: confirm(id, state, stateBytes, project, pending.nextRecord) };
|
|
204
|
-
}
|
|
205
|
-
requireThat(sameStamp(stamp, pending.beforeDocument), 'RECOVERY_CONFLICT', 'Markdown 与写入前后摘要均不同,保留正文和 pending。');
|
|
206
|
-
const projects = { ...state.projects };
|
|
207
|
-
if (previous) projects[id] = success;
|
|
208
|
-
else delete projects[id];
|
|
209
|
-
saveState({ ...state, projects }, stateBytes, () => requireThat(
|
|
210
|
-
sameStamp(documentStamp(read(documentName(id))), pending.beforeDocument), 'RECOVERY_CONFLICT', 'Markdown 在恢复时发生变化,保留 pending。',
|
|
211
|
-
));
|
|
212
|
-
return { status: 'cleared', record: previous };
|
|
213
|
-
});
|
|
180
|
+
const { project, previous } = view(id);
|
|
181
|
+
const lock = read('.' + id + '.lock');
|
|
182
|
+
return { status: project === null ? 'missing' : 'no-pending',
|
|
183
|
+
...(previous ? { record: previous } : {}), ...(lock ? { lockPresent: true } : {}) };
|
|
214
184
|
}
|
|
215
185
|
|
|
216
186
|
function list() {
|
|
217
187
|
const base = directory();
|
|
218
188
|
if (base === null) return [];
|
|
219
189
|
return filesystem.readdirSync(base, { withFileTypes: true })
|
|
220
|
-
.filter(entry => entry.isFile() && entry.name.endsWith('.
|
|
221
|
-
.map(entry => entry.name.slice(0, -
|
|
190
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.json') && isId(entry.name.slice(0, -5)))
|
|
191
|
+
.map(entry => entry.name.slice(0, -5)).sort();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function resolveId(query) {
|
|
195
|
+
const tracked = list();
|
|
196
|
+
if (tracked.includes(query)) return query;
|
|
197
|
+
const bytes = read('repos.json', ['.agents', 'home']);
|
|
198
|
+
const registry = bytes ? JSON.parse(new TextDecoder('utf-8', {fatal:true}).decode(bytes)) : {repos:[]};
|
|
199
|
+
requireThat(Array.isArray(registry.repos), 'INVALID_REGISTRY', 'repos.json 缺少项目登记数组。');
|
|
200
|
+
const registered = new Map(registry.repos.map(repo => [repo.id, repo]));
|
|
201
|
+
if (registered.has(query)) return query;
|
|
202
|
+
const names = new Map(Object.entries(registry.projectNames ?? {}));
|
|
203
|
+
const knownIds = new Set([...tracked, ...registered.keys()]);
|
|
204
|
+
const unchecked = [query, ...[...names].filter(([, name]) => name === query).map(([id]) => id)]
|
|
205
|
+
.filter(id => isId(id) && !knownIds.has(id));
|
|
206
|
+
if (unchecked.length) {
|
|
207
|
+
const config = read('site.config.json', ['.agents', 'home', 'website']);
|
|
208
|
+
const bindings = config && JSON.parse(config).overrides;
|
|
209
|
+
for (const id of unchecked) if (registered.has(bindings?.[id]?.submoduleOf)) knownIds.add(id);
|
|
210
|
+
if (knownIds.has(query)) return query;
|
|
211
|
+
}
|
|
212
|
+
const matches = [...knownIds].filter(id => names.get(id) === query || registered.get(id)?.aliases?.includes(query));
|
|
213
|
+
requireThat(matches.length <= 1, 'AMBIGUOUS_PROJECT', '项目名称重名,请使用准确 ID:' + matches.join('、'));
|
|
214
|
+
if (matches.length) return matches[0];
|
|
215
|
+
requireThat(isId(query), 'PROJECT_MISSING', '未找到该名称对应的项目。');
|
|
216
|
+
return query;
|
|
222
217
|
}
|
|
223
218
|
|
|
224
|
-
return { root, view, commit, recover, list, show: id =>
|
|
219
|
+
return { root, view, commit, createProject, recover, list, resolveId, show: id => view(id).bytes };
|
|
225
220
|
}
|
|
@@ -48,63 +48,3 @@ export function candidateEntries(candidate, snapshot, git) {
|
|
|
48
48
|
}
|
|
49
49
|
return candidate.entries;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
function oneLine(text) {
|
|
53
|
-
return text.trim().replace(/[[\]]/gu, '\\$&');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function section(record, entries) {
|
|
57
|
-
const { displayDates: { from, to }, kind, stats } = record;
|
|
58
|
-
const parts = [`## ${from ? `${from} 至 ${to}` : to}`];
|
|
59
|
-
if (kind === 'delta') {
|
|
60
|
-
if (record.previousRangeId === null) parts.push('指定起点之前的变更未回填。');
|
|
61
|
-
if (record.changeReason) parts.push('本次按新指定的引用继续记录。');
|
|
62
|
-
} else if (kind === 'baseline' || kind === 'rebaseline') {
|
|
63
|
-
const lead = kind === 'rebaseline' ? '重新建立基线。' : record.initialization.mode === 'from' ? '所选初始区间为空。' : '';
|
|
64
|
-
parts.push(`${lead}从 ${to} 开始记录,之前的变更未回填。`);
|
|
65
|
-
}
|
|
66
|
-
if (record.freshness === 'remote-cache') parts.push('本次采用本地缓存,远端新鲜度未验证。');
|
|
67
|
-
const byCategory = new Map(categories.map(category => [category, []]));
|
|
68
|
-
for (const entry of entries) byCategory.get(entry.category).push(entry);
|
|
69
|
-
const columns = ['变更总数', ...categories, '本次提交'];
|
|
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
|
-
}
|
|
76
|
-
const row = cells => `| ${cells.join(' | ')} |`;
|
|
77
|
-
parts.push([
|
|
78
|
-
row(columns),
|
|
79
|
-
row(columns.map(() => '---:')),
|
|
80
|
-
row(counts.map(count => count.toLocaleString('en-US'))),
|
|
81
|
-
].join('\n'));
|
|
82
|
-
for (const [category, group] of byCategory) {
|
|
83
|
-
const items = group.map(entry => {
|
|
84
|
-
const impacts = [...new Set(entry.markers)].map(marker => `**[${marker}]**`).join(' ');
|
|
85
|
-
const source = entry.date ? `${entry.date} · ${entry.area ? oneLine(entry.area) : '—'} · ` : '';
|
|
86
|
-
return `- ${source}${impacts ? `${impacts} ` : ''}${oneLine(entry.text)}`;
|
|
87
|
-
});
|
|
88
|
-
if (items.length) parts.push(`### ${category}`, items.join('\n'));
|
|
89
|
-
}
|
|
90
|
-
if (record.coverage === 'complete' && !entries.length) parts.push('本次没有需单列的变更。');
|
|
91
|
-
return parts.join('\n\n');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function renderNext(before, repoId, displayName, record, entries) {
|
|
95
|
-
const body = section(record, entries);
|
|
96
|
-
if (before === null || !before.length) return Buffer.from(`# ${oneLine(displayName ?? repoId)} 变更日志\n\n${body}\n`);
|
|
97
|
-
let existing;
|
|
98
|
-
try { existing = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(before); }
|
|
99
|
-
catch { requireThat(false, 'DOCUMENT_FORMAT', '已有 Markdown 需要可读的 UTF-8 内容,保留原件。'); }
|
|
100
|
-
const start = existing.match(/^\uFEFF?(?:(?:---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$))?(?:[ \t]*\r?\n)*# [^\r\n]+(?:\r?\n|$)|(?:---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)))/u)?.[0]
|
|
101
|
-
?? (existing.startsWith('\uFEFF') ? '\uFEFF' : '');
|
|
102
|
-
const at = Buffer.byteLength(start);
|
|
103
|
-
const insertion = `${at && start !== '\uFEFF' ? (start.endsWith('\n') ? '\n' : '\n\n') : ''}${body}\n${at < before.length ? '\n' : ''}`;
|
|
104
|
-
const newline = existing.match(/\r?\n/u)?.[0] ?? '\n';
|
|
105
|
-
return Buffer.concat([
|
|
106
|
-
before.subarray(0, at),
|
|
107
|
-
Buffer.from(insertion.replaceAll('\n', newline)),
|
|
108
|
-
before.subarray(at),
|
|
109
|
-
]);
|
|
110
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: home-route
|
|
3
|
-
description:
|
|
3
|
+
description: 按稳定 ID、用户指定的名称或其他别名查找已登记项目、子模块和项目日志,支持分组、本机路径覆盖与指定 worktree。用于「项目在哪里」「这个名字指哪个仓库」「用这个 worktree」,核对实际 checkout、Git 远端身份和资料入口。更新登记用 home-setup,诊断已发现的结构异常用 home-doctor。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# 定位项目与实际 checkout
|
|
@@ -11,7 +11,7 @@ description: 只读定位已登记项目,解析项目名、别名、分组、
|
|
|
11
11
|
|
|
12
12
|
先读取下述 Home 主入口,再读[路由与身份核查](references/routing.md)。同一上下文已读同一根、同一版本的入口可复用;新会话、压缩后缺失、入口更新或换根时重读。入口读不到先核对根、路径和安装状态,可用时调用 `home-doctor`;无需先成功读取才能做最小只读诊断。
|
|
13
13
|
|
|
14
|
-
1. 从实际 Home 根读取 `./.agents/home/AGENTS.md
|
|
14
|
+
1. 从实际 Home 根读取 `./.agents/home/AGENTS.md`。优先匹配稳定 ID,再匹配 `repos.json` 的 `projectNames` 和登记项 `aliases`。重名时列候选。只有分仓日志的项目返回日志位置。已声明的子模块可经父仓核对 checkout。分组查询限于登记项目。
|
|
15
15
|
2. 按显式 checkout → local.json → 登记路径选择入口。核对真实路径、Git root、主 remote 和 common directory,支持 `.git` 为文件的 worktree;路径指向不同仓库时停止该目标。v2 按指定主 remote 的首 fetch URL 核验,其他 remote 的变动单独报告;旧 v1 沿用原身份规则。
|
|
16
16
|
3. 只确认统一入口是否存在;项目资料引用只解析 `repo ID + checkout 内相对路径`,不读取正文或扫描项目知识。
|
|
17
17
|
4. 将解析结果交回调用者。项目调查和开发由 `home-workflow` 按用户选择调用当地派遣方法。已授权的 Git 区间采集交 `home-project-changelog`。登记修改交 `home-setup`,结构异常交 `home-doctor`。
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## 输入与选择
|
|
4
4
|
|
|
5
|
-
读取 Home 的 `.agents/home/repos.json`;当前新登记为 `formatVersion: 2`,继续读取旧 v1;完整写入校验归 `home-setup
|
|
5
|
+
读取 Home 的 `.agents/home/repos.json`;当前新登记为 `formatVersion: 2`,继续读取旧 v1;完整写入校验归 `home-setup`。未知版本明确失败。`--repo` 先精确匹配登记或日志的稳定 ID,再匹配 `projectNames` 中的首选名称及登记项 `aliases`。同一项目只返回一次,多个匹配返回 `ambiguous` 和候选 ID。显式 `--group` 只匹配登记分组。
|
|
6
|
+
|
|
7
|
+
只有分仓 JSON 时,普通查询返回 `changelog_only`、稳定 ID 和日志路径,可直接查看历史。已配置 `submoduleOf` 的项目,根据父仓 HEAD 的 gitlink、`.gitmodules` 路径和本地初始化的 remote 核验子模块,返回 `resolved` 和实际 checkout。派遣、查询分支和补采 Git 均需要已核实的 checkout。
|
|
6
8
|
|
|
7
9
|
本机覆盖只接受:
|
|
8
10
|
|