@wjarka/cezarion 0.17.0-dev.5427 → 0.17.0-dev.5435
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/activity/publisher.d.ts +1 -0
- package/dist/activity/publisher.js +8 -4
- package/dist/activity/publisher.js.map +1 -1
- package/dist/artifacts/cli.js +4 -0
- package/dist/artifacts/cli.js.map +1 -1
- package/dist/artifacts/reports-index.d.ts +2 -0
- package/dist/artifacts/reports-index.js +9 -0
- package/dist/artifacts/reports-index.js.map +1 -1
- package/dist/artifacts/store.js +26 -6
- package/dist/artifacts/store.js.map +1 -1
- package/dist/automations/coordinator.d.ts +9 -0
- package/dist/automations/coordinator.js +28 -4
- package/dist/automations/coordinator.js.map +1 -1
- package/dist/automations/schedule-runner.js +7 -0
- package/dist/automations/schedule-runner.js.map +1 -1
- package/dist/automations/scheduler.js +16 -3
- package/dist/automations/scheduler.js.map +1 -1
- package/dist/automations/store.d.ts +3 -0
- package/dist/automations/store.js +40 -2
- package/dist/automations/store.js.map +1 -1
- package/dist/automations/task-template.js +26 -16
- package/dist/automations/task-template.js.map +1 -1
- package/dist/cli-dispatch.js +10 -0
- package/dist/cli-dispatch.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.js +18 -1
- package/dist/config.js.map +1 -1
- package/dist/data-gitignore.js +4 -1
- package/dist/data-gitignore.js.map +1 -1
- package/dist/delegation/routes.d.ts +16 -16
- package/dist/delegation/routes.js +7 -1
- package/dist/delegation/routes.js.map +1 -1
- package/dist/delegation/service.d.ts +2 -0
- package/dist/delegation/service.js +5 -0
- package/dist/delegation/service.js.map +1 -1
- package/dist/delegation/transport.d.ts +16 -16
- package/dist/delegation/workspace.d.ts +7 -0
- package/dist/delegation/workspace.js +26 -4
- package/dist/delegation/workspace.js.map +1 -1
- package/dist/index.js +3 -75
- package/dist/index.js.map +1 -1
- package/dist/preview/browser-launch.d.ts +1 -0
- package/dist/preview/browser-launch.js +1 -1
- package/dist/preview/browser-launch.js.map +1 -1
- package/dist/preview/host.d.ts +6 -0
- package/dist/preview/host.js +17 -3
- package/dist/preview/host.js.map +1 -1
- package/dist/preview/project-exits.d.ts +16 -0
- package/dist/preview/project-exits.js +36 -0
- package/dist/preview/project-exits.js.map +1 -0
- package/dist/project-commands.d.ts +14 -0
- package/dist/project-commands.js +89 -0
- package/dist/project-commands.js.map +1 -0
- package/dist/project-migration/durable.d.ts +25 -0
- package/dist/project-migration/durable.js +69 -0
- package/dist/project-migration/durable.js.map +1 -0
- package/dist/project-migration/engine.d.ts +47 -0
- package/dist/project-migration/engine.js +95 -0
- package/dist/project-migration/engine.js.map +1 -0
- package/dist/project-migration/journal.d.ts +137 -0
- package/dist/project-migration/journal.js +68 -0
- package/dist/project-migration/journal.js.map +1 -0
- package/dist/project-migration/plan.d.ts +82 -0
- package/dist/project-migration/plan.js +438 -0
- package/dist/project-migration/plan.js.map +1 -0
- package/dist/project-migration/steps.d.ts +18 -0
- package/dist/project-migration/steps.js +264 -0
- package/dist/project-migration/steps.js.map +1 -0
- package/dist/runs/project-run-connection.d.ts +7 -1
- package/dist/runs/project-run-connection.js +9 -0
- package/dist/runs/project-run-connection.js.map +1 -1
- package/dist/runs/run-claims.d.ts +14 -0
- package/dist/runs/run-claims.js +28 -0
- package/dist/runs/run-claims.js.map +1 -1
- package/dist/runs/run-database-row.d.ts +8 -0
- package/dist/runs/run-database-row.js +12 -0
- package/dist/runs/run-database-row.js.map +1 -1
- package/dist/runs/run-database.d.ts +4 -2
- package/dist/runs/run-database.js +6 -6
- package/dist/runs/run-database.js.map +1 -1
- package/dist/runs/store.d.ts +6 -3
- package/dist/runs/store.js +9 -23
- package/dist/runs/store.js.map +1 -1
- package/dist/runs/webhook.js +3 -2
- package/dist/runs/webhook.js.map +1 -1
- package/dist/self-update/checkouts.js +8 -1
- package/dist/self-update/checkouts.js.map +1 -1
- package/dist/server/activity-sources.js +14 -8
- package/dist/server/activity-sources.js.map +1 -1
- package/dist/server/archive-on-merge.js +4 -1
- package/dist/server/archive-on-merge.js.map +1 -1
- package/dist/server/cockpit-ownership.d.ts +96 -0
- package/dist/server/cockpit-ownership.js +301 -13
- package/dist/server/cockpit-ownership.js.map +1 -1
- package/dist/server/launch-key.js +2 -0
- package/dist/server/launch-key.js.map +1 -1
- package/dist/server/live-routes.js +7 -2
- package/dist/server/live-routes.js.map +1 -1
- package/dist/server/preview-socket.js +9 -1
- package/dist/server/preview-socket.js.map +1 -1
- package/dist/server/project-context.d.ts +25 -1
- package/dist/server/project-context.js +133 -52
- package/dist/server/project-context.js.map +1 -1
- package/dist/server/server.d.ts +7 -7
- package/dist/server/server.js +10 -9
- package/dist/server/server.js.map +1 -1
- package/dist/server/workspace-live-routes.d.ts +6 -6
- package/dist/server/workspace-projects.js +8 -3
- package/dist/server/workspace-projects.js.map +1 -1
- package/dist/ui-state.js +3 -1
- package/dist/ui-state.js.map +1 -1
- package/dist/voice/decision-log.js +3 -0
- package/dist/voice/decision-log.js.map +1 -1
- package/dist/voice/routes.d.ts +19 -19
- package/dist/workflows/run.d.ts +3 -0
- package/dist/workflows/run.js +14 -1
- package/dist/workflows/run.js.map +1 -1
- package/package.json +3 -3
|
@@ -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,UAA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C,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,MAAM,EAAE,CAAC,GAAG,C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1C,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 {};
|