jg-agent-hq 2.0.0 → 4.0.0
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/CHANGELOG.md +18 -0
- package/README.md +14 -14
- package/api/README.md +97 -65
- package/dist/actions/actions.js +15 -0
- package/dist/cli/cli.js +28 -5
- package/dist/cli/utilities.d.ts +3 -0
- package/dist/cli/utilities.js +13 -0
- package/dist/collaboration/dispatch/types.d.ts +2 -2
- package/dist/contracts/actions/types.d.ts +4 -4
- package/dist/contracts/browser/index.d.ts +1 -3
- package/dist/contracts/browser/index.js +1 -3
- package/dist/contracts/browser/types.d.ts +15 -1447
- package/dist/contracts/browser/types.js +3 -112
- package/dist/contracts/index.d.ts +9 -11
- package/dist/contracts/index.js +6 -8
- package/dist/contracts/plans/index.d.ts +4 -6
- package/dist/contracts/plans/index.js +2 -4
- package/dist/contracts/plans/types.d.ts +38 -905
- package/dist/contracts/plans/types.js +13 -139
- package/dist/contracts/sessions/index.d.ts +2 -0
- package/dist/contracts/sessions/index.js +2 -0
- package/dist/contracts/sessions/types.d.ts +101 -0
- package/dist/contracts/sessions/types.js +43 -0
- package/dist/contracts/types.d.ts +551 -1035
- package/dist/contracts/types.js +32 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/plans/admission.d.ts +6 -6
- package/dist/plans/admission.js +1 -1
- package/dist/plans/authority.d.ts +2 -0
- package/dist/plans/authority.js +23 -13
- package/dist/plans/documents.d.ts +20 -17
- package/dist/plans/documents.js +29 -63
- package/dist/plans/files.d.ts +2 -2
- package/dist/plans/files.js +5 -5
- package/dist/plans/finalization.d.ts +6 -8
- package/dist/plans/finalization.js +25 -26
- package/dist/plans/index.d.ts +2 -3
- package/dist/plans/index.js +1 -2
- package/dist/plans/plans.d.ts +8 -8
- package/dist/plans/plans.js +36 -83
- package/dist/plans/projections.d.ts +2 -2
- package/dist/plans/projections.js +44 -82
- package/dist/plans/revisions.d.ts +4 -5
- package/dist/plans/revisions.js +5 -44
- package/dist/plans/types.d.ts +5 -281
- package/dist/plans/types.js +2 -30
- package/dist/plans/utilities.js +2 -11
- package/dist/providers/claude/agents/agents.d.ts +16 -0
- package/dist/providers/claude/agents/agents.js +80 -0
- package/dist/providers/claude/agents/constants.d.ts +3 -0
- package/dist/providers/claude/agents/constants.js +4 -0
- package/dist/providers/claude/agents/index.d.ts +1 -0
- package/dist/providers/claude/agents/index.js +2 -0
- package/dist/providers/claude/agents/types.d.ts +14 -0
- package/dist/providers/claude/agents/types.js +9 -0
- package/dist/providers/claude/claude.js +2 -0
- package/dist/providers/claude/history/history.model.js +2 -0
- package/dist/providers/claude/history/types.d.ts +115 -368
- package/dist/providers/claude/index.d.ts +1 -0
- package/dist/providers/claude/index.js +2 -0
- package/dist/providers/claude/transformers.js +14 -1
- package/dist/providers/codex/adapter.d.ts +1 -1
- package/dist/providers/codex/adapter.js +26 -3
- package/dist/providers/codex/codex.js +51 -18
- package/dist/providers/codex/events.d.ts +2 -1
- package/dist/providers/codex/events.js +8 -3
- package/dist/providers/codex/index.d.ts +1 -1
- package/dist/providers/codex/index.js +1 -1
- package/dist/providers/codex/rpc.d.ts +9 -4
- package/dist/providers/codex/rpc.js +109 -47
- package/dist/providers/codex/skill-roots/constants.d.ts +4 -0
- package/dist/providers/codex/skill-roots/constants.js +7 -0
- package/dist/providers/codex/skill-roots/index.d.ts +2 -0
- package/dist/providers/codex/skill-roots/index.js +4 -0
- package/dist/providers/codex/skill-roots/skill-roots.d.ts +35 -0
- package/dist/providers/codex/skill-roots/skill-roots.js +93 -0
- package/dist/providers/codex/transformers.d.ts +3 -1
- package/dist/providers/codex/transformers.js +41 -3
- package/dist/providers/codex/types.d.ts +38 -1
- package/dist/providers/codex/types.js +15 -3
- package/dist/providers/codex/websocket/constants.d.ts +11 -0
- package/dist/providers/codex/websocket/constants.js +18 -0
- package/dist/providers/codex/websocket/index.d.ts +1 -0
- package/dist/providers/codex/websocket/index.js +2 -0
- package/dist/providers/codex/websocket/websocket.d.ts +7 -0
- package/dist/providers/codex/websocket/websocket.js +219 -0
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +1 -1
- package/dist/providers/process.d.ts +2 -2
- package/dist/providers/process.js +37 -4
- package/dist/providers/registry/registry.js +2 -1
- package/dist/providers/types.d.ts +25 -2
- package/dist/runtime/runtime.js +11 -3
- package/dist/runtime/state/index.d.ts +1 -1
- package/dist/runtime/state/index.js +1 -1
- package/dist/runtime/state/state.d.ts +15 -0
- package/dist/runtime/state/state.js +92 -1
- package/dist/runtime/types.d.ts +0 -2
- package/dist/runtime/types.js +0 -3
- package/dist/sessions/sessions.js +2 -0
- package/dist/snapshots/archive/archive.d.ts +29 -0
- package/dist/snapshots/archive/archive.js +342 -0
- package/dist/snapshots/archive/constants.d.ts +5 -0
- package/dist/snapshots/archive/constants.js +8 -0
- package/dist/snapshots/archive/index.d.ts +1 -0
- package/dist/snapshots/archive/index.js +2 -0
- package/dist/snapshots/artifacts.d.ts +10 -1
- package/dist/snapshots/artifacts.js +38 -13
- package/dist/snapshots/capture.d.ts +15 -0
- package/dist/snapshots/capture.js +158 -0
- package/dist/snapshots/database.d.ts +2 -0
- package/dist/snapshots/database.js +35 -55
- package/dist/snapshots/fences.d.ts +10 -0
- package/dist/snapshots/fences.js +51 -0
- package/dist/snapshots/index.d.ts +1 -0
- package/dist/snapshots/index.js +2 -0
- package/dist/snapshots/snapshots.d.ts +7 -3
- package/dist/snapshots/snapshots.js +31 -117
- package/dist/snapshots/snapshots.worker.js +5 -1
- package/dist/snapshots/types.d.ts +35 -3
- package/dist/snapshots/types.js +19 -4
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.js +2 -1
- package/dist/storage/schema/constants.d.ts +2 -0
- package/dist/storage/schema/constants.js +9 -0
- package/dist/storage/schema/index.d.ts +3 -0
- package/dist/storage/schema/index.js +6 -0
- package/dist/storage/schema/schema.d.ts +18 -0
- package/dist/storage/schema/schema.js +59 -0
- package/dist/storage/schema/types.d.ts +7 -0
- package/dist/storage/schema/types.js +8 -0
- package/dist/storage/storage.d.ts +1 -1
- package/dist/storage/storage.js +2 -2
- package/dist/storage/types.d.ts +0 -5
- package/dist/storage/types.js +0 -6
- package/dist/store/collaboration/collaboration.model.d.ts +2 -2
- package/dist/store/control/types.d.ts +16 -16
- package/dist/store/plans/plans.model.d.ts +3 -105
- package/dist/store/plans/plans.model.js +6 -46
- package/dist/store/schema.js +7 -35
- package/dist/store/schema.sql +91 -16
- package/dist/store/sessions/index.d.ts +1 -0
- package/dist/store/sessions/index.js +2 -0
- package/dist/store/sessions/sessions.model.d.ts +28 -0
- package/dist/store/sessions/sessions.model.js +105 -0
- package/dist/store/store.js +13 -7
- package/dist/store/store.worker.js +16 -11
- package/dist/store/types.d.ts +134 -513
- package/dist/store/types.js +21 -7
- package/docs/recovery.md +8 -4
- package/errors/README.md +3 -3
- package/package.json +2 -2
- package/dist/plans/reconciliation.d.ts +0 -34
- package/dist/plans/reconciliation.js +0 -246
package/dist/snapshots/types.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isAbsolute } from 'node:path';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { PlanRevisionSchema } from '../contracts/index.js';
|
|
3
4
|
const PathSchema = z.string().min(1).max(4096).refine(isAbsolute);
|
|
4
5
|
const HashSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
5
6
|
// one streamed inventory format; source paths are evidence, never output path components
|
|
@@ -8,6 +9,7 @@ export const SnapshotHeaderSchema = z.strictObject({
|
|
|
8
9
|
format: z.literal(1),
|
|
9
10
|
createdAt: z.iso.datetime(),
|
|
10
11
|
schemaHash: HashSchema,
|
|
12
|
+
packageVersion: z.string().min(1).max(64),
|
|
11
13
|
sourceStateRoot: PathSchema,
|
|
12
14
|
sourceCoordinationRoot: PathSchema,
|
|
13
15
|
sourceAllowedRoots: z.array(PathSchema).min(1).max(128),
|
|
@@ -21,13 +23,21 @@ export const SnapshotPlanSchema = z.strictObject({
|
|
|
21
23
|
key: HashSchema,
|
|
22
24
|
sourceDirectory: PathSchema,
|
|
23
25
|
planId: z.string().max(4096).nullable(),
|
|
24
|
-
|
|
26
|
+
// computed from the copied files, next to the revisions the captured database records
|
|
27
|
+
revision: PlanRevisionSchema.nullable(),
|
|
28
|
+
recordedRevisions: z.array(PlanRevisionSchema).max(32),
|
|
25
29
|
plan: SnapshotFileSchema.nullable(),
|
|
26
30
|
milestones: SnapshotFileSchema.nullable(),
|
|
27
31
|
coordination: SnapshotFileSchema.nullable(),
|
|
28
32
|
diagnostics: z
|
|
29
|
-
.array(z.enum([
|
|
30
|
-
|
|
33
|
+
.array(z.enum([
|
|
34
|
+
'plan-missing',
|
|
35
|
+
'plan-unavailable',
|
|
36
|
+
'plan-diagnostics',
|
|
37
|
+
'coordination-invalid',
|
|
38
|
+
'plan-changed',
|
|
39
|
+
]))
|
|
40
|
+
.max(4),
|
|
31
41
|
});
|
|
32
42
|
export const SnapshotRecordSchema = z.discriminatedUnion('kind', [
|
|
33
43
|
SnapshotHeaderSchema,
|
|
@@ -46,6 +56,7 @@ export const SnapshotInspectionSchema = z.object({
|
|
|
46
56
|
header: SnapshotHeaderSchema,
|
|
47
57
|
planCount: z.number().int().nonnegative(),
|
|
48
58
|
diagnosticPlanCount: z.number().int().nonnegative(),
|
|
59
|
+
changedPlanCount: z.number().int().nonnegative(),
|
|
49
60
|
pendingWriteCount: z.number().int().nonnegative(),
|
|
50
61
|
});
|
|
51
62
|
export const RestoreOptionsSchema = z.strictObject({
|
|
@@ -60,7 +71,11 @@ export const SnapshotWorkerResponseSchema = z.discriminatedUnion('kind', [
|
|
|
60
71
|
z.object({ kind: z.literal('result'), result: SnapshotInspectionSchema }),
|
|
61
72
|
z.object({
|
|
62
73
|
kind: z.literal('error'),
|
|
63
|
-
code: z.enum([
|
|
74
|
+
code: z.enum([
|
|
75
|
+
'JG_AGENT_HQ_SNAPSHOT_INVALID',
|
|
76
|
+
'JG_AGENT_HQ_SNAPSHOT_FAILED',
|
|
77
|
+
'JG_AGENT_HQ_STORAGE_INVALID',
|
|
78
|
+
]),
|
|
64
79
|
message: z.string(),
|
|
65
80
|
}),
|
|
66
81
|
]);
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { StorageDescriptorSchema
|
|
1
|
+
export { StorageDescriptorSchema } from './types.js';
|
|
2
|
+
export { StorageStampSchema } from './schema/index.js';
|
|
2
3
|
export type { IStorageDescriptor, IStorageMaintenanceOperation } from './types.js';
|
|
3
4
|
export { STORAGE_CONNECTION_SETTINGS } from './constants.js';
|
|
4
5
|
export { createStorage } from './storage.js';
|
package/dist/storage/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// types and validated worker metadata
|
|
2
|
-
export { StorageDescriptorSchema
|
|
2
|
+
export { StorageDescriptorSchema } from './types.js';
|
|
3
|
+
export { StorageStampSchema } from './schema/index.js';
|
|
3
4
|
// required connection settings
|
|
4
5
|
export { STORAGE_CONNECTION_SETTINGS } from './constants.js';
|
|
5
6
|
// runtime maintenance admission
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { hashValue } from 'jg-crypto';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
// the version stamped into databases and snapshots this package writes
|
|
5
|
+
export const PACKAGE_VERSION = z
|
|
6
|
+
.object({ version: z.string().min(1).max(64) })
|
|
7
|
+
.parse(JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'))).version;
|
|
8
|
+
// the one schema this package reads; package-owned SQL is immutable during a process lifetime
|
|
9
|
+
export const CURRENT_SCHEMA_HASH = hashValue(readFileSync(new URL('../../store/schema.sql', import.meta.url)));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
/**
|
|
3
|
+
* Rejects storage written by another schema, naming the package version that wrote it.
|
|
4
|
+
* @throws
|
|
5
|
+
* - JG_AGENT_HQ_STORAGE_INVALID: The HQ storage is invalid
|
|
6
|
+
*/
|
|
7
|
+
export declare const rejectStorage: (packageVersion: string | null, cause?: unknown) => never;
|
|
8
|
+
/**
|
|
9
|
+
* Recognizes the current schema's stamp without writing or adopting an arbitrary database.
|
|
10
|
+
* @returns The stamped action key hash and package version, or null for a completely empty database.
|
|
11
|
+
* @throws
|
|
12
|
+
* - JG_AGENT_HQ_STORAGE_INVALID: The HQ storage is invalid
|
|
13
|
+
* - JG_AGENT_HQ_ACTION_KEY_UNAVAILABLE: The HQ action key is unavailable
|
|
14
|
+
*/
|
|
15
|
+
export declare const readStorageStamp: (database: DatabaseSync, actionKeyHash?: string) => {
|
|
16
|
+
actionKeyHash: string;
|
|
17
|
+
packageVersion: string;
|
|
18
|
+
} | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Exception, isException, extractMessage } from 'jg-exception';
|
|
2
|
+
import { CURRENT_SCHEMA_HASH } from './constants.js';
|
|
3
|
+
import { StorageStampSchema } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Rejects storage written by another schema, naming the package version that wrote it.
|
|
6
|
+
* @throws
|
|
7
|
+
* - JG_AGENT_HQ_STORAGE_INVALID: The HQ storage is invalid
|
|
8
|
+
*/
|
|
9
|
+
export const rejectStorage = (packageVersion, cause) => {
|
|
10
|
+
throw new Exception(`The HQ storage is invalid: written by ${packageVersion ? `jg-agent-hq ${packageVersion}` : 'another jg-agent-hq version'}`, { code: 'JG_AGENT_HQ_STORAGE_INVALID', data: { kind: 'state-conflict' }, cause });
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Recognizes the current schema's stamp without writing or adopting an arbitrary database.
|
|
14
|
+
* @returns The stamped action key hash and package version, or null for a completely empty database.
|
|
15
|
+
* @throws
|
|
16
|
+
* - JG_AGENT_HQ_STORAGE_INVALID: The HQ storage is invalid
|
|
17
|
+
* - JG_AGENT_HQ_ACTION_KEY_UNAVAILABLE: The HQ action key is unavailable
|
|
18
|
+
*/
|
|
19
|
+
export const readStorageStamp = (database, actionKeyHash) => {
|
|
20
|
+
try {
|
|
21
|
+
if (!database.prepare('SELECT 1 FROM sqlite_schema LIMIT 1').get())
|
|
22
|
+
return null;
|
|
23
|
+
const columns = database
|
|
24
|
+
.prepare('PRAGMA table_xinfo(hq_schema)')
|
|
25
|
+
.all()
|
|
26
|
+
.map((column) => column.name);
|
|
27
|
+
// a stamp without the package version comes from an earlier package
|
|
28
|
+
if (columns.length && !columns.includes('package_version'))
|
|
29
|
+
rejectStorage(null);
|
|
30
|
+
const rows = database
|
|
31
|
+
.prepare('SELECT id, schema_hash, action_key_hash, package_version FROM hq_schema LIMIT 2')
|
|
32
|
+
.all();
|
|
33
|
+
const parsed = StorageStampSchema.safeParse(rows.length === 1 ? rows[0] : null);
|
|
34
|
+
if (!parsed.success)
|
|
35
|
+
throw new Exception('The HQ storage is invalid', {
|
|
36
|
+
code: 'JG_AGENT_HQ_STORAGE_INVALID',
|
|
37
|
+
data: { kind: 'state-conflict' },
|
|
38
|
+
cause: parsed.error,
|
|
39
|
+
});
|
|
40
|
+
const stamp = parsed.data;
|
|
41
|
+
if (stamp.schema_hash !== CURRENT_SCHEMA_HASH)
|
|
42
|
+
rejectStorage(stamp.package_version);
|
|
43
|
+
if (actionKeyHash !== undefined && stamp.action_key_hash !== actionKeyHash)
|
|
44
|
+
throw new Exception('The HQ action key is unavailable', {
|
|
45
|
+
code: 'JG_AGENT_HQ_ACTION_KEY_UNAVAILABLE',
|
|
46
|
+
data: { kind: 'state-conflict' },
|
|
47
|
+
});
|
|
48
|
+
return { actionKeyHash: stamp.action_key_hash, packageVersion: stamp.package_version };
|
|
49
|
+
}
|
|
50
|
+
catch (cause) {
|
|
51
|
+
if (isException(cause))
|
|
52
|
+
throw cause;
|
|
53
|
+
throw new Exception(`The HQ storage is invalid: ${extractMessage(cause)}`, {
|
|
54
|
+
code: 'JG_AGENT_HQ_STORAGE_INVALID',
|
|
55
|
+
data: { kind: 'state-conflict' },
|
|
56
|
+
cause,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// singleton identity of the schema, the action key and the package version that wrote them
|
|
3
|
+
export const StorageStampSchema = z.object({
|
|
4
|
+
id: z.literal(1),
|
|
5
|
+
schema_hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
6
|
+
action_key_hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
7
|
+
package_version: z.string().min(1).max(64),
|
|
8
|
+
});
|
|
@@ -8,6 +8,6 @@ import type { IStorageMaintenanceOperation } from './types.js';
|
|
|
8
8
|
export declare const createStorage: (store: IStore) => {
|
|
9
9
|
run: <T>(operation: () => Promise<T>) => Promise<T>;
|
|
10
10
|
background: <T>(operation: () => Promise<T>) => Promise<T>;
|
|
11
|
-
withStorageMaintenance: <T>(operation: IStorageMaintenanceOperation<T
|
|
11
|
+
withStorageMaintenance: <T>(operation: IStorageMaintenanceOperation<T>) => Promise<T>;
|
|
12
12
|
dispose: () => void;
|
|
13
13
|
};
|
package/dist/storage/storage.js
CHANGED
|
@@ -63,7 +63,7 @@ export const createStorage = (store) => {
|
|
|
63
63
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
64
64
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
65
65
|
*/
|
|
66
|
-
const withStorageMaintenance = async (operation
|
|
66
|
+
const withStorageMaintenance = async (operation) => {
|
|
67
67
|
if (typeof operation !== 'function')
|
|
68
68
|
throw new Exception('The HQ request is invalid', {
|
|
69
69
|
code: 'JG_AGENT_HQ_REQUEST_INVALID',
|
|
@@ -79,7 +79,7 @@ export const createStorage = (store) => {
|
|
|
79
79
|
while (active.size > 0)
|
|
80
80
|
await Promise.allSettled([...active]);
|
|
81
81
|
isMaintenanceHeld = true;
|
|
82
|
-
if (!(await store.prepareStorageMaintenance(
|
|
82
|
+
if (!(await store.prepareStorageMaintenance()))
|
|
83
83
|
conflict();
|
|
84
84
|
return await operation(structuredClone(store.storage));
|
|
85
85
|
}
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const StorageStampSchema: z.ZodObject<{
|
|
3
|
-
id: z.ZodLiteral<1>;
|
|
4
|
-
schema_hash: z.ZodString;
|
|
5
|
-
action_key_hash: z.ZodString;
|
|
6
|
-
}, z.core.$strip>;
|
|
7
2
|
export declare const StorageDescriptorSchema: z.ZodObject<{
|
|
8
3
|
databasePath: z.ZodString;
|
|
9
4
|
schemaHash: z.ZodString;
|
package/dist/storage/types.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { STORAGE_CONNECTION_SETTINGS } from './constants.js';
|
|
3
|
-
// singleton identity binding the current HQ schema and private action key
|
|
4
|
-
export const StorageStampSchema = z.object({
|
|
5
|
-
id: z.literal(1),
|
|
6
|
-
schema_hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
7
|
-
action_key_hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
8
|
-
});
|
|
9
3
|
// trusted Node-only metadata; application tables have independent schema ownership
|
|
10
4
|
export const StorageDescriptorSchema = z.object({
|
|
11
5
|
databasePath: z.string().min(1),
|
|
@@ -219,10 +219,10 @@ export declare class CollaborationModel {
|
|
|
219
219
|
isArchived: boolean;
|
|
220
220
|
name: string;
|
|
221
221
|
workspaceRoot: string;
|
|
222
|
-
ownership: "
|
|
222
|
+
ownership: "managed" | "uncertain";
|
|
223
223
|
runtimeEpoch: string | null;
|
|
224
224
|
activeTurnId: string | null;
|
|
225
|
-
state: "unknown" | "idle" | "completed" | "failed" | "interrupted" | "waiting-input" | "
|
|
225
|
+
state: "unknown" | "idle" | "completed" | "failed" | "interrupted" | "waiting-input" | "running" | "creating" | "inactive" | "starting" | "waiting-approval" | "stopping";
|
|
226
226
|
createdAt: number;
|
|
227
227
|
updatedAt: number;
|
|
228
228
|
} | null;
|
|
@@ -9,8 +9,8 @@ export declare const ThreadRowSchema: z.ZodObject<{
|
|
|
9
9
|
name: z.ZodString;
|
|
10
10
|
workspace_root: z.ZodString;
|
|
11
11
|
ownership: z.ZodEnum<{
|
|
12
|
-
uncertain: "uncertain";
|
|
13
12
|
managed: "managed";
|
|
13
|
+
uncertain: "uncertain";
|
|
14
14
|
}>;
|
|
15
15
|
runtime_epoch: z.ZodNullable<z.ZodUUID>;
|
|
16
16
|
active_turn_id: z.ZodNullable<z.ZodString>;
|
|
@@ -28,10 +28,10 @@ export declare const ThreadRowSchema: z.ZodObject<{
|
|
|
28
28
|
failed: "failed";
|
|
29
29
|
interrupted: "interrupted";
|
|
30
30
|
"waiting-input": "waiting-input";
|
|
31
|
+
running: "running";
|
|
31
32
|
creating: "creating";
|
|
32
33
|
inactive: "inactive";
|
|
33
34
|
starting: "starting";
|
|
34
|
-
running: "running";
|
|
35
35
|
"waiting-approval": "waiting-approval";
|
|
36
36
|
stopping: "stopping";
|
|
37
37
|
}>;
|
|
@@ -87,10 +87,10 @@ export declare const ActionRowSchema: z.ZodObject<{
|
|
|
87
87
|
delivery: z.ZodEnum<{
|
|
88
88
|
failed: "failed";
|
|
89
89
|
canceled: "canceled";
|
|
90
|
+
uncertain: "uncertain";
|
|
90
91
|
queued: "queued";
|
|
91
92
|
submitted: "submitted";
|
|
92
93
|
acknowledged: "acknowledged";
|
|
93
|
-
uncertain: "uncertain";
|
|
94
94
|
}>;
|
|
95
95
|
completion: z.ZodNullable<z.ZodEnum<{
|
|
96
96
|
completed: "completed";
|
|
@@ -699,10 +699,10 @@ export declare const AdmissionResultSchema: z.ZodObject<{
|
|
|
699
699
|
delivery: z.ZodEnum<{
|
|
700
700
|
failed: "failed";
|
|
701
701
|
canceled: "canceled";
|
|
702
|
+
uncertain: "uncertain";
|
|
702
703
|
queued: "queued";
|
|
703
704
|
submitted: "submitted";
|
|
704
705
|
acknowledged: "acknowledged";
|
|
705
|
-
uncertain: "uncertain";
|
|
706
706
|
}>;
|
|
707
707
|
completion: z.ZodNullable<z.ZodEnum<{
|
|
708
708
|
completed: "completed";
|
|
@@ -811,8 +811,8 @@ export declare const AdmissionResultSchema: z.ZodObject<{
|
|
|
811
811
|
name: z.ZodString;
|
|
812
812
|
workspaceRoot: z.ZodString;
|
|
813
813
|
ownership: z.ZodEnum<{
|
|
814
|
-
uncertain: "uncertain";
|
|
815
814
|
managed: "managed";
|
|
815
|
+
uncertain: "uncertain";
|
|
816
816
|
}>;
|
|
817
817
|
runtimeEpoch: z.ZodNullable<z.ZodUUID>;
|
|
818
818
|
activeTurnId: z.ZodNullable<z.ZodString>;
|
|
@@ -823,10 +823,10 @@ export declare const AdmissionResultSchema: z.ZodObject<{
|
|
|
823
823
|
failed: "failed";
|
|
824
824
|
interrupted: "interrupted";
|
|
825
825
|
"waiting-input": "waiting-input";
|
|
826
|
+
running: "running";
|
|
826
827
|
creating: "creating";
|
|
827
828
|
inactive: "inactive";
|
|
828
829
|
starting: "starting";
|
|
829
|
-
running: "running";
|
|
830
830
|
"waiting-approval": "waiting-approval";
|
|
831
831
|
stopping: "stopping";
|
|
832
832
|
}>;
|
|
@@ -883,10 +883,10 @@ export declare const DispatchSchema: z.ZodObject<{
|
|
|
883
883
|
delivery: z.ZodEnum<{
|
|
884
884
|
failed: "failed";
|
|
885
885
|
canceled: "canceled";
|
|
886
|
+
uncertain: "uncertain";
|
|
886
887
|
queued: "queued";
|
|
887
888
|
submitted: "submitted";
|
|
888
889
|
acknowledged: "acknowledged";
|
|
889
|
-
uncertain: "uncertain";
|
|
890
890
|
}>;
|
|
891
891
|
completion: z.ZodNullable<z.ZodEnum<{
|
|
892
892
|
completed: "completed";
|
|
@@ -995,8 +995,8 @@ export declare const DispatchSchema: z.ZodObject<{
|
|
|
995
995
|
name: z.ZodString;
|
|
996
996
|
workspaceRoot: z.ZodString;
|
|
997
997
|
ownership: z.ZodEnum<{
|
|
998
|
-
uncertain: "uncertain";
|
|
999
998
|
managed: "managed";
|
|
999
|
+
uncertain: "uncertain";
|
|
1000
1000
|
}>;
|
|
1001
1001
|
runtimeEpoch: z.ZodNullable<z.ZodUUID>;
|
|
1002
1002
|
activeTurnId: z.ZodNullable<z.ZodString>;
|
|
@@ -1007,10 +1007,10 @@ export declare const DispatchSchema: z.ZodObject<{
|
|
|
1007
1007
|
failed: "failed";
|
|
1008
1008
|
interrupted: "interrupted";
|
|
1009
1009
|
"waiting-input": "waiting-input";
|
|
1010
|
+
running: "running";
|
|
1010
1011
|
creating: "creating";
|
|
1011
1012
|
inactive: "inactive";
|
|
1012
1013
|
starting: "starting";
|
|
1013
|
-
running: "running";
|
|
1014
1014
|
"waiting-approval": "waiting-approval";
|
|
1015
1015
|
stopping: "stopping";
|
|
1016
1016
|
}>;
|
|
@@ -1059,8 +1059,8 @@ export declare const ObservationResultSchema: z.ZodObject<{
|
|
|
1059
1059
|
name: z.ZodString;
|
|
1060
1060
|
workspaceRoot: z.ZodString;
|
|
1061
1061
|
ownership: z.ZodEnum<{
|
|
1062
|
-
uncertain: "uncertain";
|
|
1063
1062
|
managed: "managed";
|
|
1063
|
+
uncertain: "uncertain";
|
|
1064
1064
|
}>;
|
|
1065
1065
|
runtimeEpoch: z.ZodNullable<z.ZodUUID>;
|
|
1066
1066
|
activeTurnId: z.ZodNullable<z.ZodString>;
|
|
@@ -1071,10 +1071,10 @@ export declare const ObservationResultSchema: z.ZodObject<{
|
|
|
1071
1071
|
failed: "failed";
|
|
1072
1072
|
interrupted: "interrupted";
|
|
1073
1073
|
"waiting-input": "waiting-input";
|
|
1074
|
+
running: "running";
|
|
1074
1075
|
creating: "creating";
|
|
1075
1076
|
inactive: "inactive";
|
|
1076
1077
|
starting: "starting";
|
|
1077
|
-
running: "running";
|
|
1078
1078
|
"waiting-approval": "waiting-approval";
|
|
1079
1079
|
stopping: "stopping";
|
|
1080
1080
|
}>;
|
|
@@ -1143,8 +1143,8 @@ export declare const ManagedThreadPageSchema: z.ZodObject<{
|
|
|
1143
1143
|
name: z.ZodString;
|
|
1144
1144
|
workspaceRoot: z.ZodString;
|
|
1145
1145
|
ownership: z.ZodEnum<{
|
|
1146
|
-
uncertain: "uncertain";
|
|
1147
1146
|
managed: "managed";
|
|
1147
|
+
uncertain: "uncertain";
|
|
1148
1148
|
}>;
|
|
1149
1149
|
runtimeEpoch: z.ZodNullable<z.ZodUUID>;
|
|
1150
1150
|
activeTurnId: z.ZodNullable<z.ZodString>;
|
|
@@ -1155,10 +1155,10 @@ export declare const ManagedThreadPageSchema: z.ZodObject<{
|
|
|
1155
1155
|
failed: "failed";
|
|
1156
1156
|
interrupted: "interrupted";
|
|
1157
1157
|
"waiting-input": "waiting-input";
|
|
1158
|
+
running: "running";
|
|
1158
1159
|
creating: "creating";
|
|
1159
1160
|
inactive: "inactive";
|
|
1160
1161
|
starting: "starting";
|
|
1161
|
-
running: "running";
|
|
1162
1162
|
"waiting-approval": "waiting-approval";
|
|
1163
1163
|
stopping: "stopping";
|
|
1164
1164
|
}>;
|
|
@@ -1219,10 +1219,10 @@ export declare const ActionPageSchema: z.ZodObject<{
|
|
|
1219
1219
|
delivery: z.ZodEnum<{
|
|
1220
1220
|
failed: "failed";
|
|
1221
1221
|
canceled: "canceled";
|
|
1222
|
+
uncertain: "uncertain";
|
|
1222
1223
|
queued: "queued";
|
|
1223
1224
|
submitted: "submitted";
|
|
1224
1225
|
acknowledged: "acknowledged";
|
|
1225
|
-
uncertain: "uncertain";
|
|
1226
1226
|
}>;
|
|
1227
1227
|
digest: z.ZodString;
|
|
1228
1228
|
controlState: z.ZodNullable<z.ZodEnum<{
|
|
@@ -1322,8 +1322,8 @@ export declare const ApprovalIdentitySchema: z.ZodObject<{
|
|
|
1322
1322
|
name: z.ZodString;
|
|
1323
1323
|
workspaceRoot: z.ZodString;
|
|
1324
1324
|
ownership: z.ZodEnum<{
|
|
1325
|
-
uncertain: "uncertain";
|
|
1326
1325
|
managed: "managed";
|
|
1326
|
+
uncertain: "uncertain";
|
|
1327
1327
|
}>;
|
|
1328
1328
|
runtimeEpoch: z.ZodNullable<z.ZodUUID>;
|
|
1329
1329
|
activeTurnId: z.ZodNullable<z.ZodString>;
|
|
@@ -1334,10 +1334,10 @@ export declare const ApprovalIdentitySchema: z.ZodObject<{
|
|
|
1334
1334
|
failed: "failed";
|
|
1335
1335
|
interrupted: "interrupted";
|
|
1336
1336
|
"waiting-input": "waiting-input";
|
|
1337
|
+
running: "running";
|
|
1337
1338
|
creating: "creating";
|
|
1338
1339
|
inactive: "inactive";
|
|
1339
1340
|
starting: "starting";
|
|
1340
|
-
running: "running";
|
|
1341
1341
|
"waiting-approval": "waiting-approval";
|
|
1342
1342
|
stopping: "stopping";
|
|
1343
1343
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { PlanMilestoneSchema, type IActionPlanContext } from '../../contracts/index.js';
|
|
4
|
-
import { type IPlanWriteIntent, type IPlanProjection
|
|
4
|
+
import { type IPlanWriteIntent, type IPlanProjection } from '../../plans/index.js';
|
|
5
5
|
/** Owns selected-plan projections and write replay identities inside the SQLite worker. */
|
|
6
6
|
export declare class PlansModel {
|
|
7
7
|
private readonly __database;
|
|
@@ -32,110 +32,8 @@ export declare class PlansModel {
|
|
|
32
32
|
data: z.infer<typeof PlanMilestoneSchema>[];
|
|
33
33
|
hasMore: boolean;
|
|
34
34
|
};
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
/** Reads one indexed seek page with additional response-byte headroom. */
|
|
38
|
-
listRevision(page: {
|
|
39
|
-
directory: string;
|
|
40
|
-
collection: string;
|
|
41
|
-
after: string;
|
|
42
|
-
limit: number;
|
|
43
|
-
}): {
|
|
44
|
-
data: ({
|
|
45
|
-
kind: "source";
|
|
46
|
-
entry: {
|
|
47
|
-
ordinal: number;
|
|
48
|
-
title: string;
|
|
49
|
-
status: "pending" | "in progress" | "done";
|
|
50
|
-
id: string;
|
|
51
|
-
contractDigest: string;
|
|
52
|
-
contract: string;
|
|
53
|
-
sharedDigest: string;
|
|
54
|
-
};
|
|
55
|
-
} | {
|
|
56
|
-
kind: "draft";
|
|
57
|
-
entry: {
|
|
58
|
-
ordinal: number;
|
|
59
|
-
title: string;
|
|
60
|
-
status: "pending" | "in progress" | "done";
|
|
61
|
-
id: string;
|
|
62
|
-
contractDigest: string;
|
|
63
|
-
contract: string;
|
|
64
|
-
sharedDigest: string;
|
|
65
|
-
matchedSourceId: string | null;
|
|
66
|
-
};
|
|
67
|
-
} | {
|
|
68
|
-
kind: "evidence";
|
|
69
|
-
entry: {
|
|
70
|
-
id: string;
|
|
71
|
-
action: {
|
|
72
|
-
id: string;
|
|
73
|
-
operatorId: string;
|
|
74
|
-
source: {
|
|
75
|
-
kind: "user-action" | "user-message";
|
|
76
|
-
reference: string;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
milestoneId: string | null;
|
|
80
|
-
revision: {
|
|
81
|
-
planDigest: string;
|
|
82
|
-
breakdownDigest: string | null;
|
|
83
|
-
};
|
|
84
|
-
contractDigest: string;
|
|
85
|
-
title: string;
|
|
86
|
-
contract: string;
|
|
87
|
-
sharedDigest: string | null;
|
|
88
|
-
checkouts: {
|
|
89
|
-
repository: string;
|
|
90
|
-
directory: string;
|
|
91
|
-
claimReference: string;
|
|
92
|
-
paths: string[];
|
|
93
|
-
branch: string | null;
|
|
94
|
-
head: string;
|
|
95
|
-
fingerprint: string;
|
|
96
|
-
}[];
|
|
97
|
-
checks: {
|
|
98
|
-
command: string;
|
|
99
|
-
outcome: "passed";
|
|
100
|
-
reference: string;
|
|
101
|
-
}[];
|
|
102
|
-
completedAt: number;
|
|
103
|
-
reopenActionId: string | null;
|
|
104
|
-
};
|
|
105
|
-
} | {
|
|
106
|
-
kind: "correspondence";
|
|
107
|
-
entry: {
|
|
108
|
-
id: string;
|
|
109
|
-
action: {
|
|
110
|
-
id: string;
|
|
111
|
-
operatorId: string;
|
|
112
|
-
source: {
|
|
113
|
-
kind: "user-action" | "user-message";
|
|
114
|
-
reference: string;
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
revision: {
|
|
118
|
-
planDigest: string;
|
|
119
|
-
breakdownDigest: string | null;
|
|
120
|
-
};
|
|
121
|
-
relation: "equivalent" | "requirements-changed" | "omitted" | "reopened";
|
|
122
|
-
targets: {
|
|
123
|
-
id: string;
|
|
124
|
-
contractDigest: string;
|
|
125
|
-
status: "pending" | "in progress" | "done";
|
|
126
|
-
}[];
|
|
127
|
-
invalidatedReceiptIds: string[];
|
|
128
|
-
recordedAt: number;
|
|
129
|
-
sources: {
|
|
130
|
-
id: string;
|
|
131
|
-
status: "pending" | "in progress" | "done";
|
|
132
|
-
contractDigest: string;
|
|
133
|
-
}[];
|
|
134
|
-
};
|
|
135
|
-
})[];
|
|
136
|
-
lastId: string | null;
|
|
137
|
-
hasMore: boolean;
|
|
138
|
-
};
|
|
35
|
+
/** Records a plan directory for snapshot capture; an existing registration is kept. */
|
|
36
|
+
register(directory: string): void;
|
|
139
37
|
/** Resolves one thread's current guided scope without trusting its display label. */
|
|
140
38
|
getThreadPlan(threadId: string): IActionPlanContext | null;
|
|
141
39
|
/** Finds the bounded managed/uncertain cohort that must stop before this plan can be edited. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Exception } from 'jg-exception';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { PlanMilestoneSchema,
|
|
3
|
+
import { PlanMilestoneSchema, ActionPlanContextSchema, } from '../../contracts/index.js';
|
|
4
4
|
import { PlanWriteIntentSchema, } from '../../plans/index.js';
|
|
5
5
|
/** Owns selected-plan projections and write replay identities inside the SQLite worker. */
|
|
6
6
|
export class PlansModel {
|
|
@@ -117,51 +117,11 @@ export class PlansModel {
|
|
|
117
117
|
hasMore,
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.prepare('
|
|
124
|
-
.
|
|
125
|
-
if (current && current.source_hash === projection.sourceHash)
|
|
126
|
-
return;
|
|
127
|
-
this.__database.exec('BEGIN IMMEDIATE');
|
|
128
|
-
try {
|
|
129
|
-
this.__database
|
|
130
|
-
.prepare('DELETE FROM hq_plan_record WHERE directory = ?')
|
|
131
|
-
.run(projection.directory);
|
|
132
|
-
const insert = this.__database.prepare('INSERT INTO hq_plan_record (directory, collection, record_id, entry) VALUES (?, ?, ?, ?)');
|
|
133
|
-
for (const row of projection.records)
|
|
134
|
-
insert.run(projection.directory, row.collection, row.id, JSON.stringify(row.entry));
|
|
135
|
-
this.__database
|
|
136
|
-
.prepare('INSERT INTO hq_plan_revision_projection (directory, source_hash) VALUES (?, ?) ON CONFLICT(directory) DO UPDATE SET source_hash = excluded.source_hash')
|
|
137
|
-
.run(projection.directory, projection.sourceHash);
|
|
138
|
-
this.__database.exec('COMMIT');
|
|
139
|
-
}
|
|
140
|
-
catch (cause) {
|
|
141
|
-
this.__database.exec('ROLLBACK');
|
|
142
|
-
throw cause;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/** Reads one indexed seek page with additional response-byte headroom. */
|
|
146
|
-
listRevision(page) {
|
|
147
|
-
const rows = this.__database
|
|
148
|
-
.prepare('SELECT record_id, entry FROM hq_plan_record WHERE directory = ? AND collection = ? AND record_id > ? ORDER BY record_id LIMIT ?')
|
|
149
|
-
.all(page.directory, page.collection, page.after, page.limit + 1);
|
|
150
|
-
const data = [];
|
|
151
|
-
let bytes = 0;
|
|
152
|
-
let lastId = null;
|
|
153
|
-
for (const row of rows) {
|
|
154
|
-
if (data.length === page.limit)
|
|
155
|
-
break;
|
|
156
|
-
const entry = z.string().parse(row.entry);
|
|
157
|
-
const size = Buffer.byteLength(entry);
|
|
158
|
-
if (data.length && bytes + size > 4_194_304)
|
|
159
|
-
break;
|
|
160
|
-
data.push(PlanReconciliationEntrySchema.parse(JSON.parse(entry)));
|
|
161
|
-
bytes += size;
|
|
162
|
-
lastId = z.string().parse(row.record_id);
|
|
163
|
-
}
|
|
164
|
-
return { data, lastId, hasMore: rows.length > data.length };
|
|
120
|
+
/** Records a plan directory for snapshot capture; an existing registration is kept. */
|
|
121
|
+
register(directory) {
|
|
122
|
+
this.__database
|
|
123
|
+
.prepare('INSERT INTO hq_plan_registration (directory) VALUES (?) ON CONFLICT(directory) DO NOTHING')
|
|
124
|
+
.run(directory);
|
|
165
125
|
}
|
|
166
126
|
/** Resolves one thread's current guided scope without trusting its display label. */
|
|
167
127
|
getThreadPlan(threadId) {
|