@wjarka/cezarion 0.17.0-dev.5429 → 0.17.0-dev.5440

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/ci-wait/controller.d.ts +37 -37
  2. package/dist/delegation/routes.d.ts +62 -62
  3. package/dist/delegation/workspace.d.ts +7 -0
  4. package/dist/delegation/workspace.js +26 -4
  5. package/dist/delegation/workspace.js.map +1 -1
  6. package/dist/project-migration/durable.d.ts +25 -0
  7. package/dist/project-migration/durable.js +69 -0
  8. package/dist/project-migration/durable.js.map +1 -0
  9. package/dist/project-migration/engine.d.ts +47 -0
  10. package/dist/project-migration/engine.js +95 -0
  11. package/dist/project-migration/engine.js.map +1 -0
  12. package/dist/project-migration/journal.d.ts +137 -0
  13. package/dist/project-migration/journal.js +68 -0
  14. package/dist/project-migration/journal.js.map +1 -0
  15. package/dist/project-migration/plan.d.ts +82 -0
  16. package/dist/project-migration/plan.js +438 -0
  17. package/dist/project-migration/plan.js.map +1 -0
  18. package/dist/project-migration/steps.d.ts +18 -0
  19. package/dist/project-migration/steps.js +264 -0
  20. package/dist/project-migration/steps.js.map +1 -0
  21. package/dist/runs/agent-tmpdir.js +53 -28
  22. package/dist/runs/agent-tmpdir.js.map +1 -1
  23. package/dist/runs/run-database-row.d.ts +8 -0
  24. package/dist/runs/run-database-row.js +12 -0
  25. package/dist/runs/run-database-row.js.map +1 -1
  26. package/dist/runs/run-database.d.ts +3 -1
  27. package/dist/runs/run-database.js +4 -4
  28. package/dist/runs/run-database.js.map +1 -1
  29. package/dist/server/cockpit-ownership.d.ts +3 -0
  30. package/dist/server/cockpit-ownership.js +7 -0
  31. package/dist/server/cockpit-ownership.js.map +1 -1
  32. package/package.json +3 -3
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The migration's durability invariant, enforced by `settle` alone:
3
+ *
4
+ * (a) After every effect on an entry (created, renamed in or out, rewritten or removed, by the
5
+ * engine or by Git or SQLite on its behalf), the entry's data when it is a file that was
6
+ * written, then every directory from its base root down to its parent, are fsynced. This runs
7
+ * on the first run and on every resume, whether the effect happened now or before a crash.
8
+ * (b) Each step calls `settle` right after the effect and before anything that depends on it: the
9
+ * next item, a worktree unlock, the step's done mark, the journal's removal.
10
+ *
11
+ * So a power loss never keeps a later action, or the done mark, while losing the effect it
12
+ * depended on. One object, so tests observe each call.
13
+ */
14
+ export declare const durable: {
15
+ directory(path: string): void;
16
+ file(path: string): void;
17
+ };
18
+ /** `root` and every directory below it down to `path`. */
19
+ export declare function directoriesDown(root: string, path: string): string[];
20
+ /** Rule (a) for one entry: its data when `data` and it exists, then each directory from `root` down to its parent. */
21
+ export declare function settle(root: string, entry: string, options?: {
22
+ data?: boolean;
23
+ }): void;
24
+ /** Atomic replacement with exact permission bits: temp file, fsync, rename. The caller settles it. */
25
+ export declare function replaceAtomically(path: string, content: string, mode: number): void;
@@ -0,0 +1,69 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { closeSync, fchmodSync, fsyncSync, openSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join, sep } from 'node:path';
4
+ import { syncDirectory } from '../home/private-files.js';
5
+ import { pathPresent } from '../project-paths.js';
6
+ /**
7
+ * The migration's durability invariant, enforced by `settle` alone:
8
+ *
9
+ * (a) After every effect on an entry (created, renamed in or out, rewritten or removed, by the
10
+ * engine or by Git or SQLite on its behalf), the entry's data when it is a file that was
11
+ * written, then every directory from its base root down to its parent, are fsynced. This runs
12
+ * on the first run and on every resume, whether the effect happened now or before a crash.
13
+ * (b) Each step calls `settle` right after the effect and before anything that depends on it: the
14
+ * next item, a worktree unlock, the step's done mark, the journal's removal.
15
+ *
16
+ * So a power loss never keeps a later action, or the done mark, while losing the effect it
17
+ * depended on. One object, so tests observe each call.
18
+ */
19
+ export const durable = {
20
+ directory(path) { syncDirectory(path); },
21
+ file(path) {
22
+ // Windows opens no handle that FlushFileBuffers accepts read-only; its renames are write-through.
23
+ if (process.platform === 'win32')
24
+ return;
25
+ const fd = openSync(path, 'r');
26
+ try {
27
+ fsyncSync(fd);
28
+ }
29
+ finally {
30
+ closeSync(fd);
31
+ }
32
+ },
33
+ };
34
+ /** `root` and every directory below it down to `path`. */
35
+ export function directoriesDown(root, path) {
36
+ if (path !== root && !path.startsWith(root + sep))
37
+ throw new Error(`${path} is not inside ${root}`);
38
+ const directories = [root];
39
+ for (const part of path === root ? [] : path.slice(root.length + 1).split(sep))
40
+ directories.push(join(directories.at(-1), part));
41
+ return directories;
42
+ }
43
+ /** Rule (a) for one entry: its data when `data` and it exists, then each directory from `root` down to its parent. */
44
+ export function settle(root, entry, options = {}) {
45
+ if (options.data && pathPresent(entry))
46
+ durable.file(entry);
47
+ for (const directory of directoriesDown(root, dirname(entry)))
48
+ durable.directory(directory);
49
+ }
50
+ /** Atomic replacement with exact permission bits: temp file, fsync, rename. The caller settles it. */
51
+ export function replaceAtomically(path, content, mode) {
52
+ const temporary = `${path}.${randomUUID()}.tmp`;
53
+ const fd = openSync(temporary, 'wx', mode);
54
+ try {
55
+ try {
56
+ fchmodSync(fd, mode);
57
+ writeFileSync(fd, content);
58
+ fsyncSync(fd);
59
+ }
60
+ finally {
61
+ closeSync(fd);
62
+ }
63
+ renameSync(temporary, path);
64
+ }
65
+ finally {
66
+ rmSync(temporary, { force: true });
67
+ }
68
+ }
69
+ //# sourceMappingURL=durable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable.js","sourceRoot":"","sources":["../../src/project-migration/durable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MA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IAAI,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5D,KAAK,MAAM,SAAS,IAAI,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAC9F,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,OAAe,EAAE,IAAY;IAC3E,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,UAAU,EAAE,MAAM,CAAC;IAChD,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,IAAI,CAAC;YAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YAAC,aAAa,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC;gBAAS,CAAC;YAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC;QACnG,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;YAAS,CAAC;QAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type ProjectMigrationFence } from '../server/cockpit-ownership.ts';
2
+ import { type ProjectMigrationJournal } from './journal.ts';
3
+ import { type ProjectMigrationPlan } from './plan.ts';
4
+ import { type MigrationFault } from './steps.ts';
5
+ /**
6
+ * The project state migration engine (P4b2, hearsay-tools/cezarion#3088): it moves a project's
7
+ * runtime state from `.ai/cezar/` to `.ai/squawk/` under the exclusive project fence (P4b1). It is
8
+ * internal: no command, route or boot hook calls it until P4b3 wires it and P5 enables it.
9
+ *
10
+ * Order: the caller takes the fence (`fenceProject` or `fenceProjectContext`); the engine checks
11
+ * that this process holds it, runs the holder duty (`closeProject`: dispose the project's context
12
+ * and close its store), plans, writes the journal, runs each step and marks it done, and removes
13
+ * the journal last. The caller releases the fence afterwards, also after a failure: the journal
14
+ * then keeps the project blocked until a resume completes it.
15
+ */
16
+ export interface ProjectMigrationOptions {
17
+ /** The project root, in the form the project is registered with. */
18
+ repoRoot: string;
19
+ /** The fence this process holds for the project. */
20
+ fence: ProjectMigrationFence;
21
+ /** Test seam: called at each fault point; throwing there stops the migration as a crash would. */
22
+ fault?: MigrationFault;
23
+ }
24
+ export interface ProjectMigrationResult {
25
+ /** The journal as completed (removed from disk). */
26
+ journal: ProjectMigrationJournal;
27
+ /** Whether an unfinished journal was completed rather than a new plan run. */
28
+ resumed: boolean;
29
+ /** Commands that move the tracked files the migration left in place, for the user to commit. */
30
+ gitMv: string[];
31
+ }
32
+ /** The plan had conflicts or blockers: nothing was written and no journal exists. */
33
+ export declare class ProjectMigrationRefusedError extends Error {
34
+ readonly plan: ProjectMigrationPlan;
35
+ constructor(plan: ProjectMigrationPlan);
36
+ }
37
+ /** Complete an unfinished journal, for P4b3's recovery before any project read; undefined without one. */
38
+ export declare function resumeProjectMigration(options: ProjectMigrationOptions): Promise<ProjectMigrationResult | undefined>;
39
+ /**
40
+ * Migrate the project, or finish its unfinished journal first. `closeProject` is the holder duty
41
+ * after the drain and before the first move: an owning cockpit disposes the project's context
42
+ * (`ProjectContexts.dispose(id, { releasePreviews: false })`, previews were released in the drain),
43
+ * which closes its store; a CLI closes the store it opened. A refused plan writes nothing.
44
+ */
45
+ export declare function migrateProject(options: ProjectMigrationOptions & {
46
+ closeProject?: () => void | Promise<void>;
47
+ }): Promise<ProjectMigrationResult>;
@@ -0,0 +1,95 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { realpathSync } from 'node:fs';
3
+ import { join, resolve } from 'node:path';
4
+ import { holdProjectWork, holdsProjectFence, migrationFencePaths } from '../server/cockpit-ownership.js';
5
+ import { PROJECT_MIGRATION_STEPS, readProjectMigrationJournal, removeProjectMigrationJournal, writeProjectMigrationJournal, } from './journal.js';
6
+ import { gitMvCommands, LEGACY_PROJECT_DIR, planProjectMigration } from './plan.js';
7
+ import { GIT_MIGRATION_STEPS, MIGRATION_STEP_RUNNERS } from './steps.js';
8
+ import { withWorktreeMutation } from '../git-worktree-lock.js';
9
+ /** The plan had conflicts or blockers: nothing was written and no journal exists. */
10
+ export class ProjectMigrationRefusedError extends Error {
11
+ plan;
12
+ constructor(plan) {
13
+ super(`Cannot migrate ${plan.repoRoot}:${[...plan.blockers, ...plan.conflicts.map(conflict => `${conflict.path}: ${conflict.reason}`)]
14
+ .map(line => `\n- ${line}`).join('')}`);
15
+ this.plan = plan;
16
+ this.name = 'ProjectMigrationRefusedError';
17
+ }
18
+ }
19
+ function legacyDataDir(repoRoot) {
20
+ return join(resolve(repoRoot), ...LEGACY_PROJECT_DIR.split('/'));
21
+ }
22
+ /** The engine runs only under a fence its own process holds, and only for that fence's project. */
23
+ function assertHeldFence(dataDir, fence) {
24
+ const paths = migrationFencePaths(dataDir);
25
+ if (!paths || paths.lock !== fence.lock || paths.journal !== fence.journal || !holdsProjectFence(dataDir)) {
26
+ throw new Error(`The project migration of ${resolve(dataDir, '..', '..')} needs the project's migration fence held by this process`);
27
+ }
28
+ }
29
+ async function runJournal(path, start, resumed, fault) {
30
+ let journal = start;
31
+ const run = async (step, git) => {
32
+ if (journal.done.includes(step))
33
+ return;
34
+ fault(`${step}:before`);
35
+ await MIGRATION_STEP_RUNNERS[step](journal, fault, git);
36
+ fault(`${step}:after`);
37
+ journal = { ...journal, done: [...journal.done, step] };
38
+ writeProjectMigrationJournal(path, journal);
39
+ fault(`${step}:marked`);
40
+ };
41
+ // Worktree locks, moves and repairs in one hold of the common directory's mutation lock, so no
42
+ // cooperating process mutates worktree registrations in between; the Git locks cover a crash.
43
+ if (journal.worktrees.length > 0 && GIT_MIGRATION_STEPS.some(step => !journal.done.includes(step))) {
44
+ await withWorktreeMutation(journal.repoRoot, async (git) => { for (const step of GIT_MIGRATION_STEPS)
45
+ await run(step, git); });
46
+ }
47
+ for (const step of PROJECT_MIGRATION_STEPS)
48
+ await run(step);
49
+ removeProjectMigrationJournal(path);
50
+ return { journal, resumed, gitMv: gitMvCommands(journal.repoRoot, journal.tracked) };
51
+ }
52
+ /** Complete an unfinished journal, for P4b3's recovery before any project read; undefined without one. */
53
+ export async function resumeProjectMigration(options) {
54
+ const dataDir = legacyDataDir(options.repoRoot);
55
+ assertHeldFence(dataDir, options.fence);
56
+ return holdProjectWork(dataDir, async () => resumeHeld(options));
57
+ }
58
+ async function resumeHeld(options) {
59
+ const journal = readProjectMigrationJournal(options.fence.journal);
60
+ if (!journal)
61
+ return undefined;
62
+ const root = realpathSync(resolve(options.repoRoot));
63
+ if (journal.repoRoot !== root)
64
+ throw new Error(`The migration journal ${options.fence.journal} belongs to ${journal.repoRoot}, not ${root}`);
65
+ return runJournal(options.fence.journal, journal, true, options.fault ?? (() => undefined));
66
+ }
67
+ /**
68
+ * Migrate the project, or finish its unfinished journal first. `closeProject` is the holder duty
69
+ * after the drain and before the first move: an owning cockpit disposes the project's context
70
+ * (`ProjectContexts.dispose(id, { releasePreviews: false })`, previews were released in the drain),
71
+ * which closes its store; a CLI closes the store it opened. A refused plan writes nothing.
72
+ */
73
+ export async function migrateProject(options) {
74
+ const dataDir = legacyDataDir(options.repoRoot);
75
+ assertHeldFence(dataDir, options.fence);
76
+ return holdProjectWork(dataDir, async () => {
77
+ await options.closeProject?.();
78
+ const unfinished = await resumeHeld(options);
79
+ if (unfinished)
80
+ return unfinished;
81
+ const plan = await planProjectMigration(options.repoRoot);
82
+ if (plan.blockers.length > 0 || plan.conflicts.length > 0)
83
+ throw new ProjectMigrationRefusedError(plan);
84
+ const journal = {
85
+ version: 1, id: randomUUID(), createdAt: new Date().toISOString(), repoRoot: plan.repoRoot, source: plan.source,
86
+ destination: plan.destination, done: [], moves: plan.moves, tracked: plan.tracked, worktrees: plan.worktrees, rewrites: plan.rewrites,
87
+ };
88
+ const fault = options.fault ?? (() => undefined);
89
+ fault('journal:before');
90
+ writeProjectMigrationJournal(plan.journal, journal);
91
+ fault('journal:written');
92
+ return runJournal(plan.journal, journal, false, fault);
93
+ });
94
+ }
95
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/project-migration/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAA8B,MAAM,gCAAgC,CAAC;AACrI,OAAO,EACL,uBAAuB,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,4BAA4B,GAElH,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,oBAAoB,EAA6B,MAAM,WAAW,CAAC;AAC/G,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAuB,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAoB,MAAM,yBAAyB,CAAC;AAgCjF,qFAAqF;AACrF,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAChC,IAAI;IAAzB,YAAqB,IAA0B;QAC7C,KAAK,CAAC,kBAAkB,IAAI,CAAC,QAAQ,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;aACnI,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CA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AAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM;YAC/G,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACtI,CAAC;QACF,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACjD,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACxB,4BAA4B,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACzB,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,137 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The project migration journal, `<root>/.ai/squawk-migration.json` (P4b1's
4
+ * `MIGRATION_JOURNAL_FILE`). It sits beside both directory names, so no move carries it. It holds
5
+ * the whole plan: every move, every repair and every old-to-new path rewrite. Each step marks
6
+ * itself done here after its effect; a resume runs the steps not marked done and every step
7
+ * checks each item's state first, so a crash between an effect and its mark never applies a
8
+ * rewrite twice. While the file exists, P4b1's admission refuses the project to everyone but the
9
+ * fence holder.
10
+ */
11
+ export declare const PROJECT_MIGRATION_STEPS: readonly ['lock-worktrees', 'move', 'repair-worktrees', 'receipts', 'run-store', 'run-files'];
12
+ export type ProjectMigrationStep = typeof PROJECT_MIGRATION_STEPS[number];
13
+ /** One runtime item renamed from the legacy directory into the new one. */
14
+ export declare const migrationMoveSchema: z.ZodObject<{
15
+ from: z.ZodString;
16
+ to: z.ZodString;
17
+ kind: z.ZodEnum<{
18
+ directory: "directory";
19
+ file: "file";
20
+ other: "other";
21
+ symlink: "symlink";
22
+ }>;
23
+ }, z.core.$strict>;
24
+ /** A tracked file: never moved; the user runs the printed `git mv`. Paths relative to the repo root. */
25
+ export declare const trackedFileSchema: z.ZodObject<{
26
+ from: z.ZodString;
27
+ to: z.ZodString;
28
+ }, z.core.$strict>;
29
+ /** A registered task worktree that the move carried: `git worktree repair` points Git at its new path. */
30
+ export declare const worktreeRepairSchema: z.ZodObject<{
31
+ from: z.ZodString;
32
+ to: z.ZodString;
33
+ }, z.core.$strict>;
34
+ /** Where a stored path lives: a JSON field of a file, a field of a run row, or the handoff's worktree line. */
35
+ export declare const pathRewriteSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
36
+ from: z.ZodString;
37
+ to: z.ZodString;
38
+ kind: z.ZodEnum<{
39
+ "artifact-metadata": "artifact-metadata";
40
+ "autosave-cleanup": "autosave-cleanup";
41
+ "cleanup-checkpoint": "cleanup-checkpoint";
42
+ receipt: "receipt";
43
+ "worker-execution": "worker-execution";
44
+ "worker-result": "worker-result";
45
+ }>;
46
+ file: z.ZodString;
47
+ field: z.ZodArray<z.ZodString>;
48
+ }, z.core.$strict>, z.ZodObject<{
49
+ from: z.ZodString;
50
+ to: z.ZodString;
51
+ kind: z.ZodLiteral<"handoff">;
52
+ file: z.ZodString;
53
+ }, z.core.$strict>, z.ZodObject<{
54
+ from: z.ZodString;
55
+ to: z.ZodString;
56
+ kind: z.ZodLiteral<"run-row">;
57
+ runId: z.ZodString;
58
+ field: z.ZodUnion<readonly [z.ZodObject<{
59
+ data: z.ZodArray<z.ZodString>;
60
+ }, z.core.$strict>, z.ZodObject<{
61
+ summary: z.ZodArray<z.ZodString>;
62
+ }, z.core.$strict>, z.ZodObject<{
63
+ column: z.ZodLiteral<"worktree_path">;
64
+ }, z.core.$strict>]>;
65
+ }, z.core.$strict>], "kind">;
66
+ export type PathRewrite = z.infer<typeof pathRewriteSchema>;
67
+ export declare const projectMigrationJournalSchema: z.ZodObject<{
68
+ version: z.ZodLiteral<1>;
69
+ id: z.ZodUUID;
70
+ createdAt: z.ZodISODateTime;
71
+ repoRoot: z.ZodString;
72
+ source: z.ZodString;
73
+ destination: z.ZodString;
74
+ done: z.ZodArray<z.ZodEnum<{
75
+ "lock-worktrees": "lock-worktrees";
76
+ move: "move";
77
+ receipts: "receipts";
78
+ "repair-worktrees": "repair-worktrees";
79
+ "run-files": "run-files";
80
+ "run-store": "run-store";
81
+ }>>;
82
+ moves: z.ZodArray<z.ZodObject<{
83
+ from: z.ZodString;
84
+ to: z.ZodString;
85
+ kind: z.ZodEnum<{
86
+ directory: "directory";
87
+ file: "file";
88
+ other: "other";
89
+ symlink: "symlink";
90
+ }>;
91
+ }, z.core.$strict>>;
92
+ tracked: z.ZodArray<z.ZodObject<{
93
+ from: z.ZodString;
94
+ to: z.ZodString;
95
+ }, z.core.$strict>>;
96
+ worktrees: z.ZodArray<z.ZodObject<{
97
+ from: z.ZodString;
98
+ to: z.ZodString;
99
+ }, z.core.$strict>>;
100
+ rewrites: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
101
+ from: z.ZodString;
102
+ to: z.ZodString;
103
+ kind: z.ZodEnum<{
104
+ "artifact-metadata": "artifact-metadata";
105
+ "autosave-cleanup": "autosave-cleanup";
106
+ "cleanup-checkpoint": "cleanup-checkpoint";
107
+ receipt: "receipt";
108
+ "worker-execution": "worker-execution";
109
+ "worker-result": "worker-result";
110
+ }>;
111
+ file: z.ZodString;
112
+ field: z.ZodArray<z.ZodString>;
113
+ }, z.core.$strict>, z.ZodObject<{
114
+ from: z.ZodString;
115
+ to: z.ZodString;
116
+ kind: z.ZodLiteral<"handoff">;
117
+ file: z.ZodString;
118
+ }, z.core.$strict>, z.ZodObject<{
119
+ from: z.ZodString;
120
+ to: z.ZodString;
121
+ kind: z.ZodLiteral<"run-row">;
122
+ runId: z.ZodString;
123
+ field: z.ZodUnion<readonly [z.ZodObject<{
124
+ data: z.ZodArray<z.ZodString>;
125
+ }, z.core.$strict>, z.ZodObject<{
126
+ summary: z.ZodArray<z.ZodString>;
127
+ }, z.core.$strict>, z.ZodObject<{
128
+ column: z.ZodLiteral<"worktree_path">;
129
+ }, z.core.$strict>]>;
130
+ }, z.core.$strict>], "kind">>;
131
+ }, z.core.$strict>;
132
+ export type ProjectMigrationJournal = z.infer<typeof projectMigrationJournalSchema>;
133
+ export declare function readProjectMigrationJournal(path: string): ProjectMigrationJournal | undefined;
134
+ /** Durable, atomic, private replacement, settled before the caller goes on. */
135
+ export declare function writeProjectMigrationJournal(path: string, journal: ProjectMigrationJournal): void;
136
+ /** The last step: the project is admitted again once this file is gone. */
137
+ export declare function removeProjectMigrationJournal(path: string): void;
@@ -0,0 +1,68 @@
1
+ import { readFileSync, rmSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
+ import { z } from 'zod';
4
+ import { replaceAtomically, settle } from './durable.js';
5
+ /**
6
+ * The project migration journal, `<root>/.ai/squawk-migration.json` (P4b1's
7
+ * `MIGRATION_JOURNAL_FILE`). It sits beside both directory names, so no move carries it. It holds
8
+ * the whole plan: every move, every repair and every old-to-new path rewrite. Each step marks
9
+ * itself done here after its effect; a resume runs the steps not marked done and every step
10
+ * checks each item's state first, so a crash between an effect and its mark never applies a
11
+ * rewrite twice. While the file exists, P4b1's admission refuses the project to everyone but the
12
+ * fence holder.
13
+ */
14
+ export const PROJECT_MIGRATION_STEPS = ['lock-worktrees', 'move', 'repair-worktrees', 'receipts', 'run-store', 'run-files'];
15
+ const absolute = z.string().min(1).refine(path => path.startsWith('/') || /^[a-z]:[\\/]/i.test(path), 'absolute path');
16
+ const pathChange = { from: absolute, to: absolute };
17
+ /** One runtime item renamed from the legacy directory into the new one. */
18
+ export const migrationMoveSchema = z.object({ ...pathChange, kind: z.enum(['file', 'directory', 'symlink', 'other']) }).strict();
19
+ /** A tracked file: never moved; the user runs the printed `git mv`. Paths relative to the repo root. */
20
+ export const trackedFileSchema = z.object({ from: z.string().min(1), to: z.string().min(1) }).strict();
21
+ /** A registered task worktree that the move carried: `git worktree repair` points Git at its new path. */
22
+ export const worktreeRepairSchema = z.object({ ...pathChange }).strict();
23
+ /** Where a stored path lives: a JSON field of a file, a field of a run row, or the handoff's worktree line. */
24
+ export const pathRewriteSchema = z.discriminatedUnion('kind', [
25
+ z.object({ kind: z.enum(['receipt', 'cleanup-checkpoint', 'worker-execution', 'autosave-cleanup', 'worker-result', 'artifact-metadata']), file: absolute,
26
+ field: z.array(z.string().min(1)).min(1), ...pathChange }).strict(),
27
+ z.object({ kind: z.literal('handoff'), file: absolute, ...pathChange }).strict(),
28
+ z.object({ kind: z.literal('run-row'), runId: z.string().min(1),
29
+ field: z.union([z.object({ data: z.array(z.string().min(1)).min(1) }).strict(),
30
+ z.object({ summary: z.array(z.string().min(1)).min(1) }).strict(),
31
+ z.object({ column: z.literal('worktree_path') }).strict()]), ...pathChange }).strict(),
32
+ ]);
33
+ export const projectMigrationJournalSchema = z.object({
34
+ version: z.literal(1),
35
+ id: z.uuid(),
36
+ createdAt: z.iso.datetime(),
37
+ repoRoot: absolute,
38
+ source: absolute,
39
+ destination: absolute,
40
+ done: z.array(z.enum(PROJECT_MIGRATION_STEPS)),
41
+ moves: z.array(migrationMoveSchema),
42
+ tracked: z.array(trackedFileSchema),
43
+ worktrees: z.array(worktreeRepairSchema),
44
+ rewrites: z.array(pathRewriteSchema),
45
+ }).strict();
46
+ export function readProjectMigrationJournal(path) {
47
+ let text;
48
+ try {
49
+ text = readFileSync(path, 'utf8');
50
+ }
51
+ catch (error) {
52
+ if (error.code === 'ENOENT')
53
+ return undefined;
54
+ throw error;
55
+ }
56
+ return projectMigrationJournalSchema.parse(JSON.parse(text));
57
+ }
58
+ /** Durable, atomic, private replacement, settled before the caller goes on. */
59
+ export function writeProjectMigrationJournal(path, journal) {
60
+ replaceAtomically(path, `${JSON.stringify(projectMigrationJournalSchema.parse(journal), null, 2)}\n`, 0o600);
61
+ settle(dirname(path), path, { data: true });
62
+ }
63
+ /** The last step: the project is admitted again once this file is gone. */
64
+ export function removeProjectMigrationJournal(path) {
65
+ rmSync(path, { force: true });
66
+ settle(dirname(path), path);
67
+ }
68
+ //# sourceMappingURL=journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/project-migration/journal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AAGrI,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,CAAC;AACvH,MAAM,UAAU,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AAEpD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AACjI,wGAAwG;AACxG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MA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,CAAC;IAAC,CAAC;IAC1C,OAAO,KAAK,EAAE,CAAC;QACb,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACzE,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,6BAA6B,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,4BAA4B,CAAC,IAAY,EAAE,OAAgC;IACzF,iBAAiB,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,6BAA6B,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7G,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,6BAA6B,CAAC,IAAY;IACxD,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,82 @@
1
+ import nodePath from 'node:path';
2
+ import type { PathRewrite } from './journal.ts';
3
+ /**
4
+ * The read-only plan of a project migration, which is also its dry run: every move, every tracked
5
+ * file left in place with the `git mv` that moves it, every worktree repair and every path rewrite,
6
+ * plus what blocks it. Planning writes nothing: no directory, Git metadata, receipt, run record or
7
+ * journal changes, and the run store is read so that no SQLite sidecar is created.
8
+ */
9
+ export declare const LEGACY_PROJECT_DIR = ".ai/cezar";
10
+ export declare const MIGRATED_PROJECT_DIR = ".ai/squawk";
11
+ /** Paths that may hold the old directory but are left as they are, on purpose. */
12
+ export declare const NOT_REWRITTEN: readonly string[];
13
+ export type MigrationMove = {
14
+ from: string;
15
+ to: string;
16
+ kind: 'file' | 'directory' | 'symlink' | 'other';
17
+ };
18
+ export type TrackedFile = {
19
+ from: string;
20
+ to: string;
21
+ };
22
+ export type WorktreeRepair = {
23
+ from: string;
24
+ to: string;
25
+ };
26
+ export type MigrationConflict = {
27
+ path: string;
28
+ reason: string;
29
+ };
30
+ export interface ProjectMigrationPlan {
31
+ repoRoot: string;
32
+ source: string;
33
+ destination: string;
34
+ journal: string;
35
+ moves: MigrationMove[];
36
+ tracked: TrackedFile[];
37
+ worktrees: WorktreeRepair[];
38
+ rewrites: PathRewrite[];
39
+ conflicts: MigrationConflict[];
40
+ blockers: string[];
41
+ /** Shell commands, run from any directory, that move the tracked files for the user to commit. */
42
+ gitMv: string[];
43
+ notRewritten: readonly string[];
44
+ }
45
+ /** Git in `cwd`; undefined when it fails. */
46
+ export declare function gitOutput(cwd: string, args: string[]): Promise<string | undefined>;
47
+ /** Index entries under the legacy directory, relative to the repository root with `/`. */
48
+ export declare function trackedPaths(root: string): Promise<Set<string> | undefined>;
49
+ export interface PathMapping {
50
+ /** The project root in each form stored paths may use: as registered, and its real path. */
51
+ roots: readonly string[];
52
+ realRoot: string;
53
+ source: string;
54
+ destination: string;
55
+ moves: readonly MigrationMove[];
56
+ /** Tracked files, relative to the root with `/`. */
57
+ tracked: ReadonlySet<string>;
58
+ }
59
+ /**
60
+ * Where a stored path goes, in the root form it was written in; undefined when it stays. A path
61
+ * inside a moved item follows that item. A path into the old directory that no longer exists (a
62
+ * cleaned temp directory, a removed worktree) follows the directory, as its item would have, unless
63
+ * a tracked file or an ownership claim holds that name. Everything else stays.
64
+ */
65
+ export declare function pathMapper(mapping: PathMapping): (path: string) => string | undefined;
66
+ /** `git mv` for each tracked file, from the repository root, creating each new parent first. */
67
+ export declare function gitMvCommands(root: string, tracked: readonly TrackedFile[]): string[];
68
+ type JsonField = string[];
69
+ export declare function valueAt(value: unknown, field: readonly string[]): unknown;
70
+ /** Every stored path field of a run record that a migration rewrites. */
71
+ export declare function runRecordPathFields(record: unknown): JsonField[];
72
+ export declare function handoffWorktreeLine(text: string): string | undefined;
73
+ /** `text` with its seeded worktree line naming `to`, when it still names `from`; else unchanged. */
74
+ export declare function rewriteHandoffWorktreeLine(text: string, from: string, to: string): string;
75
+ export declare function redirectedComponent(base: string, path: string): string | undefined;
76
+ /** A path Git printed, in this platform's form: Git for Windows prints forward slashes. */
77
+ export declare function gitReportedPath(path: string, api?: Pick<typeof nodePath, 'normalize'>): string;
78
+ /** The dry run, and the plan a real migration writes into its journal. Writes nothing. */
79
+ export declare function planProjectMigration(repoRoot: string): Promise<ProjectMigrationPlan>;
80
+ /** The dry run as text: every move, repair, rewrite, tracked file and conflict, and the boundary. */
81
+ export declare function describeProjectMigrationPlan(plan: ProjectMigrationPlan): string;
82
+ export {};