@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
|
@@ -3,32 +3,33 @@ import fs from 'node:fs';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { isDeepStrictEqual, parseArgs } from 'node:util';
|
|
5
5
|
import {
|
|
6
|
-
dateAt, digest,
|
|
7
|
-
lineMetricScope, rangeIdFor, requireThat, revisionOf,
|
|
6
|
+
dateAt, digest, expectId, expectKeys, isDigest, isInstant, isLine, isOid, isRevisionRef,
|
|
7
|
+
lineMetricScope, rangeIdFor, requireThat, revisionOf, sameTracking, validTracking,
|
|
8
8
|
} from './contract.mjs';
|
|
9
9
|
import {
|
|
10
10
|
commitEvidence, firstCommitAt, headCount, isReachable, listCommits, measureLines, observeTarget, openFrozenSource, openRoutedSource,
|
|
11
11
|
point, resolveInitialBase, shallowBoundaries,
|
|
12
12
|
} from './git.mjs';
|
|
13
13
|
import { openStore } from './storage.mjs';
|
|
14
|
-
import { candidateEntries
|
|
15
|
-
import { revisionSnapshot,
|
|
14
|
+
import { candidateEntries } from './summary.mjs';
|
|
15
|
+
import { revisionSnapshot, upgradeRange } from './revision.mjs';
|
|
16
16
|
import { taskLedger } from './tasks.mjs';
|
|
17
17
|
|
|
18
18
|
function checkSelection(selection, view) {
|
|
19
|
-
expectKeys(selection, ['tracking', 'mode', 'base', 'timezone', 'offline', 'completeHistory',
|
|
20
|
-
'changeReason', 'rebaselineReason'], 'ARGUMENT', '选择文件包含未知字段或格式无效。');
|
|
21
|
-
requireThat(
|
|
19
|
+
expectKeys(selection, ['tracking', 'mode', 'base', 'timezone', 'offline', 'completeHistory',
|
|
20
|
+
'changeReason', 'rebaselineReason', 'collectionAt'], 'ARGUMENT', '选择文件包含未知字段或格式无效。');
|
|
21
|
+
requireThat(selection.collectionAt === undefined || (isInstant(selection.collectionAt) &&
|
|
22
|
+
new Date(selection.collectionAt).toISOString() === selection.collectionAt),
|
|
23
|
+
'ARGUMENT', 'collectionAt 需要标准 UTC 时间,例如 2026-12-03T07:00:00.000Z。');
|
|
22
24
|
requireThat(selection.tracking === undefined || validTracking(selection.tracking), 'ARGUMENT', '跟踪引用无效。');
|
|
23
|
-
for (const key of ['offline', 'completeHistory'
|
|
25
|
+
for (const key of ['offline', 'completeHistory']) {
|
|
24
26
|
requireThat(selection[key] === undefined || typeof selection[key] === 'boolean', 'ARGUMENT', `${key} 使用布尔值。`);
|
|
25
27
|
}
|
|
26
28
|
for (const key of ['timezone', 'changeReason', 'rebaselineReason']) {
|
|
27
29
|
requireThat(selection[key] === undefined || isLine(selection[key]), 'ARGUMENT', `${key} 使用单行值。`);
|
|
28
30
|
}
|
|
29
31
|
if (view.previous) {
|
|
30
|
-
requireThat(
|
|
31
|
-
requireThat(selection.mode === undefined && selection.base === undefined && !selection.adoptExisting,
|
|
32
|
+
requireThat(selection.mode === undefined && selection.base === undefined,
|
|
32
33
|
'ARGUMENT', '此项目已初始化。按既有节点续写,或明确提供重建基线的理由。');
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
@@ -36,10 +37,6 @@ function checkSelection(selection, view) {
|
|
|
36
37
|
requireThat(['full-history', 'from', 'baseline'].includes(mode) && (mode === 'from' ? isRevisionRef(selection.base) : selection.base === undefined)
|
|
37
38
|
&& selection.changeReason === undefined && selection.rebaselineReason === undefined,
|
|
38
39
|
'ARGUMENT', '首次采用全历史、指定起点或只建基线。');
|
|
39
|
-
if (view.document !== null) {
|
|
40
|
-
requireThat(selection.adoptExisting && mode !== 'full-history', 'ORPHAN_DOCUMENT',
|
|
41
|
-
'已有 Markdown 缺少成功状态。先恢复 JSON,或按明确意图保留原文并接管。');
|
|
42
|
-
} else requireThat(!selection.adoptExisting, 'ARGUMENT', '没有待接管的 Markdown。');
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
export function freeze(home, route, selection = {}) {
|
|
@@ -56,6 +53,7 @@ export function freeze(home, route, selection = {}) {
|
|
|
56
53
|
const base = selection.mode === 'from' ? resolveInitialBase(source, selection.base, target.freshness) : null;
|
|
57
54
|
return {
|
|
58
55
|
formatVersion: 1, homeRoot: store.root, repoId: route.repoId, binding: source.binding, selection, timezone, base,
|
|
56
|
+
collectionAt: selection.collectionAt ?? new Date(target.observedAt).toISOString(),
|
|
59
57
|
expectedProjectRevision: revisionOf(view.project), ...target,
|
|
60
58
|
};
|
|
61
59
|
}
|
|
@@ -65,10 +63,12 @@ function checkFrozen(frozen, view) {
|
|
|
65
63
|
&& isLine(frozen.timezone) && validTracking(frozen.tracking)
|
|
66
64
|
&& (frozen.expectedProjectRevision === null || isDigest(frozen.expectedProjectRevision)),
|
|
67
65
|
'FROZEN', '需要本次 freeze 的完整结果。');
|
|
68
|
-
checkSelection(frozen.selection, view);
|
|
69
66
|
requireThat(frozen.expectedProjectRevision === revisionOf(view.project), 'STALE_CANDIDATE', '项目的成功状态已变化,重新冻结。');
|
|
67
|
+
checkSelection(frozen.selection, view);
|
|
70
68
|
const { tracking, binding, freshness, selection } = frozen;
|
|
71
69
|
requireThat((selection.mode === 'from' ? isOid(frozen.base) : frozen.base === null)
|
|
70
|
+
&& (frozen.collectionAt === undefined ? selection.collectionAt === undefined
|
|
71
|
+
: frozen.collectionAt === (selection.collectionAt ?? new Date(frozen.observedAt).toISOString()))
|
|
72
72
|
&& (!selection.tracking || sameTracking(selection.tracking, tracking))
|
|
73
73
|
&& (tracking.kind === 'remote-branch' ? tracking.remote === binding?.remote?.name
|
|
74
74
|
&& freshness === (selection.offline ? 'remote-cache' : 'remote-observed') : freshness === 'local'),
|
|
@@ -127,6 +127,7 @@ function collect(frozen, view, git) {
|
|
|
127
127
|
const record = {
|
|
128
128
|
kind, sourceIdentity, tracking, initialization, previousRangeId: previous?.rangeId ?? null,
|
|
129
129
|
from, to, freshness,
|
|
130
|
+
...(frozen.collectionAt && {collectionAt:frozen.collectionAt}),
|
|
130
131
|
...(historyStart ? { firstCommitAt: historyStart } : {}),
|
|
131
132
|
...(changeReason ? { changeReason, previousSourceIdentity: previous.sourceIdentity } : {}),
|
|
132
133
|
displayDates: { from: startTime ? dateAt(startTime, timezone) : null, to: dateAt(to.observedAt, timezone), timezone },
|
|
@@ -134,7 +135,7 @@ function collect(frozen, view, git) {
|
|
|
134
135
|
stats: statistics(git, to.commit, shallow, commits.length, metrics),
|
|
135
136
|
};
|
|
136
137
|
return { status: 'ready', repoId, frozen, record: { ...record, rangeId: rangeIdFor(repoId, record) }, commits,
|
|
137
|
-
expected: { projectRevision: frozen.expectedProjectRevision
|
|
138
|
+
expected: { projectRevision: frozen.expectedProjectRevision } };
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
export function snapshot(home, frozen) {
|
|
@@ -179,21 +180,20 @@ export function apply(home, input, candidate, { filesystem } = {}) {
|
|
|
179
180
|
const store = openStore(home, filesystem);
|
|
180
181
|
requireThat(input.frozen.homeRoot === store.root, 'IDENTITY', '冻结节点来自另一 Home。');
|
|
181
182
|
const view = store.view(input.repoId);
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
requireThat(view.document !== null, 'DOCUMENT_MISSING', '成功记录对应的 Markdown 丢失,先恢复正文。');
|
|
185
|
-
return { status: 'already-saved', record: view.previous };
|
|
186
|
-
}
|
|
183
|
+
const prior = view.project?.ranges.find(range => range.rangeId === input.record.rangeId);
|
|
184
|
+
if (prior) return { status: 'already-saved', record: prior };
|
|
187
185
|
checkFrozen(input.frozen, view);
|
|
188
|
-
requireThat(sameStamp(documentStamp(view.document), input.expected?.document), 'STALE_CANDIDATE', 'Markdown 已变化,重读后重新生成。');
|
|
189
186
|
const git = openFrozenSource(input.frozen);
|
|
190
187
|
const actual = collect(input.frozen, view, git);
|
|
191
188
|
requireThat(isDeepStrictEqual(input, actual), 'SNAPSHOT', '实际范围、统计或写入基线与 snapshot 不一致。');
|
|
192
189
|
const entries = candidateEntries(candidate, actual, git);
|
|
193
190
|
const ledger = taskLedger(actual, entries, git);
|
|
194
191
|
const record = { ...actual.record, ledger, generatedAt: new Date().toISOString(), savedAt: null };
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
return store.commit(actual.repoId, actual.expected, record, { displayName: candidate?.displayName });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function revisionRequest(input, candidate, ledger) {
|
|
196
|
+
return digest(JSON.stringify([input, candidate, ledger]));
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
export function revise(home, input, candidate, { filesystem } = {}) {
|
|
@@ -202,24 +202,24 @@ export function revise(home, input, candidate, { filesystem } = {}) {
|
|
|
202
202
|
const store = openStore(home, filesystem);
|
|
203
203
|
requireThat(input.frozen.homeRoot === store.root, 'IDENTITY', '冻结结果来自另一个 Home。');
|
|
204
204
|
const view = store.view(input.repoId);
|
|
205
|
-
requireThat(!view.project?.pending, 'PENDING', '该项目存在待恢复写入,先执行 recover。');
|
|
206
|
-
const request = digest(JSON.stringify([input, candidate]));
|
|
207
205
|
const prior = view.project?.ranges.find(range => range.rangeId === input.record.rangeId);
|
|
208
|
-
|
|
209
|
-
if (prior?.revisionRequest === request && prior.revisionDocument === stamp.sha256) {
|
|
206
|
+
if (prior?.revisionRequest && prior.revisionRequest === revisionRequest(input, candidate, prior.ledger)) {
|
|
210
207
|
return { status: 'already-saved', record: prior };
|
|
211
208
|
}
|
|
212
|
-
requireThat(input.expected?.projectRevision === revisionOf(view.project)
|
|
213
|
-
'STALE_CANDIDATE', '
|
|
209
|
+
requireThat(input.expected?.projectRevision === revisionOf(view.project),
|
|
210
|
+
'STALE_CANDIDATE', '项目 JSON 已变化,重新打开区间后再处理。');
|
|
214
211
|
const git = openFrozenSource(input.frozen);
|
|
215
212
|
const actual = revisionSnapshot(view, input.frozen, git, input.record.rangeId);
|
|
216
213
|
requireThat(isDeepStrictEqual(input, actual), 'SNAPSHOT', '实际历史区间与输入快照不同。');
|
|
217
214
|
const entries = candidateEntries(candidate, actual, git);
|
|
218
215
|
const ledger = taskLedger(actual, entries, git);
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
216
|
+
const { legacy, ...upgraded } = upgradeRange(actual.record, actual.historyStart);
|
|
217
|
+
if (isDeepStrictEqual(upgraded, actual.record) && isDeepStrictEqual(ledger, prior.ledger)) {
|
|
218
|
+
return { status: 'already-saved', record: prior };
|
|
219
|
+
}
|
|
220
|
+
const record = { ...upgraded, ledger, revisionRequest: revisionRequest(input, candidate, ledger),
|
|
221
|
+
generatedAt: new Date().toISOString(), savedAt: null };
|
|
222
|
+
return store.commit(actual.repoId, actual.expected, record, { revision: true });
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
const commands = {
|
|
@@ -241,7 +241,7 @@ function json(filename) {
|
|
|
241
241
|
export function main(argv = process.argv.slice(2)) {
|
|
242
242
|
try {
|
|
243
243
|
if (argv.length === 1 && argv[0] === '--help') {
|
|
244
|
-
console.log('用法:node changelog.mjs freeze | snapshot | evidence | apply | reopen | revise | recover | show\n各命令使用 --help 查看参数。正式资料在指定 Home 的 .agents/home/changelogs/。');
|
|
244
|
+
console.log('用法:node changelog.mjs freeze | snapshot | evidence | apply | reopen | revise | recover | show\n各命令使用 --help 查看参数。正式资料在指定 Home 的 .agents/home/website/changelogs/。');
|
|
245
245
|
return 0;
|
|
246
246
|
}
|
|
247
247
|
const [command, ...args] = argv;
|
|
@@ -268,12 +268,16 @@ export function main(argv = process.argv.slice(2)) {
|
|
|
268
268
|
case 'apply': result = apply(values.home, json(values.snapshot), values.candidate ? json(values.candidate) : undefined); break;
|
|
269
269
|
case 'reopen': result = reopen(values.home, json(values.route), values.range); break;
|
|
270
270
|
case 'revise': result = revise(values.home, json(values.snapshot), json(values.candidate)); break;
|
|
271
|
-
case 'recover':
|
|
271
|
+
case 'recover': {
|
|
272
|
+
const store = openStore(values.home);
|
|
273
|
+
result = store.recover(store.resolveId(values.repo));
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
272
276
|
case 'show': {
|
|
273
277
|
const store = openStore(values.home);
|
|
274
278
|
if (values.repo === undefined) { result = { projects: store.list() }; break; }
|
|
275
|
-
const bytes = store.show(values.repo);
|
|
276
|
-
requireThat(bytes !== null, '
|
|
279
|
+
const bytes = store.show(store.resolveId(values.repo));
|
|
280
|
+
requireThat(bytes !== null, 'PROJECT_MISSING', '未找到此项目的 JSON。');
|
|
277
281
|
process.stdout.write(bytes);
|
|
278
282
|
return 0;
|
|
279
283
|
}
|
|
@@ -121,13 +121,14 @@ function validRecord(id, entry, previous, initialization, saved) {
|
|
|
121
121
|
|| !validPoint(entry.to) || !isLine(entry.sourceIdentity) || !validTracking(entry.tracking)
|
|
122
122
|
|| entry.rangeId !== rangeIdFor(id, entry) || entry.previousRangeId !== (previous?.rangeId ?? null)
|
|
123
123
|
|| !isInstant(entry.generatedAt) || (saved ? !isInstant(entry.savedAt) : entry.savedAt !== null)
|
|
124
|
+
|| (hasOwn(entry, 'collectionAt') && !(isInstant(entry.collectionAt) && new Date(entry.collectionAt).toISOString() === entry.collectionAt))
|
|
124
125
|
|| !['remote-observed', 'remote-cache', 'local'].includes(entry.freshness)) return false;
|
|
125
126
|
if (entry.tracking.kind === 'remote-branch' ? entry.freshness === 'local' : entry.freshness !== 'local') return false;
|
|
126
127
|
const complete = ['delta', 'full-history'].includes(entry.kind);
|
|
127
128
|
if (entry.coverage !== (complete ? 'complete' : 'not-backfilled') || !validStats(entry.stats, entry.coverage)) return false;
|
|
128
129
|
if (hasOwn(entry, 'ledger') && !validLedger(entry.ledger, entry.stats.rangeCommitCount)) return false;
|
|
129
|
-
if (
|
|
130
|
-
|
|
130
|
+
if (hasOwn(entry, 'revisionRequest') && !isDigest(entry.revisionRequest)) return false;
|
|
131
|
+
if (hasOwn(entry, 'revisionDocument') && (!isDigest(entry.revisionDocument) || !isDigest(entry.revisionRequest))) return false;
|
|
131
132
|
if (entry.kind === 'delta') {
|
|
132
133
|
if (!validPoint(entry.from) || entry.from.commit === entry.to.commit) return false;
|
|
133
134
|
if (previous) {
|
|
@@ -162,6 +163,41 @@ function sameRevisionRange(before, after) {
|
|
|
162
163
|
return isDeepStrictEqual(stable(before), stable(after));
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
export function validateProjectFile(project, id) {
|
|
167
|
+
const message = `${id} 的项目 JSON 版本、身份或区间无法核对。`;
|
|
168
|
+
const validNotes = notes => Array.isArray(notes) && notes.every(note => typeof note === 'string' && note.trim());
|
|
169
|
+
expectKeys(project, ['schemaVersion', 'repoId', 'initialization', 'lastSuccessfulRangeId', 'ranges', 'notes', 'displayName'],
|
|
170
|
+
'PROJECT_FORMAT', message);
|
|
171
|
+
requireThat(isId(id) && project.repoId === id && project.schemaVersion === 1
|
|
172
|
+
&& validInitialization(project.initialization) && Array.isArray(project.ranges)
|
|
173
|
+
&& (!hasOwn(project, 'notes') || validNotes(project.notes))
|
|
174
|
+
&& (!hasOwn(project, 'displayName') || isLine(project.displayName)), 'PROJECT_FORMAT', message);
|
|
175
|
+
const ids = new Set();
|
|
176
|
+
let previous = null;
|
|
177
|
+
for (const range of project.ranges) {
|
|
178
|
+
expectKeys(range, ['kind', 'sourceIdentity', 'tracking', 'initialization', 'previousRangeId', 'from', 'to',
|
|
179
|
+
'freshness', 'firstCommitAt', 'collectionAt', 'changeReason', 'previousSourceIdentity', 'displayDates', 'coverage', 'stats',
|
|
180
|
+
'rangeId', 'ledger', 'legacy', 'generatedAt', 'savedAt', 'notes', 'revisionRequest'], 'PROJECT_FORMAT', message);
|
|
181
|
+
requireThat(validRecord(id, range, previous, project.initialization, true)
|
|
182
|
+
&& !ids.has(range.rangeId)
|
|
183
|
+
&& (!hasOwn(range, 'notes') || validNotes(range.notes)), 'PROJECT_FORMAT', message);
|
|
184
|
+
const { legacy } = range;
|
|
185
|
+
requireThat(hasOwn(range, 'ledger') !== hasOwn(range, 'legacy'), 'PROJECT_FORMAT', message);
|
|
186
|
+
if (hasOwn(range, 'legacy')) {
|
|
187
|
+
expectKeys(legacy, ['entries', 'added'], 'PROJECT_FORMAT', message);
|
|
188
|
+
requireThat(Array.isArray(legacy.entries) && legacy.entries.every(entry => isObject(entry)
|
|
189
|
+
&& categories.includes(entry.category) && isLine(entry.text) && Array.isArray(entry.markers)
|
|
190
|
+
&& entry.markers.every(marker => markers.includes(marker)))
|
|
191
|
+
&& (!hasOwn(legacy, 'added') || legacy.added === null || nonnegative(legacy.added)
|
|
192
|
+
&& legacy.added <= legacy.entries.filter(entry => entry.category === '功能').length), 'PROJECT_FORMAT', message);
|
|
193
|
+
}
|
|
194
|
+
ids.add(range.rangeId);
|
|
195
|
+
previous = range;
|
|
196
|
+
}
|
|
197
|
+
requireThat(previous !== null && project.lastSuccessfulRangeId === previous.rangeId, 'PROJECT_FORMAT', message);
|
|
198
|
+
return project;
|
|
199
|
+
}
|
|
200
|
+
|
|
165
201
|
export function validateState(state) {
|
|
166
202
|
requireThat(isObject(state) && state.formatVersion === 1 && isObject(state.projects), 'STATE_FORMAT', 'state.json 的版本或 projects 无法核对。');
|
|
167
203
|
for (const [id, project] of Object.entries(state.projects)) {
|
|
@@ -169,7 +205,8 @@ export function validateState(state) {
|
|
|
169
205
|
requireThat(isId(id) && isObject(project) && validInitialization(project.initialization) && Array.isArray(project.ranges), 'STATE_FORMAT', message);
|
|
170
206
|
let previous = null;
|
|
171
207
|
for (const range of project.ranges) {
|
|
172
|
-
requireThat(validRecord(id, range, previous, project.initialization, true)
|
|
208
|
+
requireThat(validRecord(id, range, previous, project.initialization, true)
|
|
209
|
+
&& hasOwn(range, 'revisionRequest') === hasOwn(range, 'revisionDocument'), 'STATE_FORMAT', message);
|
|
173
210
|
previous = range;
|
|
174
211
|
}
|
|
175
212
|
requireThat(project.lastSuccessfulRangeId === (previous?.rangeId ?? null)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Reader for pre-JSON Home logs. Used only by the one-time migration.
|
|
2
|
+
import { categories, requireThat } from './contract.mjs';
|
|
3
|
+
|
|
4
|
+
const tags = ['破坏性', '安全', '弃用', '移除', '回退'];
|
|
5
|
+
const columns = ['变更总数', ...categories, '本次提交'];
|
|
6
|
+
const dateTitle = /^## (\d{4}-\d{2}-\d{2})(?: 至 (\d{4}-\d{2}-\d{2}))?$/u;
|
|
7
|
+
const splitCells = line => line.trim().slice(1,-1).split('|').map(word => word.trim());
|
|
8
|
+
function validDay(day) {
|
|
9
|
+
if (typeof day !== 'string' || !/^\d{4}-\d{2}-\d{2}$/u.test(day)) return false;
|
|
10
|
+
const ms = Date.parse(day + 'T00:00:00Z');
|
|
11
|
+
return Number.isFinite(ms) && new Date(ms).toISOString().slice(0,10) === day;
|
|
12
|
+
}
|
|
13
|
+
function tableAt(lines, i) {
|
|
14
|
+
if (!lines[i]?.startsWith('|') || !lines[i+1]?.startsWith('|') || !lines[i+2]?.startsWith('|')) return null;
|
|
15
|
+
const headers = splitCells(lines[i]), values = splitCells(lines[i+2]);
|
|
16
|
+
const expected = headers.includes('新增') ? [...columns, '新增'] : columns;
|
|
17
|
+
const separators = splitCells(lines[i+1]);
|
|
18
|
+
if (headers.length !== expected.length || headers.length !== values.length || !expected.every(key=>headers.includes(key))) return null;
|
|
19
|
+
if (separators.length !== headers.length || !separators.every(cell=>/^:?-{3,}:?$/u.test(cell))) return null;
|
|
20
|
+
if (!values.every(val=>/^(?:\d+|\d{1,3}(?:,\d{3})+)$/u.test(val) && Number.isSafeInteger(Number(val.replaceAll(',',''))))) return null;
|
|
21
|
+
return Object.fromEntries(headers.map((key,index)=>[key,Number(values[index].replaceAll(',',''))]));
|
|
22
|
+
}
|
|
23
|
+
function entry(category, body) {
|
|
24
|
+
const markers = [];
|
|
25
|
+
const dated = /^(\d{4}-\d{2}-\d{2}) · (.+?) · (.+)$/u.exec(body);
|
|
26
|
+
const unescape = value => value.replace(/\\([\[\]])/gu,'$1');
|
|
27
|
+
const meta = dated && validDay(dated[1]) ? {date:dated[1],area:dated[2] === '—' ? null : unescape(dated[2])} : null;
|
|
28
|
+
let text = meta ? dated[3] : body;
|
|
29
|
+
while (true) {
|
|
30
|
+
const match = /^\*\*\[([^\]]+)\]\*\*\s+/u.exec(text);
|
|
31
|
+
if (!match || !tags.includes(match[1])) break;
|
|
32
|
+
markers.push(match[1]);
|
|
33
|
+
text = text.slice(match[0].length);
|
|
34
|
+
}
|
|
35
|
+
return meta ? [category,unescape(text),markers,meta] : [category,unescape(text),markers];
|
|
36
|
+
}
|
|
37
|
+
function parsePeriod(title, lines, datedOnly) {
|
|
38
|
+
let group = '', totals = null, originalTable = '', fence = '';
|
|
39
|
+
const items = [], notes = [];
|
|
40
|
+
for (let i=0; i<lines.length; i++) {
|
|
41
|
+
const line = lines[i].trim();
|
|
42
|
+
if (!line) continue;
|
|
43
|
+
const delimiter = /^\s*(\x60{3,}|~{3,})/u.exec(line);
|
|
44
|
+
if (delimiter || fence) {
|
|
45
|
+
if (delimiter && !fence) fence=delimiter[1];
|
|
46
|
+
else if (delimiter && delimiter[1][0]===fence[0] && delimiter[1].length>=fence.length) fence='';
|
|
47
|
+
notes.push(line);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const table = tableAt(lines,i);
|
|
51
|
+
if (table) {
|
|
52
|
+
requireThat(!totals, 'MIGRATION_SOURCE', '旧日期段包含多份统计表,请先核对原文。');
|
|
53
|
+
totals=table; originalTable=lines.slice(i,i+3).join('\n'); i+=2; group=''; continue;
|
|
54
|
+
}
|
|
55
|
+
if (line.startsWith('### ')) {
|
|
56
|
+
group = line.slice(4);
|
|
57
|
+
if (!categories.includes(group)) notes.push(line);
|
|
58
|
+
} else if (categories.includes(group) && line.startsWith('- ')) {
|
|
59
|
+
const task = entry(group,line.slice(2));
|
|
60
|
+
if (datedOnly && !task[3]) notes.push(line);
|
|
61
|
+
else items.push(task);
|
|
62
|
+
} else notes.push(line);
|
|
63
|
+
}
|
|
64
|
+
const from = title[2] ? title[1] : null, to = title[2] ?? title[1];
|
|
65
|
+
const countsOK = totals && totals['变更总数'] === items.length &&
|
|
66
|
+
(totals['新增'] === undefined || totals['新增'] <= totals['功能']) &&
|
|
67
|
+
categories.every(category=>totals[category] === items.filter(([name])=>name===category).length);
|
|
68
|
+
if (originalTable && !countsOK) notes.push('原文统计待核对\n'+originalTable);
|
|
69
|
+
return {
|
|
70
|
+
from, to, items, notes, note:notes.join('\n'), commits:totals?.['本次提交'] ?? null,
|
|
71
|
+
added:countsOK ? totals['新增'] ?? (totals['功能'] === 0 ? 0 : null) : null,
|
|
72
|
+
verified:Boolean(countsOK), baseline:!items.length && totals?.['本次提交'] === 0 && notes.some(note=>/基线|之前的变更未回填/u.test(note)),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function parseMarkdown(body, {datedOnly = false} = {}) {
|
|
77
|
+
const ranges = [], legacy = [];
|
|
78
|
+
let header = null, block = [], fence = '', comment = false;
|
|
79
|
+
function flush() {
|
|
80
|
+
if (header) ranges.push(parsePeriod(header,block,datedOnly));
|
|
81
|
+
else legacy.push(...block);
|
|
82
|
+
block = [];
|
|
83
|
+
}
|
|
84
|
+
const visibleBody = body.replace(/^\uFEFF/u,'').replace(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/u,'');
|
|
85
|
+
for (let line of visibleBody.split(/\r?\n/u)) {
|
|
86
|
+
if (!fence && (comment || /^ {0,3}<!--/u.test(line))) {
|
|
87
|
+
const end = line.indexOf('-->');
|
|
88
|
+
comment = end < 0;
|
|
89
|
+
if (comment) continue;
|
|
90
|
+
line = line.slice(end + 3);
|
|
91
|
+
if (!line.trim()) continue;
|
|
92
|
+
}
|
|
93
|
+
const fenceStart = /^\s*(\x60{3,}|~{3,})/u.exec(line);
|
|
94
|
+
if (fenceStart) {
|
|
95
|
+
if (!fence) fence = fenceStart[1];
|
|
96
|
+
else if (fenceStart[1][0] === fence[0] && fenceStart[1].length >= fence.length) fence = '';
|
|
97
|
+
block.push(line);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (!fence && line.startsWith('## ')) {
|
|
101
|
+
flush();
|
|
102
|
+
const match = dateTitle.exec(line.trim());
|
|
103
|
+
header = match && validDay(match[1]) && (!match[2] || validDay(match[2]) && match[2]>=match[1]) ? match : null;
|
|
104
|
+
if (!header) block.push(line);
|
|
105
|
+
} else if (header || block.length || !line.startsWith('# ')) block.push(line);
|
|
106
|
+
}
|
|
107
|
+
flush();
|
|
108
|
+
const occurrences = new Map();
|
|
109
|
+
for (const period of [...ranges].reverse()) {
|
|
110
|
+
const pair = (period.from ?? 'single') + '_' + period.to;
|
|
111
|
+
const number = (occurrences.get(pair) ?? 0) + 1;
|
|
112
|
+
occurrences.set(pair,number);
|
|
113
|
+
period.key = pair+'-'+number;
|
|
114
|
+
}
|
|
115
|
+
return {periods:ranges,legacy:legacy.join('\n').trim()};
|
|
116
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { isDeepStrictEqual, parseArgs } from 'node:util';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { digest, isId, requireThat, validateProjectFile, validateState } from './contract.mjs';
|
|
7
|
+
import { parseMarkdown } from './legacy-markdown.mjs';
|
|
8
|
+
import { openStore } from './storage.mjs';
|
|
9
|
+
|
|
10
|
+
const decode = bytes => new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
11
|
+
const stat = file => fs.lstatSync(file, { throwIfNoEntry: false });
|
|
12
|
+
|
|
13
|
+
function oldDirectory(root) {
|
|
14
|
+
let current = root;
|
|
15
|
+
for (const name of ['.agents', 'home', 'changelogs']) {
|
|
16
|
+
current = path.join(current, name);
|
|
17
|
+
const entry = stat(current);
|
|
18
|
+
if (!entry) return null;
|
|
19
|
+
requireThat(entry.isDirectory() && !entry.isSymbolicLink(), 'UNSAFE_PATH', '旧日志路径须为普通目录。');
|
|
20
|
+
}
|
|
21
|
+
return current;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readOld(root, name) {
|
|
25
|
+
const file = path.join(root, name);
|
|
26
|
+
const entry = stat(file);
|
|
27
|
+
requireThat(entry?.isFile() && !entry.isSymbolicLink(), 'MIGRATION_SOURCE', name+' 缺失或不是普通文件。');
|
|
28
|
+
const descriptor = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
|
|
29
|
+
try {
|
|
30
|
+
const opened = fs.fstatSync(descriptor);
|
|
31
|
+
requireThat(opened.isFile() && opened.ino === entry.ino, 'MIGRATION_SOURCE', name+' 在读取前已变化。');
|
|
32
|
+
const bytes = fs.readFileSync(descriptor);
|
|
33
|
+
requireThat(stat(file)?.ino === opened.ino, 'MIGRATION_SOURCE', name+' 在读取中已变化。');
|
|
34
|
+
return bytes;
|
|
35
|
+
} finally { fs.closeSync(descriptor); }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function convertProject(id, project, document) {
|
|
39
|
+
requireThat(!project.pending, 'LEGACY_PENDING', id+' 有旧版未完成写入,先用原版本 recover 后再迁移。');
|
|
40
|
+
const parsed = parseMarkdown(document);
|
|
41
|
+
const dated = parseMarkdown(document, { datedOnly:true });
|
|
42
|
+
const ranges = project.ranges.map((old, index) => {
|
|
43
|
+
const period = (old.ledger ? dated : parsed).periods[project.ranges.length - 1 - index];
|
|
44
|
+
const {from, to} = old.displayDates;
|
|
45
|
+
const baseline = ['baseline','rebaseline'].includes(old.kind);
|
|
46
|
+
const matches = period?.verified && period.to === to && period.commits === old.stats.rangeCommitCount
|
|
47
|
+
&& period.baseline === baseline && (period.from === from || (old.kind === 'full-history' && from === null));
|
|
48
|
+
requireThat(matches && parsed.periods.length === project.ranges.length, 'MIGRATION_SOURCE',
|
|
49
|
+
id+' 的旧日期段、任务数或提交数与成功区间不符,请先核对旧原件。');
|
|
50
|
+
const {revisionDocument, revisionRequest, ...range} = old;
|
|
51
|
+
if (old.ledger) {
|
|
52
|
+
const expected = old.ledger.tasks.map(t => [t.category,t.text,t.markers,{date:t.date,area:t.area}]);
|
|
53
|
+
const features = old.ledger.tasks.filter(task => task.category === '功能');
|
|
54
|
+
const added = features.every(task => typeof task.added === 'boolean') ? features.filter(task=>task.added).length : null;
|
|
55
|
+
requireThat(isDeepStrictEqual(expected, period.items) && period.added === added,
|
|
56
|
+
'MIGRATION_SOURCE', id+' 的旧正文、精确新增统计与任务元数据不一致。');
|
|
57
|
+
} else {
|
|
58
|
+
range.legacy = {entries:period.items.map(([category,text,markers]) => ({category,text,markers})), added:period.added};
|
|
59
|
+
}
|
|
60
|
+
const notes = [...period.notes];
|
|
61
|
+
if (old.kind === 'full-history' && from === null && period.from) notes.unshift('旧日志记载的区间起日为 '+period.from+'。');
|
|
62
|
+
if (notes.length) range.notes = notes;
|
|
63
|
+
return range;
|
|
64
|
+
});
|
|
65
|
+
const result = {schemaVersion:1,repoId:id,initialization:project.initialization,lastSuccessfulRangeId:project.lastSuccessfulRangeId,ranges};
|
|
66
|
+
const body = document.replace(/^\uFEFF/u,'').replace(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/u,'');
|
|
67
|
+
const title = body.match(/^\s*# ([^\r\n]+) 变更日志[ \t]*(?:\r?\n|$)/u)?.[1]?.trim();
|
|
68
|
+
if (title && title !== id) result.displayName = title;
|
|
69
|
+
if (parsed.legacy) result.notes = [parsed.legacy];
|
|
70
|
+
validateProjectFile(result,id);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function migrate(home, {apply = false, repoIds} = {}) {
|
|
75
|
+
requireThat(repoIds === undefined || Array.isArray(repoIds) && repoIds.every(isId),
|
|
76
|
+
'ARGUMENT', '迁移范围需要有效仓库 ID。');
|
|
77
|
+
const selected = id => !repoIds || repoIds.includes(id);
|
|
78
|
+
const store = openStore(home);
|
|
79
|
+
const root = oldDirectory(store.root);
|
|
80
|
+
if (root === null) return {status:'no-legacy', projects:[], unpaired:[]};
|
|
81
|
+
requireThat(!stat(path.join(root,'.state.lock')), 'LOCK_BUSY', '旧日志写入锁仍在,核实原操作后重试。');
|
|
82
|
+
const names = fs.readdirSync(root);
|
|
83
|
+
const markdown = names.filter(n => n.endsWith('.md') && isId(n.slice(0,-3)) && selected(n.slice(0,-3)));
|
|
84
|
+
if (!names.includes('state.json')) return {status:markdown.length?'unpaired':'no-legacy',projects:[],unpaired:markdown};
|
|
85
|
+
const bytes = readOld(root,'state.json');
|
|
86
|
+
const state = validateState(JSON.parse(decode(bytes)));
|
|
87
|
+
const prepared = Object.entries(state.projects).filter(([id]) => selected(id)).map(([id, project]) => {
|
|
88
|
+
const source = readOld(root,id+'.md');
|
|
89
|
+
const result = convertProject(id,project,decode(source));
|
|
90
|
+
const current = store.view(id).project;
|
|
91
|
+
requireThat(current === null || isDeepStrictEqual(current,result), 'PROJECT_EXISTS', id+' 已有不同的分仓 JSON,保留两个来源。');
|
|
92
|
+
return {id, result, revision:digest(source), exists:current !== null};
|
|
93
|
+
});
|
|
94
|
+
const unpaired = markdown.filter(n => !Object.hasOwn(state.projects,n.slice(0,-3)));
|
|
95
|
+
const projects = [];
|
|
96
|
+
for (const item of prepared) {
|
|
97
|
+
let status = item.exists ? 'already-saved' : 'ready';
|
|
98
|
+
if (apply) {
|
|
99
|
+
requireThat(oldDirectory(store.root) === root && !stat(path.join(root,'.state.lock'))
|
|
100
|
+
&& bytes.equals(readOld(root,'state.json')) && digest(readOld(root,item.id+'.md')) === item.revision,
|
|
101
|
+
'MIGRATION_SOURCE', '旧日志在迁移期间已变化,请重新核对。');
|
|
102
|
+
status = store.createProject(item.result).status;
|
|
103
|
+
}
|
|
104
|
+
projects.push({id:item.id, status, ranges:item.result.ranges.length,
|
|
105
|
+
tasks:item.result.ranges.reduce((sum,r) => sum + (r.ledger?.tasks ?? r.legacy.entries).length,0)});
|
|
106
|
+
}
|
|
107
|
+
return {status:apply?'migrated':'preview',projects,unpaired};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isDirectInvocation() {
|
|
111
|
+
if (!process.argv[1]) return false;
|
|
112
|
+
try { return fs.realpathSync.native(process.argv[1]) === fs.realpathSync.native(fileURLToPath(import.meta.url)); }
|
|
113
|
+
catch { return false; }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isDirectInvocation()) {
|
|
117
|
+
try {
|
|
118
|
+
const {values} = parseArgs({options:{home:{type:'string'},repo:{type:'string',multiple:true},apply:{type:'boolean'},help:{type:'boolean'}}});
|
|
119
|
+
if (values.help) console.log('node scripts/migrate.mjs --home HOME [--repo ID] [--apply]。默认预检,正式转换后保留旧原件。');
|
|
120
|
+
else console.log(JSON.stringify(migrate(values.home,{apply:values.apply,repoIds:values.repo}),null,2));
|
|
121
|
+
} catch (error) { console.error(JSON.stringify({status:'failed',code:error.code,message:error.message})); process.exitCode=1; }
|
|
122
|
+
}
|