@aitne/daemon 0.1.4 → 0.1.7
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/dist/adapters/notification-manager.d.ts +12 -0
- package/dist/adapters/notification-manager.d.ts.map +1 -1
- package/dist/adapters/notification-manager.js +39 -1
- package/dist/adapters/notification-manager.js.map +1 -1
- package/dist/api/routes/agent.d.ts.map +1 -1
- package/dist/api/routes/agent.js +7 -0
- package/dist/api/routes/agent.js.map +1 -1
- package/dist/api/routes/commands.d.ts.map +1 -1
- package/dist/api/routes/commands.js +16 -13
- package/dist/api/routes/commands.js.map +1 -1
- package/dist/api/routes/context.d.ts.map +1 -1
- package/dist/api/routes/context.js +13 -2
- package/dist/api/routes/context.js.map +1 -1
- package/dist/api/routes/dashboard.d.ts.map +1 -1
- package/dist/api/routes/dashboard.js +28 -0
- package/dist/api/routes/dashboard.js.map +1 -1
- package/dist/api/routes/fs.d.ts +23 -0
- package/dist/api/routes/fs.d.ts.map +1 -0
- package/dist/api/routes/fs.js +156 -0
- package/dist/api/routes/fs.js.map +1 -0
- package/dist/api/routes/fs.logic.d.ts +62 -0
- package/dist/api/routes/fs.logic.d.ts.map +1 -0
- package/dist/api/routes/fs.logic.js +137 -0
- package/dist/api/routes/fs.logic.js.map +1 -0
- package/dist/api/routes/health.d.ts.map +1 -1
- package/dist/api/routes/health.js +4 -2
- package/dist/api/routes/health.js.map +1 -1
- package/dist/api/routes/integrations.d.ts.map +1 -1
- package/dist/api/routes/integrations.js +8 -6
- package/dist/api/routes/integrations.js.map +1 -1
- package/dist/api/routes/metrics.d.ts +1 -0
- package/dist/api/routes/metrics.d.ts.map +1 -1
- package/dist/api/routes/metrics.js +24 -0
- package/dist/api/routes/metrics.js.map +1 -1
- package/dist/api/routes/observations.d.ts.map +1 -1
- package/dist/api/routes/observations.js +538 -25
- package/dist/api/routes/observations.js.map +1 -1
- package/dist/api/routes/skills.d.ts +9 -1
- package/dist/api/routes/skills.d.ts.map +1 -1
- package/dist/api/routes/skills.js +38 -16
- package/dist/api/routes/skills.js.map +1 -1
- package/dist/api/routes/wiki.d.ts +4 -0
- package/dist/api/routes/wiki.d.ts.map +1 -0
- package/dist/api/routes/wiki.js +1075 -0
- package/dist/api/routes/wiki.js.map +1 -0
- package/dist/api/server.d.ts +13 -0
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +27 -1
- package/dist/api/server.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +26 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-core.d.ts +25 -0
- package/dist/core/agent-core.d.ts.map +1 -1
- package/dist/core/agent-core.js.map +1 -1
- package/dist/core/backends/backend-router.d.ts +5 -1
- package/dist/core/backends/backend-router.d.ts.map +1 -1
- package/dist/core/backends/backend-router.js +10 -1
- package/dist/core/backends/backend-router.js.map +1 -1
- package/dist/core/backends/claude-code-core.d.ts.map +1 -1
- package/dist/core/backends/claude-code-core.js +62 -4
- package/dist/core/backends/claude-code-core.js.map +1 -1
- package/dist/core/backends/claude-tool-collection.d.ts +1 -1
- package/dist/core/backends/claude-tool-collection.d.ts.map +1 -1
- package/dist/core/backends/claude-tool-collection.js +327 -65
- package/dist/core/backends/claude-tool-collection.js.map +1 -1
- package/dist/core/backends/codex-core.d.ts.map +1 -1
- package/dist/core/backends/codex-core.js +36 -0
- package/dist/core/backends/codex-core.js.map +1 -1
- package/dist/core/backends/gemini-cli-core.d.ts +24 -5
- package/dist/core/backends/gemini-cli-core.d.ts.map +1 -1
- package/dist/core/backends/gemini-cli-core.js +62 -30
- package/dist/core/backends/gemini-cli-core.js.map +1 -1
- package/dist/core/backends/plan-presets.d.ts +3 -1
- package/dist/core/backends/plan-presets.d.ts.map +1 -1
- package/dist/core/backends/plan-presets.js +42 -2
- package/dist/core/backends/plan-presets.js.map +1 -1
- package/dist/core/bang-commands/commands-help.d.ts +5 -0
- package/dist/core/bang-commands/commands-help.d.ts.map +1 -0
- package/dist/core/bang-commands/commands-help.js +69 -0
- package/dist/core/bang-commands/commands-help.js.map +1 -0
- package/dist/core/bang-commands/commands-wiki.d.ts +75 -0
- package/dist/core/bang-commands/commands-wiki.d.ts.map +1 -0
- package/dist/core/bang-commands/commands-wiki.js +574 -0
- package/dist/core/bang-commands/commands-wiki.js.map +1 -0
- package/dist/core/bang-commands/index.d.ts +4 -2
- package/dist/core/bang-commands/index.d.ts.map +1 -1
- package/dist/core/bang-commands/index.js +15 -1
- package/dist/core/bang-commands/index.js.map +1 -1
- package/dist/core/bang-commands/registry.d.ts +47 -4
- package/dist/core/bang-commands/registry.d.ts.map +1 -1
- package/dist/core/bang-commands/registry.js +85 -15
- package/dist/core/bang-commands/registry.js.map +1 -1
- package/dist/core/context-builder.d.ts +17 -0
- package/dist/core/context-builder.d.ts.map +1 -1
- package/dist/core/context-builder.js +64 -6
- package/dist/core/context-builder.js.map +1 -1
- package/dist/core/daemon-api-cli.d.ts.map +1 -1
- package/dist/core/daemon-api-cli.js +50 -2
- package/dist/core/daemon-api-cli.js.map +1 -1
- package/dist/core/dispatcher-message-handler.d.ts.map +1 -1
- package/dist/core/dispatcher-message-handler.js +10 -0
- package/dist/core/dispatcher-message-handler.js.map +1 -1
- package/dist/core/dispatcher-morning-routine.d.ts.map +1 -1
- package/dist/core/dispatcher-morning-routine.js +17 -2
- package/dist/core/dispatcher-morning-routine.js.map +1 -1
- package/dist/core/dispatcher-result-processor.d.ts +23 -0
- package/dist/core/dispatcher-result-processor.d.ts.map +1 -1
- package/dist/core/dispatcher-result-processor.js +124 -5
- package/dist/core/dispatcher-result-processor.js.map +1 -1
- package/dist/core/dispatcher-scheduled-tasks.d.ts.map +1 -1
- package/dist/core/dispatcher-scheduled-tasks.js +114 -80
- package/dist/core/dispatcher-scheduled-tasks.js.map +1 -1
- package/dist/core/dispatcher-types.d.ts +116 -1
- package/dist/core/dispatcher-types.d.ts.map +1 -1
- package/dist/core/dispatcher-types.js.map +1 -1
- package/dist/core/dispatcher.d.ts +36 -0
- package/dist/core/dispatcher.d.ts.map +1 -1
- package/dist/core/dispatcher.js +94 -1
- package/dist/core/dispatcher.js.map +1 -1
- package/dist/core/integration-lifecycle.d.ts.map +1 -1
- package/dist/core/integration-lifecycle.js +6 -8
- package/dist/core/integration-lifecycle.js.map +1 -1
- package/dist/core/metrics.d.ts +127 -0
- package/dist/core/metrics.d.ts.map +1 -1
- package/dist/core/metrics.js +256 -1
- package/dist/core/metrics.js.map +1 -1
- package/dist/core/prompts.d.ts +2 -1
- package/dist/core/prompts.d.ts.map +1 -1
- package/dist/core/prompts.js +40 -0
- package/dist/core/prompts.js.map +1 -1
- package/dist/core/roadmap-validate.js +13 -1
- package/dist/core/roadmap-validate.js.map +1 -1
- package/dist/core/routine-acquisition-plan.d.ts +51 -0
- package/dist/core/routine-acquisition-plan.d.ts.map +1 -1
- package/dist/core/routine-acquisition-plan.js +111 -12
- package/dist/core/routine-acquisition-plan.js.map +1 -1
- package/dist/core/routine-fetch-window-retry.d.ts +109 -0
- package/dist/core/routine-fetch-window-retry.d.ts.map +1 -0
- package/dist/core/routine-fetch-window-retry.js +210 -0
- package/dist/core/routine-fetch-window-retry.js.map +1 -0
- package/dist/core/routine-fetch-window-runner.d.ts +258 -32
- package/dist/core/routine-fetch-window-runner.d.ts.map +1 -1
- package/dist/core/routine-fetch-window-runner.js +1115 -185
- package/dist/core/routine-fetch-window-runner.js.map +1 -1
- package/dist/core/routine-windows.d.ts +19 -4
- package/dist/core/routine-windows.d.ts.map +1 -1
- package/dist/core/routine-windows.js +47 -0
- package/dist/core/routine-windows.js.map +1 -1
- package/dist/core/scheduler.d.ts +50 -2
- package/dist/core/scheduler.d.ts.map +1 -1
- package/dist/core/scheduler.js +88 -7
- package/dist/core/scheduler.js.map +1 -1
- package/dist/core/skill-curation/declarations.d.ts.map +1 -1
- package/dist/core/skill-curation/declarations.js +11 -12
- package/dist/core/skill-curation/declarations.js.map +1 -1
- package/dist/core/skill-source-paths.d.ts +14 -0
- package/dist/core/skill-source-paths.d.ts.map +1 -0
- package/dist/core/skill-source-paths.js +82 -0
- package/dist/core/skill-source-paths.js.map +1 -0
- package/dist/core/skills-compiler.d.ts +18 -0
- package/dist/core/skills-compiler.d.ts.map +1 -1
- package/dist/core/skills-compiler.js +65 -18
- package/dist/core/skills-compiler.js.map +1 -1
- package/dist/core/skills-manifest.d.ts.map +1 -1
- package/dist/core/skills-manifest.js +46 -0
- package/dist/core/skills-manifest.js.map +1 -1
- package/dist/core/system-reset.d.ts +25 -0
- package/dist/core/system-reset.d.ts.map +1 -1
- package/dist/core/system-reset.js +47 -0
- package/dist/core/system-reset.js.map +1 -1
- package/dist/core/wiki/approval-queue.d.ts +31 -0
- package/dist/core/wiki/approval-queue.d.ts.map +1 -0
- package/dist/core/wiki/approval-queue.js +44 -0
- package/dist/core/wiki/approval-queue.js.map +1 -0
- package/dist/core/wiki/bridge.d.ts +74 -0
- package/dist/core/wiki/bridge.d.ts.map +1 -0
- package/dist/core/wiki/bridge.js +405 -0
- package/dist/core/wiki/bridge.js.map +1 -0
- package/dist/core/wiki/compile-lock.d.ts +42 -0
- package/dist/core/wiki/compile-lock.d.ts.map +1 -0
- package/dist/core/wiki/compile-lock.js +55 -0
- package/dist/core/wiki/compile-lock.js.map +1 -0
- package/dist/core/wiki/compile-preview.d.ts +8 -0
- package/dist/core/wiki/compile-preview.d.ts.map +1 -0
- package/dist/core/wiki/compile-preview.js +200 -0
- package/dist/core/wiki/compile-preview.js.map +1 -0
- package/dist/core/wiki/cost-estimate.d.ts +30 -0
- package/dist/core/wiki/cost-estimate.d.ts.map +1 -0
- package/dist/core/wiki/cost-estimate.js +243 -0
- package/dist/core/wiki/cost-estimate.js.map +1 -0
- package/dist/core/wiki/dispatcher.d.ts +48 -0
- package/dist/core/wiki/dispatcher.d.ts.map +1 -0
- package/dist/core/wiki/dispatcher.js +92 -0
- package/dist/core/wiki/dispatcher.js.map +1 -0
- package/dist/core/wiki/git-precompile.d.ts +86 -0
- package/dist/core/wiki/git-precompile.d.ts.map +1 -0
- package/dist/core/wiki/git-precompile.js +96 -0
- package/dist/core/wiki/git-precompile.js.map +1 -0
- package/dist/core/wiki/import-migrate.d.ts +38 -0
- package/dist/core/wiki/import-migrate.d.ts.map +1 -0
- package/dist/core/wiki/import-migrate.js +310 -0
- package/dist/core/wiki/import-migrate.js.map +1 -0
- package/dist/core/wiki/import-probe.d.ts +76 -0
- package/dist/core/wiki/import-probe.d.ts.map +1 -0
- package/dist/core/wiki/import-probe.js +245 -0
- package/dist/core/wiki/import-probe.js.map +1 -0
- package/dist/core/wiki/index-cache.d.ts +39 -0
- package/dist/core/wiki/index-cache.d.ts.map +1 -0
- package/dist/core/wiki/index-cache.js +152 -0
- package/dist/core/wiki/index-cache.js.map +1 -0
- package/dist/core/wiki/multi-url-dispatch.d.ts +52 -0
- package/dist/core/wiki/multi-url-dispatch.d.ts.map +1 -0
- package/dist/core/wiki/multi-url-dispatch.js +72 -0
- package/dist/core/wiki/multi-url-dispatch.js.map +1 -0
- package/dist/core/wiki/wiki-fts.d.ts +75 -0
- package/dist/core/wiki/wiki-fts.d.ts.map +1 -0
- package/dist/core/wiki/wiki-fts.js +265 -0
- package/dist/core/wiki/wiki-fts.js.map +1 -0
- package/dist/core/wiki/workspaces.d.ts +101 -0
- package/dist/core/wiki/workspaces.d.ts.map +1 -0
- package/dist/core/wiki/workspaces.js +352 -0
- package/dist/core/wiki/workspaces.js.map +1 -0
- package/dist/core/wiki/write-strategy.d.ts +70 -0
- package/dist/core/wiki/write-strategy.d.ts.map +1 -0
- package/dist/core/wiki/write-strategy.js +112 -0
- package/dist/core/wiki/write-strategy.js.map +1 -0
- package/dist/core/workdir.d.ts +8 -1
- package/dist/core/workdir.d.ts.map +1 -1
- package/dist/core/workdir.js +4 -1
- package/dist/core/workdir.js.map +1 -1
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +122 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/db/wiki-store.d.ts +3 -0
- package/dist/db/wiki-store.d.ts.map +1 -0
- package/dist/db/wiki-store.js +7 -0
- package/dist/db/wiki-store.js.map +1 -0
- package/dist/index.js +87 -4
- package/dist/index.js.map +1 -1
- package/dist/messaging/setup-welcome-dm.d.ts +30 -0
- package/dist/messaging/setup-welcome-dm.d.ts.map +1 -0
- package/dist/messaging/setup-welcome-dm.js +86 -0
- package/dist/messaging/setup-welcome-dm.js.map +1 -0
- package/dist/messaging/url-extract.d.ts +8 -0
- package/dist/messaging/url-extract.d.ts.map +1 -0
- package/dist/messaging/url-extract.js +41 -0
- package/dist/messaging/url-extract.js.map +1 -0
- package/dist/observers/delegated-sync-worker.d.ts +33 -25
- package/dist/observers/delegated-sync-worker.d.ts.map +1 -1
- package/dist/observers/delegated-sync-worker.js +38 -31
- package/dist/observers/delegated-sync-worker.js.map +1 -1
- package/dist/observers/imminent-event-scheduler.d.ts +20 -7
- package/dist/observers/imminent-event-scheduler.d.ts.map +1 -1
- package/dist/observers/imminent-event-scheduler.js +134 -29
- package/dist/observers/imminent-event-scheduler.js.map +1 -1
- package/dist/safety/always-disallowed.d.ts +65 -0
- package/dist/safety/always-disallowed.d.ts.map +1 -1
- package/dist/safety/always-disallowed.js +106 -10
- package/dist/safety/always-disallowed.js.map +1 -1
- package/dist/safety/audit.d.ts +46 -1
- package/dist/safety/audit.d.ts.map +1 -1
- package/dist/safety/audit.js +79 -16
- package/dist/safety/audit.js.map +1 -1
- package/dist/safety/risk-classifier.d.ts.map +1 -1
- package/dist/safety/risk-classifier.js +29 -0
- package/dist/safety/risk-classifier.js.map +1 -1
- package/dist/settings/runtime-settings.d.ts +12 -1
- package/dist/settings/runtime-settings.d.ts.map +1 -1
- package/dist/settings/runtime-settings.js +59 -1
- package/dist/settings/runtime-settings.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { WikiWorkspaceRow } from "./workspaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pre-compile git auto-commit for `!compile full` on external vaults.
|
|
4
|
+
*
|
|
5
|
+
* WIKI_BUILDER_DESIGN.md §P2.E / §14 Q5.
|
|
6
|
+
*
|
|
7
|
+
* Gate:
|
|
8
|
+
* - Internal-mode workspace → skip (NotApplicable). The
|
|
9
|
+
* `md_file_snapshots` mechanism is the recovery surface.
|
|
10
|
+
* - External, not a git repo → skip (NoBackup). The
|
|
11
|
+
* approval-gate DM tells the operator no git backup was taken.
|
|
12
|
+
* - External + git, `git_pre_compile_enabled = 0` → skip (Disabled).
|
|
13
|
+
* - External + git, dirty working tree → Refused. The bang
|
|
14
|
+
* handler is expected to abort with a DM telling the operator to
|
|
15
|
+
* commit/stash first; no agent session is spawned.
|
|
16
|
+
* - External + git, clean working tree → run `git add -A` +
|
|
17
|
+
* `git commit -m "aitne wiki: pre-compile snapshot <ts>"`. Operator
|
|
18
|
+
* hooks fire as normal (no `--no-verify`).
|
|
19
|
+
*/
|
|
20
|
+
export type GitPreCompileOutcome = {
|
|
21
|
+
status: "skipped";
|
|
22
|
+
reason: "internal_mode" | "no_git_repo" | "disabled";
|
|
23
|
+
} | {
|
|
24
|
+
status: "refused";
|
|
25
|
+
reason: "dirty_tree";
|
|
26
|
+
dirtyPaths: string[];
|
|
27
|
+
} | {
|
|
28
|
+
status: "committed";
|
|
29
|
+
commitSha: string;
|
|
30
|
+
commitMessage: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Preview shape — what a dry-run of the pre-compile gate would do without
|
|
34
|
+
* actually mutating git state. Mirrors `GitPreCompileOutcome` minus the
|
|
35
|
+
* `committed` arm, replacing it with `clean_would_commit`.
|
|
36
|
+
*
|
|
37
|
+
* Used by `GET /wiki/:ws/git/status` so the dashboard can render the
|
|
38
|
+
* "what would happen on `!compile full`" hint without creating empty
|
|
39
|
+
* commits on every poll. WIKI_BUILDER_DESIGN.md §P2.E.
|
|
40
|
+
*/
|
|
41
|
+
export type GitPreCompilePreview = {
|
|
42
|
+
status: "skipped";
|
|
43
|
+
reason: "internal_mode" | "no_git_repo" | "disabled";
|
|
44
|
+
} | {
|
|
45
|
+
status: "refused";
|
|
46
|
+
reason: "dirty_tree";
|
|
47
|
+
dirtyPaths: string[];
|
|
48
|
+
} | {
|
|
49
|
+
status: "clean_would_commit";
|
|
50
|
+
};
|
|
51
|
+
export interface GitPreCompileDeps {
|
|
52
|
+
/**
|
|
53
|
+
* Override the timestamp baked into the commit message. Tests pass a
|
|
54
|
+
* fixed string here; production callers leave it unset and the helper
|
|
55
|
+
* uses `new Date().toISOString()`.
|
|
56
|
+
*/
|
|
57
|
+
now?: () => Date;
|
|
58
|
+
/**
|
|
59
|
+
* Inject a custom `execFile`-compatible runner. Production code uses
|
|
60
|
+
* the node built-in; tests can stub it without monkey-patching the
|
|
61
|
+
* module. The signature matches `child_process.execFile`'s callback
|
|
62
|
+
* form via `promisify` — callers do not need to await the wrapped
|
|
63
|
+
* shape directly.
|
|
64
|
+
*/
|
|
65
|
+
run?: (file: string, args: string[], options?: {
|
|
66
|
+
cwd?: string;
|
|
67
|
+
timeout?: number;
|
|
68
|
+
}) => Promise<{
|
|
69
|
+
stdout: string;
|
|
70
|
+
stderr: string;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pure read of the pre-compile gate state — never mutates the git working
|
|
75
|
+
* tree. Returns the same `skipped` / `refused` arms as the mutating
|
|
76
|
+
* `runGitPreCompile`, plus a `clean_would_commit` arm in place of the
|
|
77
|
+
* mutating `committed` arm.
|
|
78
|
+
*
|
|
79
|
+
* Use this on dashboard GETs and on the `!compile full` decision pass so
|
|
80
|
+
* the actual commit is deferred until the path that *will* run the agent
|
|
81
|
+
* session decides to proceed.
|
|
82
|
+
*/
|
|
83
|
+
export declare function previewGitPreCompile(workspace: WikiWorkspaceRow, deps?: GitPreCompileDeps): Promise<GitPreCompilePreview>;
|
|
84
|
+
export declare function runGitPreCompile(workspace: WikiWorkspaceRow, deps?: GitPreCompileDeps): Promise<GitPreCompileOutcome>;
|
|
85
|
+
export declare function isGitRepo(rootPath: string): boolean;
|
|
86
|
+
//# sourceMappingURL=git-precompile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-precompile.d.ts","sourceRoot":"","sources":["../../../src/core/wiki/git-precompile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKxD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,eAAe,GAAG,aAAa,GAAG,UAAU,CAAA;CAAE,GAC3E;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,GACjE;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,eAAe,GAAG,aAAa,GAAG,UAAU,CAAA;CAAE,GAC3E;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,GACjE;IAAE,MAAM,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAErC,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,CACJ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KACzC,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,gBAAgB,EAC3B,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAgB/B;AAED,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,gBAAgB,EAC3B,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAiC/B;AA4BD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CASnD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync, statSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { createLogger } from "../../logging.js";
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
const logger = createLogger("wiki-git-precompile");
|
|
8
|
+
/**
|
|
9
|
+
* Pure read of the pre-compile gate state — never mutates the git working
|
|
10
|
+
* tree. Returns the same `skipped` / `refused` arms as the mutating
|
|
11
|
+
* `runGitPreCompile`, plus a `clean_would_commit` arm in place of the
|
|
12
|
+
* mutating `committed` arm.
|
|
13
|
+
*
|
|
14
|
+
* Use this on dashboard GETs and on the `!compile full` decision pass so
|
|
15
|
+
* the actual commit is deferred until the path that *will* run the agent
|
|
16
|
+
* session decides to proceed.
|
|
17
|
+
*/
|
|
18
|
+
export async function previewGitPreCompile(workspace, deps = {}) {
|
|
19
|
+
if (workspace.kind !== "external") {
|
|
20
|
+
return { status: "skipped", reason: "internal_mode" };
|
|
21
|
+
}
|
|
22
|
+
if (!isGitRepo(workspace.root_path)) {
|
|
23
|
+
return { status: "skipped", reason: "no_git_repo" };
|
|
24
|
+
}
|
|
25
|
+
if (workspace.git_pre_compile_enabled !== 1) {
|
|
26
|
+
return { status: "skipped", reason: "disabled" };
|
|
27
|
+
}
|
|
28
|
+
const dirtyPaths = await readDirtyPaths(workspace, deps);
|
|
29
|
+
if (dirtyPaths.length > 0) {
|
|
30
|
+
return { status: "refused", reason: "dirty_tree", dirtyPaths };
|
|
31
|
+
}
|
|
32
|
+
return { status: "clean_would_commit" };
|
|
33
|
+
}
|
|
34
|
+
export async function runGitPreCompile(workspace, deps = {}) {
|
|
35
|
+
const preview = await previewGitPreCompile(workspace, deps);
|
|
36
|
+
if (preview.status !== "clean_would_commit") {
|
|
37
|
+
return preview;
|
|
38
|
+
}
|
|
39
|
+
const run = deps.run ?? defaultRun;
|
|
40
|
+
const root = workspace.root_path;
|
|
41
|
+
const now = (deps.now ?? (() => new Date()))().toISOString();
|
|
42
|
+
const commitMessage = `aitne wiki: pre-compile snapshot ${now}`;
|
|
43
|
+
await run("git", ["-C", root, "add", "-A"], { timeout: 30_000 });
|
|
44
|
+
await run("git", [
|
|
45
|
+
"-C",
|
|
46
|
+
root,
|
|
47
|
+
"commit",
|
|
48
|
+
"--allow-empty",
|
|
49
|
+
"-m",
|
|
50
|
+
commitMessage,
|
|
51
|
+
], { timeout: 30_000 });
|
|
52
|
+
const sha = await run("git", ["-C", root, "rev-parse", "HEAD"], {
|
|
53
|
+
timeout: 5_000,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
status: "committed",
|
|
57
|
+
commitSha: sha.stdout.trim(),
|
|
58
|
+
commitMessage,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function readDirtyPaths(workspace, deps) {
|
|
62
|
+
const run = deps.run ?? defaultRun;
|
|
63
|
+
const statusOut = await run("git", ["-C", workspace.root_path, "status", "--porcelain"], { timeout: 10_000 }).catch((err) => {
|
|
64
|
+
logger.warn({ workspace: workspace.name, err: err instanceof Error ? err.message : String(err) }, "wiki git pre-compile: status check failed — treating as dirty for safety");
|
|
65
|
+
return { stdout: "?? git-status-failed", stderr: "" };
|
|
66
|
+
});
|
|
67
|
+
// Porcelain output is exactly "XY <path>" — two status chars + space.
|
|
68
|
+
// Do NOT pre-trim because trimming would eat the leading space for the
|
|
69
|
+
// single-column statuses (`?? newfile`, ` M tracked-edit`) and chop the
|
|
70
|
+
// first letter of the filename.
|
|
71
|
+
return statusOut.stdout
|
|
72
|
+
.split("\n")
|
|
73
|
+
.filter((line) => line.length > 0)
|
|
74
|
+
.map((line) => line.slice(3));
|
|
75
|
+
}
|
|
76
|
+
export function isGitRepo(rootPath) {
|
|
77
|
+
const gitDir = join(rootPath, ".git");
|
|
78
|
+
if (!existsSync(gitDir))
|
|
79
|
+
return false;
|
|
80
|
+
try {
|
|
81
|
+
const stat = statSync(gitDir);
|
|
82
|
+
return stat.isDirectory() || stat.isFile();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function defaultRun(file, args, options) {
|
|
89
|
+
const { stdout, stderr } = await execFileAsync(file, args, {
|
|
90
|
+
timeout: options?.timeout ?? 10_000,
|
|
91
|
+
cwd: options?.cwd,
|
|
92
|
+
windowsHide: true,
|
|
93
|
+
});
|
|
94
|
+
return { stdout, stderr };
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=git-precompile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-precompile.js","sourceRoot":"","sources":["../../../src/core/wiki/git-precompile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC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Migration {
|
|
2
|
+
path: string;
|
|
3
|
+
renames: Array<{
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export interface FlattenMove {
|
|
9
|
+
fromRelPath: string;
|
|
10
|
+
toRelPath: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SlugConflict {
|
|
13
|
+
layer: "10_raw" | "20_wiki";
|
|
14
|
+
slug: string;
|
|
15
|
+
paths: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface WikiImportMigrationPlan {
|
|
18
|
+
rootPath: string;
|
|
19
|
+
frontmatterMigrations: FrontmatterMigration[];
|
|
20
|
+
flattenMoves: FlattenMove[];
|
|
21
|
+
conflicts: SlugConflict[];
|
|
22
|
+
estimatedBackupBytes: number;
|
|
23
|
+
generatedAtIso: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ApplyImportMigrationResult {
|
|
26
|
+
backupDir: string;
|
|
27
|
+
filesWritten: number;
|
|
28
|
+
filesMoved: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function planImportMigration(rootPath: string): WikiImportMigrationPlan;
|
|
31
|
+
export interface ApplyMigrationOptions {
|
|
32
|
+
/** ISO date used to name the backup directory. */
|
|
33
|
+
dateStamp?: string;
|
|
34
|
+
/** Skip the conflict guard. Use only when the wizard explicitly chose to overwrite. */
|
|
35
|
+
allowConflicts?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function applyImportMigration(plan: WikiImportMigrationPlan, options?: ApplyMigrationOptions): ApplyImportMigrationResult;
|
|
38
|
+
//# sourceMappingURL=import-migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-migrate.d.ts","sourceRoot":"","sources":["../../../src/core/wiki/import-migrate.ts"],"names":[],"mappings":"AA2EA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;IAC9C,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,uBAAuB,CA6B7E;AAED,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,uBAAuB,EAC7B,OAAO,GAAE,qBAA0B,GAClC,0BAA0B,CA2C5B"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, } from "node:fs";
|
|
2
|
+
import { dirname, join, relative } from "node:path";
|
|
3
|
+
import { writeFileAtomically } from "../atomic-write.js";
|
|
4
|
+
import { extractFrontmatter } from "./import-probe.js";
|
|
5
|
+
/**
|
|
6
|
+
* Import-migrate — WIKI_BUILDER_DESIGN.md §7 (Migrate branch).
|
|
7
|
+
*
|
|
8
|
+
* Two-step operation:
|
|
9
|
+
* 1. `planImportMigration(rootPath)` — pure inspection. Returns the list
|
|
10
|
+
* of files that would be rewritten, the frontmatter-key mappings,
|
|
11
|
+
* and the subdirectory flattening moves. **Never touches disk.**
|
|
12
|
+
* The dashboard renders the plan as the user-facing preview.
|
|
13
|
+
* 2. `applyImportMigration(rootPath, plan, opts)` — executes the plan.
|
|
14
|
+
* Always writes a sibling backup mirror under
|
|
15
|
+
* `90_meta/health/pre-migrate-<date>/` before touching any file
|
|
16
|
+
* (the per-vault `git` backup is layered on top by §P2.E for git
|
|
17
|
+
* vaults; this mirror is the always-available recovery surface for
|
|
18
|
+
* non-git vaults).
|
|
19
|
+
*
|
|
20
|
+
* Migrations supported in P2:
|
|
21
|
+
* - Flatten type-based subdirectories under `20_wiki/<type>/<slug>.md`
|
|
22
|
+
* → `20_wiki/<slug>.md`, preserving the `type:` frontmatter (which
|
|
23
|
+
* stays the discriminator, per §2.4 Bases-era convention).
|
|
24
|
+
* - Flatten subdirectories under `10_raw/<topic>/<slug>.md` →
|
|
25
|
+
* `10_raw/<slug>.md`. The `images/<slug>/` subdirectory is the only
|
|
26
|
+
* permitted nested layout (§2.3) and is preserved as-is.
|
|
27
|
+
* - Frontmatter key rename for any keys that map cleanly between the
|
|
28
|
+
* two schema flavours. Unknown keys are passed through untouched —
|
|
29
|
+
* `wiki.lint` is the long-term enforcer; the migration is a one-shot
|
|
30
|
+
* best effort.
|
|
31
|
+
*
|
|
32
|
+
* Slug collisions during flattening are reported in the plan as
|
|
33
|
+
* `conflicts` and the migration refuses to apply until the wizard
|
|
34
|
+
* surfaces them and the operator chooses how to resolve.
|
|
35
|
+
*
|
|
36
|
+
* **Known limitation — iCloud-sandboxed external vaults**: this module
|
|
37
|
+
* uses `renameSync` and direct `writeFileAtomically` for moves and
|
|
38
|
+
* rewrites. Both fail with EPERM on iCloud-sandboxed paths, and the
|
|
39
|
+
* Obsidian CLI (which the runtime write path falls back to for normal
|
|
40
|
+
* file writes) does not expose a `rename` primitive — there is no
|
|
41
|
+
* equivalent fallback to route a move through. Callers running the
|
|
42
|
+
* import flow against an iCloud vault must temporarily relocate it
|
|
43
|
+
* outside the sandbox, run the migration, and move it back. The wizard
|
|
44
|
+
* surfaces this in the troubleshooting guide; the API call itself just
|
|
45
|
+
* propagates the EPERM upstream.
|
|
46
|
+
*/
|
|
47
|
+
const KEY_RENAMES_RAW = {
|
|
48
|
+
// Common renames observed in pre-Aitne LLM-wiki implementations.
|
|
49
|
+
source_url: "url",
|
|
50
|
+
retrieved_at: "captured_at",
|
|
51
|
+
fetched_at: "captured_at",
|
|
52
|
+
};
|
|
53
|
+
const KEY_RENAMES_WIKI = {
|
|
54
|
+
topic: "title",
|
|
55
|
+
kind: "type",
|
|
56
|
+
state: "status",
|
|
57
|
+
last_compiled: "compiled_at",
|
|
58
|
+
};
|
|
59
|
+
const KEY_RENAMES_OUTPUT = {
|
|
60
|
+
asked_at: "generated_at",
|
|
61
|
+
refs: "sources",
|
|
62
|
+
answer_to: "question",
|
|
63
|
+
};
|
|
64
|
+
export function planImportMigration(rootPath) {
|
|
65
|
+
const flattenMoves = [];
|
|
66
|
+
const conflicts = [];
|
|
67
|
+
collectFlattenMoves(rootPath, "20_wiki", flattenMoves, conflicts);
|
|
68
|
+
collectFlattenMoves(rootPath, "10_raw", flattenMoves, conflicts);
|
|
69
|
+
const frontmatterMigrations = collectFrontmatterMigrations(rootPath, flattenMoves);
|
|
70
|
+
const estimatedBackupBytes = estimateBytes(rootPath, flattenMoves.map((move) => move.fromRelPath)) +
|
|
71
|
+
estimateBytes(rootPath, frontmatterMigrations.map((m) => m.path));
|
|
72
|
+
return {
|
|
73
|
+
rootPath,
|
|
74
|
+
frontmatterMigrations,
|
|
75
|
+
flattenMoves,
|
|
76
|
+
conflicts,
|
|
77
|
+
estimatedBackupBytes,
|
|
78
|
+
generatedAtIso: new Date().toISOString(),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function applyImportMigration(plan, options = {}) {
|
|
82
|
+
if (plan.conflicts.length > 0 && !options.allowConflicts) {
|
|
83
|
+
throw Object.assign(new Error(`import-migrate: ${plan.conflicts.length} slug collision(s) detected — resolve them in the wizard before applying.`), { code: "EWIKI_IMPORT_CONFLICT" });
|
|
84
|
+
}
|
|
85
|
+
const dateStamp = options.dateStamp ?? new Date().toISOString().slice(0, 10);
|
|
86
|
+
const backupDir = join(plan.rootPath, "90_meta", "health", `pre-migrate-${dateStamp}`);
|
|
87
|
+
mkdirSync(backupDir, { recursive: true });
|
|
88
|
+
let filesWritten = 0;
|
|
89
|
+
let filesMoved = 0;
|
|
90
|
+
for (const move of plan.flattenMoves) {
|
|
91
|
+
const from = join(plan.rootPath, move.fromRelPath);
|
|
92
|
+
const to = join(plan.rootPath, move.toRelPath);
|
|
93
|
+
backupFile(plan.rootPath, move.fromRelPath, backupDir);
|
|
94
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
95
|
+
renameSync(from, to);
|
|
96
|
+
filesMoved += 1;
|
|
97
|
+
}
|
|
98
|
+
for (const migration of plan.frontmatterMigrations) {
|
|
99
|
+
const fullPath = join(plan.rootPath, migration.path);
|
|
100
|
+
backupFile(plan.rootPath, migration.path, backupDir);
|
|
101
|
+
const original = readFileSafely(fullPath);
|
|
102
|
+
const rewritten = applyFrontmatterRenames(original, migration.renames);
|
|
103
|
+
if (rewritten !== original) {
|
|
104
|
+
writeFileAtomically(fullPath, rewritten);
|
|
105
|
+
filesWritten += 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
writeImportReport(plan.rootPath, dateStamp, plan, {
|
|
109
|
+
filesWritten,
|
|
110
|
+
filesMoved,
|
|
111
|
+
backupDir,
|
|
112
|
+
});
|
|
113
|
+
return { backupDir, filesWritten, filesMoved };
|
|
114
|
+
}
|
|
115
|
+
function collectFlattenMoves(rootPath, layer, moves, conflicts) {
|
|
116
|
+
const dir = join(rootPath, layer);
|
|
117
|
+
if (!existsSync(dir))
|
|
118
|
+
return;
|
|
119
|
+
const seenSlugs = new Map();
|
|
120
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
121
|
+
if (!entry.isDirectory())
|
|
122
|
+
continue;
|
|
123
|
+
if (layer === "10_raw" && entry.name === "images")
|
|
124
|
+
continue;
|
|
125
|
+
const subPath = join(dir, entry.name);
|
|
126
|
+
for (const md of readMarkdownChildren(subPath)) {
|
|
127
|
+
const fromRel = `${layer}/${entry.name}/${md}`;
|
|
128
|
+
const toRel = `${layer}/${md}`;
|
|
129
|
+
moves.push({ fromRelPath: fromRel, toRelPath: toRel });
|
|
130
|
+
const existing = seenSlugs.get(toRel) ?? [];
|
|
131
|
+
existing.push(fromRel);
|
|
132
|
+
seenSlugs.set(toRel, existing);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Any slug also living at the layer root would conflict with a move.
|
|
136
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
137
|
+
if (!entry.isFile() || !entry.name.endsWith(".md"))
|
|
138
|
+
continue;
|
|
139
|
+
const rootRel = `${layer}/${entry.name}`;
|
|
140
|
+
if (seenSlugs.has(rootRel)) {
|
|
141
|
+
seenSlugs.get(rootRel)?.push(rootRel);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const [toRel, sources] of seenSlugs) {
|
|
145
|
+
if (sources.length > 1) {
|
|
146
|
+
conflicts.push({
|
|
147
|
+
layer,
|
|
148
|
+
slug: toRel.split("/").pop() ?? toRel,
|
|
149
|
+
paths: sources,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function* readMarkdownChildren(dir) {
|
|
155
|
+
if (!existsSync(dir))
|
|
156
|
+
return;
|
|
157
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
158
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
159
|
+
yield entry.name;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function collectFrontmatterMigrations(rootPath, moves) {
|
|
164
|
+
const out = [];
|
|
165
|
+
const moveByFrom = new Map(moves.map((move) => [move.fromRelPath, move.toRelPath]));
|
|
166
|
+
for (const layer of ["10_raw", "20_wiki", "30_outputs"]) {
|
|
167
|
+
const dir = join(rootPath, layer);
|
|
168
|
+
if (!existsSync(dir))
|
|
169
|
+
continue;
|
|
170
|
+
const renameMap = renameMapForLayer(layer);
|
|
171
|
+
// Inspect the file at its *current* on-disk location so the
|
|
172
|
+
// frontmatter scan sees real bytes. The recorded `path` in the
|
|
173
|
+
// returned plan is the post-flatten location — that is where the
|
|
174
|
+
// rewrite step will look after `renameSync` has run.
|
|
175
|
+
for (const currentAbs of iterateLayerMarkdownOnDisk(rootPath, layer)) {
|
|
176
|
+
const content = readFileSafely(currentAbs);
|
|
177
|
+
const fm = extractFrontmatter(content);
|
|
178
|
+
if (!fm)
|
|
179
|
+
continue;
|
|
180
|
+
const renames = [];
|
|
181
|
+
for (const [from, to] of Object.entries(renameMap)) {
|
|
182
|
+
if (Object.prototype.hasOwnProperty.call(fm, from)) {
|
|
183
|
+
renames.push({ from, to });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (renames.length === 0)
|
|
187
|
+
continue;
|
|
188
|
+
const currentRel = relative(rootPath, currentAbs).split(/[\\/]/).join("/");
|
|
189
|
+
const postMoveRel = moveByFrom.get(currentRel) ?? currentRel;
|
|
190
|
+
out.push({ path: postMoveRel, renames });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
function* iterateLayerMarkdownOnDisk(rootPath, layer) {
|
|
196
|
+
const dir = join(rootPath, layer);
|
|
197
|
+
if (!existsSync(dir))
|
|
198
|
+
return;
|
|
199
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
200
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
201
|
+
yield join(dir, entry.name);
|
|
202
|
+
}
|
|
203
|
+
else if (entry.isDirectory()) {
|
|
204
|
+
if (layer === "10_raw" && entry.name === "images")
|
|
205
|
+
continue;
|
|
206
|
+
const sub = join(dir, entry.name);
|
|
207
|
+
for (const md of readdirSync(sub, { withFileTypes: true })) {
|
|
208
|
+
if (md.isFile() && md.name.endsWith(".md")) {
|
|
209
|
+
yield join(sub, md.name);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function renameMapForLayer(layer) {
|
|
216
|
+
switch (layer) {
|
|
217
|
+
case "10_raw":
|
|
218
|
+
return KEY_RENAMES_RAW;
|
|
219
|
+
case "20_wiki":
|
|
220
|
+
return KEY_RENAMES_WIKI;
|
|
221
|
+
case "30_outputs":
|
|
222
|
+
return KEY_RENAMES_OUTPUT;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function applyFrontmatterRenames(content, renames) {
|
|
226
|
+
if (renames.length === 0)
|
|
227
|
+
return content;
|
|
228
|
+
const delim = "---";
|
|
229
|
+
if (!content.startsWith(delim))
|
|
230
|
+
return content;
|
|
231
|
+
const lines = content.split(/\r?\n/);
|
|
232
|
+
const endIdx = lines.findIndex((line, idx) => idx > 0 && line === delim);
|
|
233
|
+
if (endIdx < 0)
|
|
234
|
+
return content;
|
|
235
|
+
const renameByFrom = new Map(renames.map((r) => [r.from, r.to]));
|
|
236
|
+
for (let i = 1; i < endIdx; i += 1) {
|
|
237
|
+
const match = /^([A-Za-z_][A-Za-z0-9_-]*)(\s*:\s*.*)$/.exec(lines[i]);
|
|
238
|
+
if (!match)
|
|
239
|
+
continue;
|
|
240
|
+
const [, key, rest] = match;
|
|
241
|
+
const replacement = renameByFrom.get(key);
|
|
242
|
+
if (!replacement)
|
|
243
|
+
continue;
|
|
244
|
+
lines[i] = `${replacement}${rest}`;
|
|
245
|
+
}
|
|
246
|
+
return lines.join("\n");
|
|
247
|
+
}
|
|
248
|
+
function readFileSafely(path) {
|
|
249
|
+
try {
|
|
250
|
+
return readFileSync(path, "utf-8");
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return "";
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function estimateBytes(rootPath, relPaths) {
|
|
257
|
+
let total = 0;
|
|
258
|
+
for (const rel of relPaths) {
|
|
259
|
+
const full = join(rootPath, rel);
|
|
260
|
+
try {
|
|
261
|
+
total += statSync(full).size;
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
/* skip — file already moved by an earlier step */
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return total;
|
|
268
|
+
}
|
|
269
|
+
function backupFile(rootPath, relPath, backupDir) {
|
|
270
|
+
const src = join(rootPath, relPath);
|
|
271
|
+
if (!existsSync(src))
|
|
272
|
+
return;
|
|
273
|
+
const dest = join(backupDir, relPath);
|
|
274
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
275
|
+
writeFileAtomically(dest, readFileSync(src, "utf-8"));
|
|
276
|
+
}
|
|
277
|
+
function writeImportReport(rootPath, dateStamp, plan, outcome) {
|
|
278
|
+
const reportPath = join(rootPath, "90_meta", "health", `import-${dateStamp}.md`);
|
|
279
|
+
const lines = [
|
|
280
|
+
`# Wiki Import Report — ${dateStamp}`,
|
|
281
|
+
"",
|
|
282
|
+
`- Generated: ${plan.generatedAtIso}`,
|
|
283
|
+
`- Backup directory: \`${relative(rootPath, outcome.backupDir).split(/[\\/]/).join("/")}\``,
|
|
284
|
+
`- Files written (frontmatter rewrite): ${outcome.filesWritten}`,
|
|
285
|
+
`- Files moved (flatten): ${outcome.filesMoved}`,
|
|
286
|
+
"",
|
|
287
|
+
"## Frontmatter migrations",
|
|
288
|
+
"",
|
|
289
|
+
...(plan.frontmatterMigrations.length === 0
|
|
290
|
+
? ["_None._"]
|
|
291
|
+
: plan.frontmatterMigrations.map((m) => `- \`${m.path}\` — ${m.renames
|
|
292
|
+
.map((r) => `\`${r.from}\` → \`${r.to}\``)
|
|
293
|
+
.join(", ")}`)),
|
|
294
|
+
"",
|
|
295
|
+
"## Flatten moves",
|
|
296
|
+
"",
|
|
297
|
+
...(plan.flattenMoves.length === 0
|
|
298
|
+
? ["_None._"]
|
|
299
|
+
: plan.flattenMoves.map((m) => `- \`${m.fromRelPath}\` → \`${m.toRelPath}\``)),
|
|
300
|
+
"",
|
|
301
|
+
"## Slug conflicts (resolved during apply)",
|
|
302
|
+
"",
|
|
303
|
+
...(plan.conflicts.length === 0
|
|
304
|
+
? ["_None._"]
|
|
305
|
+
: plan.conflicts.map((c) => `- ${c.layer} \`${c.slug}\` — ${c.paths.map((p) => `\`${p}\``).join(", ")}`)),
|
|
306
|
+
"",
|
|
307
|
+
];
|
|
308
|
+
writeFileAtomically(reportPath, lines.join("\n"));
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=import-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-migrate.js","sourceRoot":"","sources":["../../../src/core/wiki/import-migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,MAAM,eAAe,GAA2B;IAC9C,iEAAiE;IACjE,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,aAAa;IAC3B,UAAU,EAAE,aAAa;CAC1B,CAAC;AAEF,MAAM,gBAAgB,GAA2B;IAC/C,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,KAAK,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M,KAAK,CAAC;YAChC,CAAC,CAAC,CAAC,SAAS,CAAC;YACb,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC1B,OAAO,CAAC,CAAC,WAAW,UAAU,CAAC,CAAC,SAAS,IAAI,CAC9C,CAAC;QACN,EAAE;QACF,2CAA2C;QAC3C,EAAE;QACF,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YAC7B,CAAC,CAAC,CAAC,SAAS,CAAC;YACb,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACvB,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC5E,CAAC;QACN,EAAE;KACH,CAAC;IACF,mBAAmB,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Existing-vault import probe — WIKI_BUILDER_DESIGN.md §7.
|
|
3
|
+
*
|
|
4
|
+
* Called by the setup wizard against a candidate `external` mode root
|
|
5
|
+
* path BEFORE the workspace row is created. The probe is read-only:
|
|
6
|
+
* it never modifies files on disk. Its job is to classify the vault
|
|
7
|
+
* (empty, partial-LLM-Wiki, full-LLM-Wiki, foreign) and surface the
|
|
8
|
+
* data the wizard needs to render the Adopt / Migrate / Split choice.
|
|
9
|
+
*
|
|
10
|
+
* Contract:
|
|
11
|
+
* - Returns `kind: "empty"` when the root has no markdown files under any
|
|
12
|
+
* of the layered directories. The wizard then offers "Initialise empty
|
|
13
|
+
* vault" rather than the Adopt/Migrate/Split branching.
|
|
14
|
+
* - Returns `kind: "partial"` when fewer than two of the canonical layer
|
|
15
|
+
* directories exist. The wizard nudges the owner to inspect the dir
|
|
16
|
+
* before continuing — likely a foreign vault we should not touch.
|
|
17
|
+
* - Returns `kind: "wiki"` when two or more layer directories exist. The
|
|
18
|
+
* wizard then surfaces the schema/layout deltas and the Adopt /
|
|
19
|
+
* Migrate / Split decision.
|
|
20
|
+
*
|
|
21
|
+
* The probe deliberately rejects layouts where any layer directory is a
|
|
22
|
+
* symlink — refusing the import is the safe default and matches the
|
|
23
|
+
* defensive posture taken by `writeFileAtomically`.
|
|
24
|
+
*/
|
|
25
|
+
export type WikiImportKind = "empty" | "partial" | "wiki";
|
|
26
|
+
declare const LAYER_DIRS: readonly ["00_inbox", "10_raw", "20_wiki", "30_outputs", "90_meta"];
|
|
27
|
+
type LayerDir = (typeof LAYER_DIRS)[number];
|
|
28
|
+
export interface LayerInventory {
|
|
29
|
+
dir: LayerDir;
|
|
30
|
+
exists: boolean;
|
|
31
|
+
isSymlink: boolean;
|
|
32
|
+
fileCount: number;
|
|
33
|
+
subdirectories: string[];
|
|
34
|
+
lastModifiedAt: string | null;
|
|
35
|
+
}
|
|
36
|
+
export interface SchemaDelta {
|
|
37
|
+
schema: "raw" | "wiki" | "output";
|
|
38
|
+
present: boolean;
|
|
39
|
+
expectedKeys: string[];
|
|
40
|
+
foundKeys: string[];
|
|
41
|
+
missingKeys: string[];
|
|
42
|
+
extraKeys: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface WikiImportProbeResult {
|
|
45
|
+
rootPath: string;
|
|
46
|
+
kind: WikiImportKind;
|
|
47
|
+
layers: LayerInventory[];
|
|
48
|
+
schemas: SchemaDelta[];
|
|
49
|
+
/**
|
|
50
|
+
* Top values of the `type:` frontmatter property across the vault.
|
|
51
|
+
* Used by the wizard to preview the existing taxonomy.
|
|
52
|
+
*/
|
|
53
|
+
topTypes: Array<{
|
|
54
|
+
value: string;
|
|
55
|
+
count: number;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Detected nested layout (e.g. `20_wiki/concepts/`). Aitne is flat;
|
|
59
|
+
* the wizard offers to flatten as part of Migrate mode.
|
|
60
|
+
*/
|
|
61
|
+
unexpectedSubdirectories: Array<{
|
|
62
|
+
layer: LayerDir;
|
|
63
|
+
subdir: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** Whether `90_meta/taxonomy.md` exists. */
|
|
66
|
+
taxonomyPresent: boolean;
|
|
67
|
+
/** Whether `20_wiki/_index.md` exists. */
|
|
68
|
+
indexPresent: boolean;
|
|
69
|
+
/** Whether the root is a git repository (used by the precompile gate). */
|
|
70
|
+
isGitRepo: boolean;
|
|
71
|
+
}
|
|
72
|
+
export declare function probeExistingWikiVault(rootPath: string): WikiImportProbeResult;
|
|
73
|
+
export declare function extractFrontmatter(content: string): Record<string, string> | null;
|
|
74
|
+
export declare function formatProbeRelativePath(rootPath: string, abs: string): string;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=import-probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-probe.d.ts","sourceRoot":"","sources":["../../../src/core/wiki/import-probe.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1D,QAAA,MAAM,UAAU,qEAAsE,CAAC;AACvF,KAAK,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAQ5C,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,QAAQ,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,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