@hearsay-tools/squawk 0.18.0-dev.6083 → 0.18.0-dev.6087

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 (45) hide show
  1. package/dist/artifacts/store.js +1 -1
  2. package/dist/artifacts/store.js.map +1 -1
  3. package/dist/automations/store.js +1 -1
  4. package/dist/automations/store.js.map +1 -1
  5. package/dist/ci-wait/controller.d.ts +41 -41
  6. package/dist/ci-wait/tools.d.ts +4 -4
  7. package/dist/config.js +1 -1
  8. package/dist/config.js.map +1 -1
  9. package/dist/core/process-stat.d.ts +36 -0
  10. package/dist/core/process-stat.js +101 -0
  11. package/dist/core/process-stat.js.map +1 -0
  12. package/dist/delegation/process-liveness.d.ts +2 -10
  13. package/dist/delegation/process-liveness.js +3 -42
  14. package/dist/delegation/process-liveness.js.map +1 -1
  15. package/dist/delegation/routes.d.ts +71 -71
  16. package/dist/delegation/transport.d.ts +66 -66
  17. package/dist/detached-process.d.ts +2 -23
  18. package/dist/detached-process.js +2 -61
  19. package/dist/detached-process.js.map +1 -1
  20. package/dist/home/leases.js +1 -1
  21. package/dist/home/leases.js.map +1 -1
  22. package/dist/home/migrate.js +1 -1
  23. package/dist/home/migrate.js.map +1 -1
  24. package/dist/home/migration-accounts.js +1 -1
  25. package/dist/home/migration-accounts.js.map +1 -1
  26. package/dist/home/migration-claim.js +1 -1
  27. package/dist/home/migration-claim.js.map +1 -1
  28. package/dist/home/private-files.js +1 -1
  29. package/dist/home/private-files.js.map +1 -1
  30. package/dist/home/process-identity.js +1 -1
  31. package/dist/home/process-identity.js.map +1 -1
  32. package/dist/home/write-lock.js +1 -1
  33. package/dist/home/write-lock.js.map +1 -1
  34. package/dist/project-fence.d.ts +63 -0
  35. package/dist/project-fence.js +146 -0
  36. package/dist/project-fence.js.map +1 -0
  37. package/dist/server/activity-routes.d.ts +23 -23
  38. package/dist/server/cockpit-ownership.d.ts +2 -59
  39. package/dist/server/cockpit-ownership.js +4 -143
  40. package/dist/server/cockpit-ownership.js.map +1 -1
  41. package/dist/server/server.d.ts +58 -58
  42. package/dist/server/workspace-live-routes.d.ts +6 -6
  43. package/dist/ui-state.js +1 -1
  44. package/dist/ui-state.js.map +1 -1
  45. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import { POWERSHELL, powershellEnv } from '../detached-process.js';
1
+ import { POWERSHELL, powershellEnv } from '../core/process-stat.js';
2
2
  import { execFileSync } from 'node:child_process';
3
3
  import { REBRAND_SWITCH } from './switch.js';
4
4
  import { randomBytes } from 'node:crypto';
@@ -1 +1 @@
1
- {"version":3,"file":"private-files.js","sourceRoot":"","sources":["../../src/home/private-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3I,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAO7C,uFAAuF;AACvF,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,SAAkB,EAAE,EACnE,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,GAC1E,GAAuB,EAAE;IACxB,IAAI,QAAQ,KAAK,OAAO,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO;IACvD,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,cAAc,CAAC;IA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AC,SAAS,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC;gBAAS,CAAC;YAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC;QAC3E,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACxB,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,CAAC;YAAS,CAAC;QAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAAC,CAAC;AAC/C,CAAC"}
@@ -1,4 +1,4 @@
1
- import { processStartToken } from '../delegation/process-liveness.js';
1
+ import { processStartToken } from '../core/process-stat.js';
2
2
  let identity;
3
3
  /** A process never changes its start identity. Cache absence too, without IO at import time. */
4
4
  export function ownProcessStartToken() {
@@ -1 +1 @@
1
- {"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../src/home/process-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,IAAI,QAAmD,CAAC;AAExD,gGAAgG;AAChG,MAAM,UAAU,oBAAoB;IAClC,QAAQ,KAAK,EAAE,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;IACvD,OAAO,QAAQ,CAAC,KAAK,CAAC;AACxB,CAAC"}
1
+ {"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../src/home/process-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,IAAI,QAAmD,CAAC;AAExD,gGAAgG;AAChG,MAAM,UAAU,oBAAoB;IAClC,QAAQ,KAAK,EAAE,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;IACvD,OAAO,QAAQ,CAAC,KAAK,CAAC;AACxB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
- import { processStartToken, recordedProcessLive } from '../delegation/process-liveness.js';
4
+ import { processStartToken, recordedProcessLive } from '../core/process-stat.js';
5
5
  import { privateDirectory } from './private-files.js';
6
6
  import { ownProcessStartToken } from './process-identity.js';
7
7
  import { assertHomeMetadata, assertHomePath } from './boundary.js';
@@ -1 +1 @@
1
- {"version":3,"file":"write-lock.js","sourceRoot":"","sources":["../../src/home/write-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGnE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;AAC/B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvD,8FAA8F;AAC9F,SAAS,YAAY,CAAC,IAAY,EAAE,KAAY;IAC9C,MAAM,KAAK,GAAG,GAAG,IAAI,MAAM,CAAC;IAC5B,IAAI,CAAC;QACH,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACzE,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1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I,CAAC,MAAM,KAAK,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;YACzG,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,OAAO;gBAAE,MAAM;YACpB,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,EAAE,CAAC,CAAC;YACrG,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpB,IAAI,CAAC;YAAC,OAAO,SAAS,EAAE,CAAC;QAAC,CAAC;gBAAS,CAAC;YAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAAC,CAAC;IACjE,CAAC;YAAS,CAAC;QAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { z } from 'zod';
2
+ declare const ownerSchema: z.ZodObject<{
3
+ pid: z.ZodNumber;
4
+ token: z.ZodString;
5
+ startToken: z.ZodOptional<z.ZodString>;
6
+ url: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strip>;
8
+ export type Owner = z.infer<typeof ownerSchema>;
9
+ export declare function readOwner(path: string): Owner | undefined;
10
+ export declare function alive(owner: Owner): boolean;
11
+ /** The migration fence and its journal: beside both directory names, so moving one never moves them. */
12
+ export declare const MIGRATION_FENCE_FILE = "squawk-migration.lock";
13
+ export declare const MIGRATION_JOURNAL_FILE = "squawk-migration.json";
14
+ /** A project's fence and journal paths; none for a data directory that is not `<root>/.ai/{cezar,squawk}`. */
15
+ export declare function migrationFencePaths(dataDir: string): {
16
+ lock: string;
17
+ journal: string;
18
+ } | undefined;
19
+ export declare class ProjectMigrationFencedError extends Error {
20
+ readonly reason: 'migrating' | 'journal' | 'unreadable';
21
+ readonly path: string;
22
+ constructor(reason: 'migrating' | 'journal' | 'unreadable', path: string, owner?: Owner);
23
+ }
24
+ /**
25
+ * Why no new operation may touch the project of `dataDir`: a live or unreadable fence (this
26
+ * process's own fence included) or an unfinished journal. Dormant cost: two `lstat` calls.
27
+ * A dead owner without a journal admits; the next fence claim reclaims its file.
28
+ */
29
+ export declare function projectAdmissionRefusal(dataDir: string): ProjectMigrationFencedError | undefined;
30
+ export declare function assertProjectAdmitted(dataDir: string): void;
31
+ /**
32
+ * The write backstop under every store write, claim and save: true while a fence or a journal
33
+ * refuses this project, outside the fence holder's own work. Offline, the migration CLI refuses
34
+ * while any cockpit it can see serves the project; this stops the writes of one it cannot see (a
35
+ * cockpit of another home that has the project registered). A skipped write is logged once per
36
+ * fence. Dormant cost: two `lstat` calls.
37
+ */
38
+ export declare function projectWriteRefused(dataDir: string): boolean;
39
+ /** A CLI write: the project's migration admission is checked right before `write` runs. A CLI
40
+ * path runs each write that follows an await through it, not only its first one. */
41
+ export declare function admittedWrite<T>(dataDir: string, write: () => T): T;
42
+ /** A durable commit refused by the backstop writes nothing and throws, as on a closed store. */
43
+ export declare function assertProjectWritable(dataDir: string): void;
44
+ /** The token of every fence this process holds, by lock path. */
45
+ export declare const heldFences: Map<string, string>;
46
+ /** Whether this process holds the live migration fence of `dataDir`'s project: the project
47
+ * migration engine runs only under a fence its own process holds. */
48
+ export declare function holdsProjectFence(dataDir: string): boolean;
49
+ /**
50
+ * Run `work` as the holder of `fence`: admission and the write backstop pass for this project
51
+ * inside it, and only inside it, so a cockpit that recovers a journal still refuses its own other
52
+ * requests for the project meanwhile.
53
+ */
54
+ export declare function asFenceHolder<T>(fence: Pick<ProjectMigrationFence, 'lock'>, work: () => T): T;
55
+ /** Run `work` unless the project is fenced or has an unfinished journal; then answer `refused`. */
56
+ export declare function withProjectAdmission<T, R>(dataDir: string, work: () => Promise<T>, refused: (error: ProjectMigrationFencedError) => R): Promise<T | R>;
57
+ /** A held migration fence: exclusive until `release`, which never removes another owner's claim. */
58
+ export interface ProjectMigrationFence {
59
+ lock: string;
60
+ journal: string;
61
+ release(): void;
62
+ }
63
+ export {};
@@ -0,0 +1,146 @@
1
+ import { logPrefix } from './home/display.js';
2
+ import { dataReadDirs, pathPresent } from './project-paths.js';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ import { readFileSync } from 'node:fs';
5
+ import { dirname, join, resolve } from 'node:path';
6
+ import { z } from 'zod';
7
+ import { recordedProcessLive } from './core/process-stat.js';
8
+ const ownerSchema = z.object({
9
+ pid: z.number().int().positive(),
10
+ token: z.string().uuid(),
11
+ startToken: z.string().optional(),
12
+ url: z.string().url().optional(),
13
+ });
14
+ export function readOwner(path) {
15
+ try {
16
+ return ownerSchema.parse(JSON.parse(readFileSync(path, 'utf8')));
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ export function alive(owner) {
23
+ // Keep unexpected OS probe failures conservative; only proven absence or a
24
+ // different process incarnation permits reclamation.
25
+ try {
26
+ process.kill(owner.pid, 0);
27
+ }
28
+ catch (error) {
29
+ return error.code !== 'ESRCH';
30
+ }
31
+ return recordedProcessLive(owner);
32
+ }
33
+ /** The migration fence and its journal: beside both directory names, so moving one never moves them. */
34
+ export const MIGRATION_FENCE_FILE = 'squawk-migration.lock';
35
+ export const MIGRATION_JOURNAL_FILE = 'squawk-migration.json';
36
+ /** A project's fence and journal paths; none for a data directory that is not `<root>/.ai/{cezar,squawk}`. */
37
+ export function migrationFencePaths(dataDir) {
38
+ const directories = dataReadDirs(resolve(dataDir));
39
+ if (directories.length < 2)
40
+ return undefined;
41
+ const parent = dirname(directories[0]);
42
+ return { lock: join(parent, MIGRATION_FENCE_FILE), journal: join(parent, MIGRATION_JOURNAL_FILE) };
43
+ }
44
+ export class ProjectMigrationFencedError extends Error {
45
+ reason;
46
+ path;
47
+ constructor(reason, path, owner) {
48
+ const project = dirname(dirname(path));
49
+ super(reason === 'journal'
50
+ ? `An unfinished project migration (${path}) blocks ${project}. Finish it with the binary that migrated the project`
51
+ : reason === 'unreadable'
52
+ ? `Cannot read the project migration lock ${path}; a migration of another binary may hold ${project}. Remove the file only if no migration runs for this project`
53
+ : `A project migration (pid ${owner?.pid}${owner?.url ? ` at ${owner.url}` : ''}) holds ${project}; retry when it finishes`);
54
+ this.reason = reason;
55
+ this.path = path;
56
+ this.name = 'ProjectMigrationFencedError';
57
+ }
58
+ }
59
+ /**
60
+ * Why no new operation may touch the project of `dataDir`: a live or unreadable fence (this
61
+ * process's own fence included) or an unfinished journal. Dormant cost: two `lstat` calls.
62
+ * A dead owner without a journal admits; the next fence claim reclaims its file.
63
+ */
64
+ export function projectAdmissionRefusal(dataDir) {
65
+ const paths = migrationFencePaths(dataDir);
66
+ if (!paths)
67
+ return undefined;
68
+ if (pathPresent(paths.lock)) {
69
+ const owner = readOwner(paths.lock);
70
+ if (!owner && pathPresent(paths.lock))
71
+ return new ProjectMigrationFencedError('unreadable', paths.lock);
72
+ if (owner && alive(owner)) {
73
+ // Only the fence holder's own work passes: the migration engine and the holder's live-task
74
+ // check, run inside `asFenceHolder`. Everything else in this process is refused too.
75
+ if (heldFences.get(paths.lock) === owner.token && holderScope.getStore() === paths.lock)
76
+ return undefined;
77
+ return new ProjectMigrationFencedError('migrating', paths.lock, owner);
78
+ }
79
+ }
80
+ return pathPresent(paths.journal) ? new ProjectMigrationFencedError('journal', paths.journal) : undefined;
81
+ }
82
+ export function assertProjectAdmitted(dataDir) {
83
+ const refusal = projectAdmissionRefusal(dataDir);
84
+ if (refusal)
85
+ throw refusal;
86
+ }
87
+ /** Fences whose skipped writes have been logged, so each is logged once. */
88
+ const writeSkipsLogged = new Set();
89
+ /**
90
+ * The write backstop under every store write, claim and save: true while a fence or a journal
91
+ * refuses this project, outside the fence holder's own work. Offline, the migration CLI refuses
92
+ * while any cockpit it can see serves the project; this stops the writes of one it cannot see (a
93
+ * cockpit of another home that has the project registered). A skipped write is logged once per
94
+ * fence. Dormant cost: two `lstat` calls.
95
+ */
96
+ export function projectWriteRefused(dataDir) {
97
+ const lock = migrationFencePaths(dataDir)?.lock;
98
+ const refusal = lock && projectAdmissionRefusal(dataDir);
99
+ if (!lock || !refusal) {
100
+ // No refusal now: the next fence of this project logs its first skip again.
101
+ if (lock)
102
+ writeSkipsLogged.delete(lock);
103
+ return false;
104
+ }
105
+ if (!writeSkipsLogged.has(lock)) {
106
+ writeSkipsLogged.add(lock);
107
+ console.warn(`${logPrefix()} A write to ${dataDir} was skipped: ${refusal.message}`);
108
+ }
109
+ return true;
110
+ }
111
+ /** A CLI write: the project's migration admission is checked right before `write` runs. A CLI
112
+ * path runs each write that follows an await through it, not only its first one. */
113
+ export function admittedWrite(dataDir, write) {
114
+ assertProjectAdmitted(dataDir);
115
+ return write();
116
+ }
117
+ /** A durable commit refused by the backstop writes nothing and throws, as on a closed store. */
118
+ export function assertProjectWritable(dataDir) {
119
+ if (projectWriteRefused(dataDir))
120
+ assertProjectAdmitted(dataDir);
121
+ }
122
+ /** The token of every fence this process holds, by lock path. */
123
+ export const heldFences = new Map();
124
+ /** The fence whose holder work the current async call chain runs (`asFenceHolder`). */
125
+ const holderScope = new AsyncLocalStorage();
126
+ /** Whether this process holds the live migration fence of `dataDir`'s project: the project
127
+ * migration engine runs only under a fence its own process holds. */
128
+ export function holdsProjectFence(dataDir) {
129
+ const lock = migrationFencePaths(dataDir)?.lock;
130
+ const token = lock ? heldFences.get(lock) : undefined;
131
+ return token !== undefined && readOwner(lock)?.token === token;
132
+ }
133
+ /**
134
+ * Run `work` as the holder of `fence`: admission and the write backstop pass for this project
135
+ * inside it, and only inside it, so a cockpit that recovers a journal still refuses its own other
136
+ * requests for the project meanwhile.
137
+ */
138
+ export function asFenceHolder(fence, work) {
139
+ return holderScope.run(fence.lock, work);
140
+ }
141
+ /** Run `work` unless the project is fenced or has an unfinished journal; then answer `refused`. */
142
+ export async function withProjectAdmission(dataDir, work, refused) {
143
+ const refusal = projectAdmissionRefusal(dataDir);
144
+ return refusal ? refused(refusal) : work();
145
+ }
146
+ //# sourceMappingURL=project-fence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-fence.js","sourceRoot":"","sources":["../src/project-fence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IACxB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAGH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QAAC,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAAC,CAAC;IACzE,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAY;IAChC,2EAA2E;IAC3E,qDAAqD;IACrD,IAAI,CAAC;QAAC,OAAO,CAA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G,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,OAAO,KAAK,KAAK,SAAS,IAAI,SAAS,CAAC,IAAK,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC;AAClE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAI,KAA0C,EAAE,IAAa;IACxF,OAAO,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED,mGAAmG;AACnG,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAO,OAAe,EAAE,IAAsB,EAAE,OAAkD;IAC1I,MAAM,OAAO,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7C,CAAC"}
@@ -59,29 +59,6 @@ export declare function ciProgressPlugs(demand: ActivityDemand): {
59
59
  export declare function createActivityRoutes(routeDeps: ActivityRouteDeps): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
60
60
  "/workspace/activity": {
61
61
  $get: {
62
- output: {
63
- error: string;
64
- code?: "invalid_input" | undefined;
65
- };
66
- outputFormat: "json";
67
- status: 400;
68
- input: {
69
- query: {
70
- project?: string | undefined;
71
- };
72
- };
73
- } | {
74
- output: {
75
- error: string;
76
- };
77
- outputFormat: "json";
78
- status: 404 | 409 | 503;
79
- input: {
80
- query: {
81
- project?: string | undefined;
82
- };
83
- };
84
- } | {
85
62
  output: {
86
63
  generatedAt: string;
87
64
  projects: {
@@ -312,6 +289,29 @@ export declare function createActivityRoutes(routeDeps: ActivityRouteDeps): impo
312
289
  project?: string | undefined;
313
290
  };
314
291
  };
292
+ } | {
293
+ output: {
294
+ error: string;
295
+ code?: "invalid_input" | undefined;
296
+ };
297
+ outputFormat: "json";
298
+ status: 400;
299
+ input: {
300
+ query: {
301
+ project?: string | undefined;
302
+ };
303
+ };
304
+ } | {
305
+ output: {
306
+ error: string;
307
+ };
308
+ outputFormat: "json";
309
+ status: 404 | 409 | 503;
310
+ input: {
311
+ query: {
312
+ project?: string | undefined;
313
+ };
314
+ };
315
315
  };
316
316
  };
317
317
  }, "/", "/workspace/activity">;
@@ -1,58 +1,8 @@
1
- import { z } from 'zod';
2
- declare const ownerSchema: z.ZodObject<{
3
- pid: z.ZodNumber;
4
- token: z.ZodString;
5
- startToken: z.ZodOptional<z.ZodString>;
6
- url: z.ZodOptional<z.ZodString>;
7
- }, z.core.$strip>;
8
- type Owner = z.infer<typeof ownerSchema>;
1
+ import { type Owner, type ProjectMigrationFence } from '../project-fence.ts';
2
+ export { MIGRATION_FENCE_FILE, MIGRATION_JOURNAL_FILE, migrationFencePaths, ProjectMigrationFencedError, projectAdmissionRefusal, assertProjectAdmitted, projectWriteRefused, admittedWrite, assertProjectWritable, holdsProjectFence, asFenceHolder, withProjectAdmission, type ProjectMigrationFence } from '../project-fence.ts';
9
3
  export declare class CockpitAlreadyRunningError extends Error {
10
4
  constructor(dataDir: string, owner?: Owner, unreadableLock?: string);
11
5
  }
12
- /** The migration fence and its journal: beside both directory names, so moving one never moves them. */
13
- export declare const MIGRATION_FENCE_FILE = "squawk-migration.lock";
14
- export declare const MIGRATION_JOURNAL_FILE = "squawk-migration.json";
15
- /** A project's fence and journal paths; none for a data directory that is not `<root>/.ai/{cezar,squawk}`. */
16
- export declare function migrationFencePaths(dataDir: string): {
17
- lock: string;
18
- journal: string;
19
- } | undefined;
20
- export declare class ProjectMigrationFencedError extends Error {
21
- readonly reason: 'migrating' | 'journal' | 'unreadable';
22
- readonly path: string;
23
- constructor(reason: 'migrating' | 'journal' | 'unreadable', path: string, owner?: Owner);
24
- }
25
- /**
26
- * Why no new operation may touch the project of `dataDir`: a live or unreadable fence (this
27
- * process's own fence included) or an unfinished journal. Dormant cost: two `lstat` calls.
28
- * A dead owner without a journal admits; the next fence claim reclaims its file.
29
- */
30
- export declare function projectAdmissionRefusal(dataDir: string): ProjectMigrationFencedError | undefined;
31
- export declare function assertProjectAdmitted(dataDir: string): void;
32
- /**
33
- * The write backstop under every store write, claim and save: true while a fence or a journal
34
- * refuses this project, outside the fence holder's own work. Offline, the migration CLI refuses
35
- * while any cockpit it can see serves the project; this stops the writes of one it cannot see (a
36
- * cockpit of another home that has the project registered). A skipped write is logged once per
37
- * fence. Dormant cost: two `lstat` calls.
38
- */
39
- export declare function projectWriteRefused(dataDir: string): boolean;
40
- /** A CLI write: the project's migration admission is checked right before `write` runs. A CLI
41
- * path runs each write that follows an await through it, not only its first one. */
42
- export declare function admittedWrite<T>(dataDir: string, write: () => T): T;
43
- /** A durable commit refused by the backstop writes nothing and throws, as on a closed store. */
44
- export declare function assertProjectWritable(dataDir: string): void;
45
- /** Whether this process holds the live migration fence of `dataDir`'s project: the project
46
- * migration engine runs only under a fence its own process holds. */
47
- export declare function holdsProjectFence(dataDir: string): boolean;
48
- /**
49
- * Run `work` as the holder of `fence`: admission and the write backstop pass for this project
50
- * inside it, and only inside it, so a cockpit that recovers a journal still refuses its own other
51
- * requests for the project meanwhile.
52
- */
53
- export declare function asFenceHolder<T>(fence: Pick<ProjectMigrationFence, 'lock'>, work: () => T): T;
54
- /** Run `work` unless the project is fenced or has an unfinished journal; then answer `refused`. */
55
- export declare function withProjectAdmission<T, R>(dataDir: string, work: () => Promise<T>, refused: (error: ProjectMigrationFencedError) => R): Promise<T | R>;
56
6
  /** A task that is not terminal: it keeps a project from being fenced for a migration. */
57
7
  export interface LiveProjectTask {
58
8
  id: string;
@@ -65,12 +15,6 @@ export declare class ProjectMigrationBusyError extends Error {
65
15
  readonly project: string;
66
16
  constructor(tasks: readonly LiveProjectTask[], project: string);
67
17
  }
68
- /** A held migration fence: exclusive until `release`, which never removes another owner's claim. */
69
- export interface ProjectMigrationFence {
70
- lock: string;
71
- journal: string;
72
- release(): void;
73
- }
74
18
  /** The live cockpit other than this process that owns `dataDir`, if any: its pid and, once it
75
19
  * listens, its URL. Read-only: nothing is claimed. */
76
20
  export declare function anotherCockpitOwner(dataDir: string): {
@@ -109,4 +53,3 @@ export declare class CockpitOwnership {
109
53
  /** Only at process exit: managers may still have asynchronous work after dispose. */
110
54
  releaseAll(): void;
111
55
  }
112
- export {};
@@ -1,18 +1,11 @@
1
- import { logPrefix } from '../home/display.js';
2
1
  import { dataReadDirs, pathPresent } from '../project-paths.js';
3
- import { AsyncLocalStorage } from 'node:async_hooks';
4
2
  import { randomUUID } from 'node:crypto';
5
- import { existsSync, linkSync, mkdirSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
3
+ import { existsSync, linkSync, mkdirSync, realpathSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
6
4
  import { dirname, join, resolve } from 'node:path';
7
5
  import { setTimeout as delay } from 'node:timers/promises';
8
- import { z } from 'zod';
9
- import { processStartToken, recordedProcessLive } from '../delegation/process-liveness.js';
10
- const ownerSchema = z.object({
11
- pid: z.number().int().positive(),
12
- token: z.string().uuid(),
13
- startToken: z.string().optional(),
14
- url: z.string().url().optional(),
15
- });
6
+ import { processStartToken } from '../core/process-stat.js';
7
+ import { readOwner, alive, heldFences, migrationFencePaths, projectAdmissionRefusal, ProjectMigrationFencedError, asFenceHolder } from '../project-fence.js';
8
+ export { MIGRATION_FENCE_FILE, MIGRATION_JOURNAL_FILE, migrationFencePaths, ProjectMigrationFencedError, projectAdmissionRefusal, assertProjectAdmitted, projectWriteRefused, admittedWrite, assertProjectWritable, holdsProjectFence, asFenceHolder, withProjectAdmission } from '../project-fence.js';
16
9
  export class CockpitAlreadyRunningError extends Error {
17
10
  constructor(dataDir, owner, unreadableLock) {
18
11
  super(unreadableLock
@@ -23,29 +16,10 @@ export class CockpitAlreadyRunningError extends Error {
23
16
  this.name = 'CockpitAlreadyRunningError';
24
17
  }
25
18
  }
26
- function readOwner(path) {
27
- try {
28
- return ownerSchema.parse(JSON.parse(readFileSync(path, 'utf8')));
29
- }
30
- catch {
31
- return undefined;
32
- }
33
- }
34
19
  function newOwner() {
35
20
  const startToken = processStartToken(process.pid);
36
21
  return { pid: process.pid, token: randomUUID(), ...(startToken ? { startToken } : {}) };
37
22
  }
38
- function alive(owner) {
39
- // Keep unexpected OS probe failures conservative; only proven absence or a
40
- // different process incarnation permits reclamation.
41
- try {
42
- process.kill(owner.pid, 0);
43
- }
44
- catch (error) {
45
- return error.code !== 'ESRCH';
46
- }
47
- return recordedProcessLive(owner);
48
- }
49
23
  function release(path, owner) {
50
24
  // A delayed cleanup must never remove a replacement owner's claim.
51
25
  if (readOwner(path)?.token === owner.token) {
@@ -120,119 +94,6 @@ function claim(path, owner, depth = 0) {
120
94
  release(guard, gate);
121
95
  }
122
96
  }
123
- /** The migration fence and its journal: beside both directory names, so moving one never moves them. */
124
- export const MIGRATION_FENCE_FILE = 'squawk-migration.lock';
125
- export const MIGRATION_JOURNAL_FILE = 'squawk-migration.json';
126
- /** A project's fence and journal paths; none for a data directory that is not `<root>/.ai/{cezar,squawk}`. */
127
- export function migrationFencePaths(dataDir) {
128
- const directories = dataReadDirs(resolve(dataDir));
129
- if (directories.length < 2)
130
- return undefined;
131
- const parent = dirname(directories[0]);
132
- return { lock: join(parent, MIGRATION_FENCE_FILE), journal: join(parent, MIGRATION_JOURNAL_FILE) };
133
- }
134
- export class ProjectMigrationFencedError extends Error {
135
- reason;
136
- path;
137
- constructor(reason, path, owner) {
138
- const project = dirname(dirname(path));
139
- super(reason === 'journal'
140
- ? `An unfinished project migration (${path}) blocks ${project}. Finish it with the binary that migrated the project`
141
- : reason === 'unreadable'
142
- ? `Cannot read the project migration lock ${path}; a migration of another binary may hold ${project}. Remove the file only if no migration runs for this project`
143
- : `A project migration (pid ${owner?.pid}${owner?.url ? ` at ${owner.url}` : ''}) holds ${project}; retry when it finishes`);
144
- this.reason = reason;
145
- this.path = path;
146
- this.name = 'ProjectMigrationFencedError';
147
- }
148
- }
149
- /**
150
- * Why no new operation may touch the project of `dataDir`: a live or unreadable fence (this
151
- * process's own fence included) or an unfinished journal. Dormant cost: two `lstat` calls.
152
- * A dead owner without a journal admits; the next fence claim reclaims its file.
153
- */
154
- export function projectAdmissionRefusal(dataDir) {
155
- const paths = migrationFencePaths(dataDir);
156
- if (!paths)
157
- return undefined;
158
- if (pathPresent(paths.lock)) {
159
- const owner = readOwner(paths.lock);
160
- if (!owner && pathPresent(paths.lock))
161
- return new ProjectMigrationFencedError('unreadable', paths.lock);
162
- if (owner && alive(owner)) {
163
- // Only the fence holder's own work passes: the migration engine and the holder's live-task
164
- // check, run inside `asFenceHolder`. Everything else in this process is refused too.
165
- if (heldFences.get(paths.lock) === owner.token && holderScope.getStore() === paths.lock)
166
- return undefined;
167
- return new ProjectMigrationFencedError('migrating', paths.lock, owner);
168
- }
169
- }
170
- return pathPresent(paths.journal) ? new ProjectMigrationFencedError('journal', paths.journal) : undefined;
171
- }
172
- export function assertProjectAdmitted(dataDir) {
173
- const refusal = projectAdmissionRefusal(dataDir);
174
- if (refusal)
175
- throw refusal;
176
- }
177
- /** Fences whose skipped writes have been logged, so each is logged once. */
178
- const writeSkipsLogged = new Set();
179
- /**
180
- * The write backstop under every store write, claim and save: true while a fence or a journal
181
- * refuses this project, outside the fence holder's own work. Offline, the migration CLI refuses
182
- * while any cockpit it can see serves the project; this stops the writes of one it cannot see (a
183
- * cockpit of another home that has the project registered). A skipped write is logged once per
184
- * fence. Dormant cost: two `lstat` calls.
185
- */
186
- export function projectWriteRefused(dataDir) {
187
- const lock = migrationFencePaths(dataDir)?.lock;
188
- const refusal = lock && projectAdmissionRefusal(dataDir);
189
- if (!lock || !refusal) {
190
- // No refusal now: the next fence of this project logs its first skip again.
191
- if (lock)
192
- writeSkipsLogged.delete(lock);
193
- return false;
194
- }
195
- if (!writeSkipsLogged.has(lock)) {
196
- writeSkipsLogged.add(lock);
197
- console.warn(`${logPrefix()} A write to ${dataDir} was skipped: ${refusal.message}`);
198
- }
199
- return true;
200
- }
201
- /** A CLI write: the project's migration admission is checked right before `write` runs. A CLI
202
- * path runs each write that follows an await through it, not only its first one. */
203
- export function admittedWrite(dataDir, write) {
204
- assertProjectAdmitted(dataDir);
205
- return write();
206
- }
207
- /** A durable commit refused by the backstop writes nothing and throws, as on a closed store. */
208
- export function assertProjectWritable(dataDir) {
209
- if (projectWriteRefused(dataDir))
210
- assertProjectAdmitted(dataDir);
211
- }
212
- /** The token of every fence this process holds, by lock path. */
213
- const heldFences = new Map();
214
- /** The fence whose holder work the current async call chain runs (`asFenceHolder`). */
215
- const holderScope = new AsyncLocalStorage();
216
- /** Whether this process holds the live migration fence of `dataDir`'s project: the project
217
- * migration engine runs only under a fence its own process holds. */
218
- export function holdsProjectFence(dataDir) {
219
- const lock = migrationFencePaths(dataDir)?.lock;
220
- const token = lock ? heldFences.get(lock) : undefined;
221
- return token !== undefined && readOwner(lock)?.token === token;
222
- }
223
- /**
224
- * Run `work` as the holder of `fence`: admission and the write backstop pass for this project
225
- * inside it, and only inside it, so a cockpit that recovers a journal still refuses its own other
226
- * requests for the project meanwhile.
227
- */
228
- export function asFenceHolder(fence, work) {
229
- return holderScope.run(fence.lock, work);
230
- }
231
- /** Run `work` unless the project is fenced or has an unfinished journal; then answer `refused`. */
232
- export async function withProjectAdmission(dataDir, work, refused) {
233
- const refusal = projectAdmissionRefusal(dataDir);
234
- return refusal ? refused(refusal) : work();
235
- }
236
97
  /** The fence was refused: tasks are live. Nothing was claimed or moved. */
237
98
  export class ProjectMigrationBusyError extends Error {
238
99
  tasks;