jg-agent-hq 8.0.2 → 9.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 +16 -0
- package/README.md +18 -37
- package/api/README.md +51 -243
- package/dist/actions/actions.d.ts +5 -50
- package/dist/actions/actions.js +49 -190
- package/dist/actions/reads.d.ts +3 -2
- package/dist/actions/reads.js +12 -5
- package/dist/actions/waits/index.d.ts +1 -0
- package/dist/actions/waits/index.js +2 -0
- package/dist/actions/waits/waits.d.ts +37 -0
- package/dist/actions/waits/waits.js +107 -0
- package/dist/cli/cli.js +6 -56
- package/dist/contracts/actions/index.d.ts +2 -4
- package/dist/contracts/actions/index.js +1 -3
- package/dist/contracts/actions/types.d.ts +135 -142
- package/dist/contracts/actions/types.js +12 -22
- package/dist/contracts/browser/types.d.ts +12 -605
- package/dist/contracts/browser/types.js +2 -5
- package/dist/contracts/evidence/types.d.ts +4 -7
- package/dist/contracts/evidence/types.js +2 -8
- package/dist/contracts/index.d.ts +5 -16
- package/dist/contracts/index.js +4 -15
- package/dist/contracts/locks/index.d.ts +2 -0
- package/dist/contracts/locks/index.js +2 -0
- package/dist/contracts/locks/types.d.ts +50 -0
- package/dist/contracts/locks/types.js +36 -0
- package/dist/contracts/providers/types.d.ts +0 -38
- package/dist/contracts/providers/types.js +0 -1
- package/dist/contracts/results/types.js +1 -1
- package/dist/contracts/sessions/types.d.ts +2 -0
- package/dist/contracts/sessions/types.js +7 -1
- package/dist/contracts/skills/types.d.ts +1 -0
- package/dist/contracts/skills/types.js +5 -0
- package/dist/contracts/types.d.ts +4526 -12307
- package/dist/contracts/types.js +13 -12
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -2
- package/dist/providers/claude/adapter.js +1 -11
- package/dist/providers/claude/claude.d.ts +6 -3
- package/dist/providers/claude/claude.js +49 -9
- package/dist/providers/claude/control/control.d.ts +2 -20
- package/dist/providers/claude/control/control.js +88 -155
- package/dist/providers/claude/control/permissions.d.ts +0 -9
- package/dist/providers/claude/control/permissions.js +0 -22
- package/dist/providers/claude/control/skills.js +1 -0
- package/dist/providers/claude/control/stream.js +1 -34
- package/dist/providers/claude/control/types.d.ts +0 -3
- package/dist/providers/claude/history/history.model.d.ts +9 -0
- package/dist/providers/claude/history/history.model.js +77 -43
- package/dist/providers/claude/history/types.d.ts +284 -3045
- package/dist/providers/claude/history/types.js +1 -0
- package/dist/providers/claude/rpc.d.ts +0 -5
- package/dist/providers/claude/rpc.js +0 -3
- package/dist/providers/codex/adapter.js +2 -12
- package/dist/providers/codex/codex.d.ts +1 -2
- package/dist/providers/codex/codex.js +2 -100
- package/dist/providers/codex/types.d.ts +2 -4
- package/dist/providers/registry/registry.d.ts +0 -2
- package/dist/providers/registry/registry.js +0 -7
- package/dist/providers/types.d.ts +4 -6
- package/dist/providers/types.js +3 -2
- package/dist/runtime/runtime.js +10 -81
- package/dist/runtime/types.d.ts +1 -18
- package/dist/runtime/types.js +0 -1
- package/dist/sessions/sessions.js +0 -1
- package/dist/skills/skills.js +3 -0
- package/dist/snapshots/archive/archive.js +2 -23
- package/dist/snapshots/capture.d.ts +2 -5
- package/dist/snapshots/capture.js +4 -85
- package/dist/snapshots/constants.d.ts +0 -1
- package/dist/snapshots/constants.js +1 -6
- package/dist/snapshots/database.d.ts +2 -3
- package/dist/snapshots/database.js +9 -114
- package/dist/snapshots/fences.d.ts +3 -5
- package/dist/snapshots/fences.js +3 -15
- package/dist/snapshots/files.d.ts +3 -1
- package/dist/snapshots/files.js +15 -4
- package/dist/snapshots/snapshots.d.ts +6 -7
- package/dist/snapshots/snapshots.js +9 -16
- package/dist/snapshots/types.d.ts +5 -81
- package/dist/snapshots/types.js +7 -30
- package/dist/storage/constants.d.ts +1 -0
- package/dist/storage/constants.js +5 -1
- package/dist/storage/types.d.ts +1 -0
- package/dist/storage/types.js +1 -0
- package/dist/store/control/constants.d.ts +3 -2
- package/dist/store/control/constants.js +3 -1
- package/dist/store/control/control.model.d.ts +1 -11
- package/dist/store/control/control.model.js +10 -131
- package/dist/store/control/transformers.d.ts +6 -3
- package/dist/store/control/transformers.js +6 -5
- package/dist/store/control/types.d.ts +91 -170
- package/dist/store/control/types.js +5 -7
- package/dist/store/schema.js +1 -1
- package/dist/store/schema.sql +3 -360
- package/dist/store/sessions/sessions.model.d.ts +10 -6
- package/dist/store/sessions/sessions.model.js +19 -2
- package/dist/store/snapshot.d.ts +10 -0
- package/dist/store/snapshot.js +37 -0
- package/dist/store/store.js +1 -54
- package/dist/store/store.worker.js +5 -97
- package/dist/store/types.d.ts +241 -4802
- package/dist/store/types.js +1 -44
- package/docs/recovery.md +10 -6
- package/errors/README.md +29 -39
- package/package.json +3 -4
- package/dist/agent-tools/agent-tools.d.ts +0 -6
- package/dist/agent-tools/agent-tools.js +0 -181
- package/dist/agent-tools/constants.d.ts +0 -7
- package/dist/agent-tools/constants.js +0 -45
- package/dist/agent-tools/index.d.ts +0 -4
- package/dist/agent-tools/index.js +0 -4
- package/dist/agent-tools/mcp/index.d.ts +0 -1
- package/dist/agent-tools/mcp/index.js +0 -2
- package/dist/agent-tools/mcp/mcp.d.ts +0 -7
- package/dist/agent-tools/mcp/mcp.js +0 -50
- package/dist/agent-tools/types.d.ts +0 -64
- package/dist/agent-tools/types.js +0 -1
- package/dist/agent-tools/utilities.d.ts +0 -13
- package/dist/agent-tools/utilities.js +0 -37
- package/dist/collaboration/collaboration.d.ts +0 -7
- package/dist/collaboration/collaboration.js +0 -119
- package/dist/collaboration/constants.d.ts +0 -2
- package/dist/collaboration/constants.js +0 -3
- package/dist/collaboration/dispatch/dispatch.d.ts +0 -12
- package/dist/collaboration/dispatch/dispatch.js +0 -148
- package/dist/collaboration/dispatch/index.d.ts +0 -3
- package/dist/collaboration/dispatch/index.js +0 -4
- package/dist/collaboration/dispatch/types.d.ts +0 -632
- package/dist/collaboration/dispatch/types.js +0 -44
- package/dist/collaboration/grants/grants.d.ts +0 -45
- package/dist/collaboration/grants/grants.js +0 -131
- package/dist/collaboration/grants/index.d.ts +0 -1
- package/dist/collaboration/grants/index.js +0 -2
- package/dist/collaboration/identity/credentials.d.ts +0 -17
- package/dist/collaboration/identity/credentials.js +0 -182
- package/dist/collaboration/identity/index.d.ts +0 -4
- package/dist/collaboration/identity/index.js +0 -4
- package/dist/collaboration/identity/types.d.ts +0 -171
- package/dist/collaboration/identity/types.js +0 -87
- package/dist/collaboration/index.d.ts +0 -3
- package/dist/collaboration/index.js +0 -3
- package/dist/collaboration/types.d.ts +0 -25
- package/dist/collaboration/types.js +0 -1
- package/dist/contracts/agent-tools/index.d.ts +0 -2
- package/dist/contracts/agent-tools/index.js +0 -2
- package/dist/contracts/agent-tools/types.d.ts +0 -697
- package/dist/contracts/agent-tools/types.js +0 -125
- package/dist/contracts/collaboration/index.d.ts +0 -4
- package/dist/contracts/collaboration/index.js +0 -4
- package/dist/contracts/collaboration/reports/constants.d.ts +0 -1
- package/dist/contracts/collaboration/reports/constants.js +0 -2
- package/dist/contracts/collaboration/reports/index.d.ts +0 -3
- package/dist/contracts/collaboration/reports/index.js +0 -3
- package/dist/contracts/collaboration/reports/types.d.ts +0 -69
- package/dist/contracts/collaboration/reports/types.js +0 -53
- package/dist/contracts/collaboration/types.d.ts +0 -6734
- package/dist/contracts/collaboration/types.js +0 -696
- package/dist/contracts/plans/index.d.ts +0 -6
- package/dist/contracts/plans/index.js +0 -6
- package/dist/contracts/plans/types.d.ts +0 -1788
- package/dist/contracts/plans/types.js +0 -278
- package/dist/plans/admission.d.ts +0 -288
- package/dist/plans/admission.js +0 -393
- package/dist/plans/authority.d.ts +0 -21
- package/dist/plans/authority.js +0 -207
- package/dist/plans/documents.d.ts +0 -80
- package/dist/plans/documents.js +0 -238
- package/dist/plans/evidence.d.ts +0 -11
- package/dist/plans/evidence.js +0 -211
- package/dist/plans/files.d.ts +0 -55
- package/dist/plans/files.js +0 -264
- package/dist/plans/finalization.d.ts +0 -11
- package/dist/plans/finalization.js +0 -30
- package/dist/plans/index.d.ts +0 -5
- package/dist/plans/index.js +0 -6
- package/dist/plans/plans.d.ts +0 -325
- package/dist/plans/plans.js +0 -803
- package/dist/plans/projections.d.ts +0 -13
- package/dist/plans/projections.js +0 -67
- package/dist/plans/revisions.d.ts +0 -50
- package/dist/plans/revisions.js +0 -181
- package/dist/plans/types.d.ts +0 -114
- package/dist/plans/types.js +0 -43
- package/dist/plans/utilities.d.ts +0 -36
- package/dist/plans/utilities.js +0 -62
- package/dist/snapshots/artifacts.d.ts +0 -16
- package/dist/snapshots/artifacts.js +0 -75
- package/dist/store/collaboration/authority.d.ts +0 -228
- package/dist/store/collaboration/authority.js +0 -128
- package/dist/store/collaboration/collaboration.model.d.ts +0 -412
- package/dist/store/collaboration/collaboration.model.js +0 -254
- package/dist/store/collaboration/constants.d.ts +0 -13
- package/dist/store/collaboration/constants.js +0 -14
- package/dist/store/collaboration/dispatch.d.ts +0 -19
- package/dist/store/collaboration/dispatch.js +0 -197
- package/dist/store/collaboration/identity.d.ts +0 -21
- package/dist/store/collaboration/identity.js +0 -146
- package/dist/store/collaboration/index.d.ts +0 -3
- package/dist/store/collaboration/index.js +0 -5
- package/dist/store/collaboration/invocation.d.ts +0 -21
- package/dist/store/collaboration/invocation.js +0 -162
- package/dist/store/collaboration/messages.d.ts +0 -54
- package/dist/store/collaboration/messages.js +0 -157
- package/dist/store/collaboration/outcomes.d.ts +0 -11
- package/dist/store/collaboration/outcomes.js +0 -216
- package/dist/store/collaboration/queries.d.ts +0 -23
- package/dist/store/collaboration/queries.js +0 -259
- package/dist/store/collaboration/reports.d.ts +0 -37
- package/dist/store/collaboration/reports.js +0 -117
- package/dist/store/collaboration/requests.d.ts +0 -22
- package/dist/store/collaboration/requests.js +0 -111
- package/dist/store/collaboration/search.d.ts +0 -13
- package/dist/store/collaboration/search.js +0 -58
- package/dist/store/collaboration/spawn.d.ts +0 -33
- package/dist/store/collaboration/spawn.js +0 -96
- package/dist/store/collaboration/streams.d.ts +0 -13
- package/dist/store/collaboration/streams.js +0 -100
- package/dist/store/collaboration/tasks.d.ts +0 -20
- package/dist/store/collaboration/tasks.js +0 -169
- package/dist/store/collaboration/transformers.d.ts +0 -56
- package/dist/store/collaboration/transformers.js +0 -179
- package/dist/store/collaboration/types.d.ts +0 -25
- package/dist/store/collaboration/types.js +0 -8
- package/dist/store/collaboration/utilities.d.ts +0 -23
- package/dist/store/collaboration/utilities.js +0 -77
- package/dist/store/collaboration/waits.d.ts +0 -26
- package/dist/store/collaboration/waits.js +0 -114
- package/dist/store/plans/index.d.ts +0 -1
- package/dist/store/plans/index.js +0 -2
- package/dist/store/plans/plans.model.d.ts +0 -47
- package/dist/store/plans/plans.model.js +0 -179
|
@@ -1,31 +1,14 @@
|
|
|
1
|
-
import type { IActionEnvelope, IActionReceipt,
|
|
1
|
+
import type { IActionEnvelope, IActionReceipt, INativeApproval, INativeApprovalSummary, ILoginObservation, ISessionTerminal } from '../contracts/index.js';
|
|
2
2
|
import { type createProviderRegistry } from '../providers/registry/index.js';
|
|
3
3
|
import type { createSkills } from '../skills/index.js';
|
|
4
4
|
import type { IStore } from '../store/index.js';
|
|
5
|
-
import type { createPlans } from '../plans/index.js';
|
|
6
|
-
import type { IAgentSpawnAdmission } from '../collaboration/identity/index.js';
|
|
7
|
-
import type { IDispatchAdmission } from '../collaboration/dispatch/index.js';
|
|
8
5
|
import { LiveItems } from './live/index.js';
|
|
9
|
-
|
|
10
|
-
agentSpawn?: IAgentSpawnAdmission;
|
|
11
|
-
collaboration?: IDispatchAdmission;
|
|
12
|
-
};
|
|
6
|
+
import { ActionWaits } from './waits/index.js';
|
|
13
7
|
/**
|
|
14
8
|
* Owns admitted native work across client disconnects, with durable delivery evidence.
|
|
15
9
|
* @returns The runtime-scoped action controller. Close must precede worker shutdown.
|
|
16
10
|
*/
|
|
17
|
-
export declare const createActions: (registry: ReturnType<typeof createProviderRegistry>, store: IStore, roots: string[], epoch: string, actionKey: Uint8Array, skills: ReturnType<typeof createSkills>,
|
|
18
|
-
/** Registers a runtime-owned event-driven recovery wakeup, without awaiting it on the event lane. */
|
|
19
|
-
setChangeHandler(handler: () => void): void;
|
|
20
|
-
/** Lets ordinary native queues advance after outcome collection releases the dispatch guard. */
|
|
21
|
-
advanceQueued(thread: IManagedThread): void;
|
|
22
|
-
/**
|
|
23
|
-
* Persists already received native lifecycle evidence before a tool rechecks its session binding.
|
|
24
|
-
* @returns Completion of the current bounded event lane, without polling native execution.
|
|
25
|
-
* @throws
|
|
26
|
-
* - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
|
|
27
|
-
*/
|
|
28
|
-
flushEvents(provider: IManagedThread["provider"]): Promise<void>;
|
|
11
|
+
export declare const createActions: (registry: ReturnType<typeof createProviderRegistry>, store: IStore, roots: string[], epoch: string, actionKey: Uint8Array, skills: ReturnType<typeof createSkills>, runBackground: (operation: () => Promise<void>) => Promise<void>, invalidateNativeCatalogs: () => void, claudeTerminalOf: (nativeId: string) => ISessionTerminal | null) => {
|
|
29
12
|
/**
|
|
30
13
|
* Reads live native authentication presentation without replaying an interrupted action.
|
|
31
14
|
* @returns The exact challenge or its known terminal status; restart loses sensitive presentation.
|
|
@@ -41,12 +24,11 @@ export declare const createActions: (registry: ReturnType<typeof createProviderR
|
|
|
41
24
|
*/
|
|
42
25
|
readLogin(actionId: string): Promise<ILoginObservation>;
|
|
43
26
|
live: LiveItems;
|
|
27
|
+
waits: ActionWaits;
|
|
44
28
|
/**
|
|
45
29
|
* Returns after durable admission; the native operation outlives this client request.
|
|
46
30
|
* @returns The durable admission receipt after validation.
|
|
47
31
|
* @throws
|
|
48
|
-
* - JG_AGENT_HQ_COLLABORATION_FORBIDDEN: The HQ collaboration operation is not authorized
|
|
49
|
-
* - JG_AGENT_HQ_COLLABORATION_CONFLICT: The HQ collaboration operation conflicts with its recorded state
|
|
50
32
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
51
33
|
* - JG_AGENT_HQ_SKILL_UNAVAILABLE: The HQ skill is unavailable
|
|
52
34
|
* - JG_AGENT_HQ_REQUEST_INVALID: The HQ request is invalid
|
|
@@ -57,36 +39,10 @@ export declare const createActions: (registry: ReturnType<typeof createProviderR
|
|
|
57
39
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
58
40
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
59
41
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
60
|
-
* - JG_AGENT_HQ_LOCK_INVALID_ARGUMENTS: The HQ lock acquisition arguments are invalid
|
|
61
|
-
* - JG_AGENT_HQ_LOCK_UNSUPPORTED_PLATFORM: The HQ lock requires Linux or macOS
|
|
62
|
-
* - JG_AGENT_HQ_RUNTIME_DIRECTORY_INVALID: The HQ runtime directory must be a real directory
|
|
63
|
-
* - JG_AGENT_HQ_RUNTIME_DIRECTORY_PERMISSIONS: The HQ runtime directory must be private and owned by the current user
|
|
64
|
-
* - JG_AGENT_HQ_LOCK_FILE_INVALID: The HQ lock must be a regular file
|
|
65
|
-
* - JG_AGENT_HQ_LOCK_FILE_PERMISSIONS: The HQ lock must be private and owned by the current user
|
|
66
|
-
* - JG_AGENT_HQ_LOCK_OWNER_OVERSIZED: The HQ lock owner exceeds the supported size
|
|
67
|
-
* - JG_AGENT_HQ_LOCK_OWNER_UNREADABLE: The HQ lock owner could not be read. Inspect .runtime/hq.lock
|
|
68
|
-
* - JG_AGENT_HQ_LOCK_OWNER_INCOMPLETE: The HQ lock owner is incomplete. Inspect .runtime/hq.lock and remove it only after its owner stopped
|
|
69
|
-
* - JG_AGENT_HQ_LOCK_OWNER_INACTIVE: The HQ lock has an inactive owner
|
|
70
|
-
* - JG_AGENT_HQ_LOCK_OWNER_UNVERIFIABLE: The HQ lock owner could not be verified
|
|
71
|
-
* - JG_AGENT_HQ_LOCK_TIMEOUT: Timed out waiting for the HQ lock
|
|
72
|
-
* - JG_AGENT_HQ_LOCK_OWNERSHIP_CHANGED: HQ lock ownership changed before release
|
|
73
42
|
*/
|
|
74
|
-
submit(action: IActionEnvelope
|
|
43
|
+
submit(action: IActionEnvelope): Promise<IActionReceipt>;
|
|
75
44
|
/** Attaches sensitive presentation only to the exact current native request. */
|
|
76
45
|
approvalPresentation(approval: INativeApprovalSummary): INativeApproval;
|
|
77
|
-
/**
|
|
78
|
-
* Quiesces the selected managed cohort without stopping unrelated controllers.
|
|
79
|
-
* @returns A promise resolved only after interruption, background cleanup and release evidence.
|
|
80
|
-
* @throws
|
|
81
|
-
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
82
|
-
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
83
|
-
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
84
|
-
* - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
|
|
85
|
-
* - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
|
|
86
|
-
* - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
|
|
87
|
-
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
88
|
-
*/
|
|
89
|
-
quiescePlan(controls: IPlanRevisionWorkflow["controls"]): Promise<void>;
|
|
90
46
|
/**
|
|
91
47
|
* Stops admission, interrupts active work, cleans native terminals and confirms shutdown.
|
|
92
48
|
* @returns A promise resolved after native exit and release of durable control ownership.
|
|
@@ -100,4 +56,3 @@ export declare const createActions: (registry: ReturnType<typeof createProviderR
|
|
|
100
56
|
*/
|
|
101
57
|
close(): Promise<void>;
|
|
102
58
|
};
|
|
103
|
-
export {};
|
package/dist/actions/actions.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { createHmac, randomUUID } from 'node:crypto';
|
|
2
2
|
import { Exception, extractMessage, isException } from 'jg-exception';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { setTimeout as wait } from 'node:timers/promises';
|
|
5
4
|
import { getErrorKind } from '../errors/index.js';
|
|
6
5
|
import { retainNativeLineage, readInputFiles } from '../providers/index.js';
|
|
7
6
|
import { capabilityUnavailable } from '../providers/registry/index.js';
|
|
8
7
|
import { resolveWorkspaceTarget } from '../runtime/state/index.js';
|
|
9
8
|
import { LiveItems } from './live/index.js';
|
|
9
|
+
import { ActionWaits } from './waits/index.js';
|
|
10
|
+
// item observations never change a receipt, and are too frequent to wake waits for
|
|
11
|
+
const ITEM_OBSERVATIONS = new Set([
|
|
12
|
+
'item-started',
|
|
13
|
+
'item-completed',
|
|
14
|
+
]);
|
|
10
15
|
const NativeRejectionSchema = z.union([
|
|
11
16
|
z.object({ nativeCode: z.number() }),
|
|
12
17
|
z.object({ nativeRejection: z.literal(true) }),
|
|
@@ -15,7 +20,7 @@ const NativeRejectionSchema = z.union([
|
|
|
15
20
|
* Owns admitted native work across client disconnects, with durable delivery evidence.
|
|
16
21
|
* @returns The runtime-scoped action controller. Close must precede worker shutdown.
|
|
17
22
|
*/
|
|
18
|
-
export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
23
|
+
export const createActions = (registry, store, roots, epoch, actionKey, skills, runBackground, invalidateNativeCatalogs, claudeTerminalOf) => {
|
|
19
24
|
const prompts = new Map();
|
|
20
25
|
const controlled = new Map();
|
|
21
26
|
const key = (provider, nativeId) => JSON.stringify([provider, nativeId]);
|
|
@@ -24,8 +29,8 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
24
29
|
live.open(key(provider, nativeId));
|
|
25
30
|
};
|
|
26
31
|
const live = new LiveItems();
|
|
32
|
+
const waits = new ActionWaits((actionId) => store.getAction(actionId));
|
|
27
33
|
const tasks = new Set();
|
|
28
|
-
const taskOwners = new Map();
|
|
29
34
|
const admissions = new Set();
|
|
30
35
|
let lane = Promise.resolve();
|
|
31
36
|
const eventCounts = new Map();
|
|
@@ -35,7 +40,6 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
35
40
|
let closing = false;
|
|
36
41
|
let unavailable = false;
|
|
37
42
|
let eventFailure;
|
|
38
|
-
let onChange = () => { };
|
|
39
43
|
const conflict = () => {
|
|
40
44
|
throw new Exception('The HQ action conflicts with its recorded state', {
|
|
41
45
|
code: 'JG_AGENT_HQ_ACTION_CONFLICT',
|
|
@@ -50,6 +54,22 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
50
54
|
data: { kind: 'agent-unavailable' },
|
|
51
55
|
});
|
|
52
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Records native evidence, then wakes the receipt waits it can affect: a lost connection's on
|
|
59
|
+
* every receipt, and other evidence's on its thread's receipts.
|
|
60
|
+
* @returns The refreshed thread and whether its queue may advance.
|
|
61
|
+
* @throws
|
|
62
|
+
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
63
|
+
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
64
|
+
*/
|
|
65
|
+
const recordObservation = async (observation) => {
|
|
66
|
+
const result = await store.observe(observation);
|
|
67
|
+
if (observation.kind === 'native-unavailable')
|
|
68
|
+
waits.notifyAll();
|
|
69
|
+
else if (result.thread && !ITEM_OBSERVATIONS.has(observation.kind))
|
|
70
|
+
waits.notifyThread(result.thread.id);
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
53
73
|
/** Quarantines controls after a lifecycle gap and stops the native transport. */
|
|
54
74
|
const failEvents = (cause) => {
|
|
55
75
|
if (unavailable)
|
|
@@ -61,8 +81,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
61
81
|
lane = runBackground(async () => {
|
|
62
82
|
await previous.catch(() => undefined);
|
|
63
83
|
for (const { provider } of registry.statuses())
|
|
64
|
-
await
|
|
65
|
-
onChange();
|
|
84
|
+
await recordObservation({ kind: 'native-unavailable', provider });
|
|
66
85
|
});
|
|
67
86
|
void lane.catch((error) => {
|
|
68
87
|
eventFailure = error;
|
|
@@ -82,14 +101,13 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
82
101
|
const previous = lane;
|
|
83
102
|
lane = runBackground(async () => {
|
|
84
103
|
await previous.catch(() => undefined);
|
|
85
|
-
await
|
|
86
|
-
onChange();
|
|
104
|
+
await recordObservation({ kind: 'native-unavailable', provider });
|
|
87
105
|
});
|
|
88
106
|
void lane.catch(failEvents);
|
|
89
107
|
registry.quarantine(provider, cause);
|
|
90
108
|
};
|
|
91
109
|
/** Keeps native work owned by the runtime when a requesting client disconnects. */
|
|
92
|
-
const runOwned = (operation
|
|
110
|
+
const runOwned = (operation) => {
|
|
93
111
|
const task = (async () => {
|
|
94
112
|
try {
|
|
95
113
|
await runBackground(operation);
|
|
@@ -99,12 +117,9 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
99
117
|
}
|
|
100
118
|
})();
|
|
101
119
|
tasks.add(task);
|
|
102
|
-
if (threadId)
|
|
103
|
-
taskOwners.set(task, threadId);
|
|
104
120
|
void task
|
|
105
121
|
.finally(() => {
|
|
106
122
|
tasks.delete(task);
|
|
107
|
-
taskOwners.delete(task);
|
|
108
123
|
})
|
|
109
124
|
.catch(failEvents);
|
|
110
125
|
};
|
|
@@ -115,7 +130,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
115
130
|
await operation();
|
|
116
131
|
}
|
|
117
132
|
catch {
|
|
118
|
-
await
|
|
133
|
+
await recordObservation({
|
|
119
134
|
kind: 'native-unavailable',
|
|
120
135
|
provider,
|
|
121
136
|
...(nativeId ? { nativeThreadId: nativeId } : {}),
|
|
@@ -204,7 +219,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
204
219
|
if (closing || unavailable || blockedProviders.has(provider))
|
|
205
220
|
return;
|
|
206
221
|
runOwned(async () => {
|
|
207
|
-
const next = await
|
|
222
|
+
const next = await store.claimQueued(threadId);
|
|
208
223
|
if (next)
|
|
209
224
|
await dispatch(next.receipt, next.thread, {
|
|
210
225
|
kind: 'message',
|
|
@@ -212,11 +227,11 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
212
227
|
input: { kind: 'text', text: next.input.text },
|
|
213
228
|
settings: next.input.settings,
|
|
214
229
|
}, next.input);
|
|
215
|
-
}
|
|
230
|
+
});
|
|
216
231
|
};
|
|
217
232
|
const apply = async (outcome) => {
|
|
218
233
|
const receipt = await store.applyOutcome(outcome);
|
|
219
|
-
|
|
234
|
+
waits.notifyAction(outcome.actionId);
|
|
220
235
|
if (!receipt?.threadId)
|
|
221
236
|
return receipt;
|
|
222
237
|
const thread = await store.getThread(receipt.threadId);
|
|
@@ -257,7 +272,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
257
272
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
258
273
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
259
274
|
*/
|
|
260
|
-
const dispatch = async (initial, originalThread, command, input
|
|
275
|
+
const dispatch = async (initial, originalThread, command, input) => {
|
|
261
276
|
let receipt = initial;
|
|
262
277
|
let thread = originalThread;
|
|
263
278
|
let hasDispatched = false;
|
|
@@ -295,14 +310,6 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
295
310
|
: null;
|
|
296
311
|
if (requestId.endsWith(':fork') && !source?.nativeId)
|
|
297
312
|
conflict();
|
|
298
|
-
if (collaboration) {
|
|
299
|
-
await plans.validateDispatch(collaboration.taskId, collaboration.requestId, receipt.id);
|
|
300
|
-
const job = await store.dispatchJob(collaboration.taskId, collaboration.requestId);
|
|
301
|
-
if (job.request.currentActionId !== receipt.id ||
|
|
302
|
-
job.request.state !== 'claimed' ||
|
|
303
|
-
job.blockedReason !== null)
|
|
304
|
-
conflict();
|
|
305
|
-
}
|
|
306
313
|
hasDispatched = true;
|
|
307
314
|
if (requestId.endsWith(':control')) {
|
|
308
315
|
if (!nativeId ||
|
|
@@ -438,8 +445,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
438
445
|
}
|
|
439
446
|
};
|
|
440
447
|
const observe = async (observation) => {
|
|
441
|
-
const result = await
|
|
442
|
-
onChange();
|
|
448
|
+
const result = await recordObservation(observation);
|
|
443
449
|
if (observation.kind === 'turn-completed') {
|
|
444
450
|
for (const [id, prompt] of prompts)
|
|
445
451
|
if (prompt.native.provider === observation.provider &&
|
|
@@ -489,10 +495,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
489
495
|
// a session this runtime controls reports its transitions through its own thread state
|
|
490
496
|
if (controlled.has(key(provider, nativeId)))
|
|
491
497
|
return;
|
|
492
|
-
enqueue(provider,
|
|
493
|
-
await store.observeSessions(provider, [{ nativeId, state }], false);
|
|
494
|
-
onChange();
|
|
495
|
-
});
|
|
498
|
+
enqueue(provider, () => store.observeSessions(provider, [{ nativeId, state }], false));
|
|
496
499
|
},
|
|
497
500
|
delta(provider, nativeId, turnId, itemId, text) {
|
|
498
501
|
if (controlled.has(key(provider, nativeId)))
|
|
@@ -524,7 +527,6 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
524
527
|
native: prompt,
|
|
525
528
|
threadId: recorded.thread.id,
|
|
526
529
|
});
|
|
527
|
-
onChange();
|
|
528
530
|
});
|
|
529
531
|
},
|
|
530
532
|
outcome(provider, outcome, nativeThread) {
|
|
@@ -576,7 +578,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
576
578
|
if (closing || blockedProviders.has(provider))
|
|
577
579
|
return;
|
|
578
580
|
enqueue(provider, async () => {
|
|
579
|
-
await
|
|
581
|
+
await recordObservation({
|
|
580
582
|
kind: 'native-unavailable',
|
|
581
583
|
provider,
|
|
582
584
|
...(nativeId ? { nativeThreadId: nativeId } : {}),
|
|
@@ -584,7 +586,6 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
584
586
|
// only sessions observed through the lost connection lose their known state
|
|
585
587
|
if (!nativeId && observingProviders.has(provider))
|
|
586
588
|
await store.markSessionsUnknown(provider);
|
|
587
|
-
onChange();
|
|
588
589
|
for (const [id, prompt] of prompts)
|
|
589
590
|
if (prompt.native.provider === provider &&
|
|
590
591
|
(!nativeId || prompt.native.nativeThreadId === nativeId))
|
|
@@ -597,8 +598,6 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
597
598
|
* Validates the current target and separates new dispatch from idempotent receipt reads.
|
|
598
599
|
* @returns The durable admission receipt; native work runs independently.
|
|
599
600
|
* @throws
|
|
600
|
-
* - JG_AGENT_HQ_COLLABORATION_FORBIDDEN: The HQ collaboration operation is not authorized
|
|
601
|
-
* - JG_AGENT_HQ_COLLABORATION_CONFLICT: The HQ collaboration operation conflicts with its recorded state
|
|
602
601
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
603
602
|
* - JG_AGENT_HQ_SKILL_UNAVAILABLE: The HQ skill is unavailable
|
|
604
603
|
* - JG_AGENT_HQ_REQUEST_INVALID: The HQ request is invalid
|
|
@@ -609,21 +608,8 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
609
608
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
610
609
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
611
610
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
612
|
-
* - JG_AGENT_HQ_LOCK_INVALID_ARGUMENTS: The HQ lock acquisition arguments are invalid
|
|
613
|
-
* - JG_AGENT_HQ_LOCK_UNSUPPORTED_PLATFORM: The HQ lock requires Linux or macOS
|
|
614
|
-
* - JG_AGENT_HQ_RUNTIME_DIRECTORY_INVALID: The HQ runtime directory must be a real directory
|
|
615
|
-
* - JG_AGENT_HQ_RUNTIME_DIRECTORY_PERMISSIONS: The HQ runtime directory must be private and owned by the current user
|
|
616
|
-
* - JG_AGENT_HQ_LOCK_FILE_INVALID: The HQ lock must be a regular file
|
|
617
|
-
* - JG_AGENT_HQ_LOCK_FILE_PERMISSIONS: The HQ lock must be private and owned by the current user
|
|
618
|
-
* - JG_AGENT_HQ_LOCK_OWNER_OVERSIZED: The HQ lock owner exceeds the supported size
|
|
619
|
-
* - JG_AGENT_HQ_LOCK_OWNER_UNREADABLE: The HQ lock owner could not be read. Inspect .runtime/hq.lock
|
|
620
|
-
* - JG_AGENT_HQ_LOCK_OWNER_INCOMPLETE: The HQ lock owner is incomplete. Inspect .runtime/hq.lock and remove it only after its owner stopped
|
|
621
|
-
* - JG_AGENT_HQ_LOCK_OWNER_INACTIVE: The HQ lock has an inactive owner
|
|
622
|
-
* - JG_AGENT_HQ_LOCK_OWNER_UNVERIFIABLE: The HQ lock owner could not be verified
|
|
623
|
-
* - JG_AGENT_HQ_LOCK_TIMEOUT: Timed out waiting for the HQ lock
|
|
624
|
-
* - JG_AGENT_HQ_LOCK_OWNERSHIP_CHANGED: HQ lock ownership changed before release
|
|
625
611
|
*/
|
|
626
|
-
const admitAndDispatch = async (action
|
|
612
|
+
const admitAndDispatch = async (action) => {
|
|
627
613
|
// The worker verifies the complete digest before returning any existing receipt.
|
|
628
614
|
const existing = await store.getAction(action.id);
|
|
629
615
|
if (existing) {
|
|
@@ -632,13 +618,13 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
632
618
|
if (thread)
|
|
633
619
|
await validateRoot(thread);
|
|
634
620
|
}
|
|
635
|
-
return (await store.admit({ action, prepared:
|
|
621
|
+
return (await store.admit({ action, prepared: {} })).receipt;
|
|
636
622
|
}
|
|
637
623
|
if (closing || unavailable || tasks.size >= 64)
|
|
638
624
|
agentUnavailable();
|
|
639
625
|
const command = action.command;
|
|
640
626
|
let provider = 'provider' in command ? command.provider : undefined;
|
|
641
|
-
const prepared = {
|
|
627
|
+
const prepared = {};
|
|
642
628
|
let input;
|
|
643
629
|
if ('threadId' in command) {
|
|
644
630
|
const target = await store.getThread(command.threadId);
|
|
@@ -656,7 +642,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
656
642
|
}
|
|
657
643
|
}
|
|
658
644
|
if (!provider)
|
|
659
|
-
return (await
|
|
645
|
+
return (await store.admit({ action, prepared })).receipt;
|
|
660
646
|
const control = await registry.get(provider);
|
|
661
647
|
if (!control.isAvailable)
|
|
662
648
|
agentUnavailable();
|
|
@@ -671,7 +657,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
671
657
|
: 'accountLogout';
|
|
672
658
|
if (capabilities.operations[operation].state !== 'supported')
|
|
673
659
|
capabilityUnavailable();
|
|
674
|
-
const admitted = await
|
|
660
|
+
const admitted = await store.admit({ action, prepared });
|
|
675
661
|
if (admitted.isNew && admitted.dispatchActionId) {
|
|
676
662
|
runOwned(async () => {
|
|
677
663
|
let hasDispatched = false;
|
|
@@ -827,31 +813,18 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
827
813
|
if (thread.provider === 'claude' && claudeTerminalOf(thread.nativeId))
|
|
828
814
|
conflict();
|
|
829
815
|
const files = await readInputFiles(command.input.files ?? [], thread.workspaceRoot, roots);
|
|
830
|
-
let selection = command.input;
|
|
831
|
-
if (scopes.collaboration) {
|
|
832
|
-
// HQ's agent tools never join a Codex session it adopted, since the terminal's session holds it
|
|
833
|
-
if (thread.provider === 'codex' && (await store.isAdoptedThread(thread.id)))
|
|
834
|
-
capabilityUnavailable();
|
|
835
|
-
const job = await store.dispatchJob(scopes.collaboration.taskId, scopes.collaboration.requestId);
|
|
836
|
-
if (command.kind !== 'message' ||
|
|
837
|
-
command.input.kind !== 'text' ||
|
|
838
|
-
command.input.text !== job.packet ||
|
|
839
|
-
command.threadId !== job.thread?.id ||
|
|
840
|
-
action.id !== job.request.pendingActionId)
|
|
841
|
-
conflict();
|
|
842
|
-
const skill = job.request.specification.skill;
|
|
843
|
-
if (skill)
|
|
844
|
-
selection = { kind: 'skill-name', name: skill.name, arguments: job.packet };
|
|
845
|
-
}
|
|
846
816
|
input = {
|
|
847
|
-
...(await skills.prepare(command.threadId,
|
|
817
|
+
...(await skills.prepare(command.threadId, command.input)),
|
|
848
818
|
files: files.map(({ content: _content, ...reference }) => reference),
|
|
849
819
|
settings: command.settings ?? {},
|
|
850
820
|
};
|
|
851
821
|
await control.validateInput(thread.nativeId, input);
|
|
852
822
|
prepared.input = input;
|
|
853
823
|
}
|
|
854
|
-
const admitted = await
|
|
824
|
+
const admitted = await store.admit({ action, prepared });
|
|
825
|
+
// sending or canceling a queued entry changes that entry's own receipt
|
|
826
|
+
if (admitted.isNew && 'queuedActionId' in command)
|
|
827
|
+
waits.notifyAction(command.queuedActionId);
|
|
855
828
|
if (admitted.isNew && admitted.dispatchActionId && admitted.thread) {
|
|
856
829
|
const receipt = admitted.dispatchActionId === admitted.receipt.id
|
|
857
830
|
? admitted.receipt
|
|
@@ -870,88 +843,11 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
870
843
|
};
|
|
871
844
|
input = receipt.queuedInput;
|
|
872
845
|
}
|
|
873
|
-
runOwned(() => dispatch(receipt, admitted.thread, dispatchedCommand, input
|
|
846
|
+
runOwned(() => dispatch(receipt, admitted.thread, dispatchedCommand, input));
|
|
874
847
|
}
|
|
875
848
|
return admitted.receipt;
|
|
876
849
|
};
|
|
877
|
-
/** Waits for actual native lifecycle evidence, never an interrupt acknowledgement. */
|
|
878
|
-
const waitForThread = async (id, predicate) => {
|
|
879
|
-
const deadline = Date.now() + 30_000;
|
|
880
|
-
while (true) {
|
|
881
|
-
const thread = await store.getThread(id);
|
|
882
|
-
if (!thread)
|
|
883
|
-
conflict();
|
|
884
|
-
if (predicate(thread))
|
|
885
|
-
return thread;
|
|
886
|
-
if (thread.ownership === 'uncertain' ||
|
|
887
|
-
thread.state === 'unknown' ||
|
|
888
|
-
Date.now() >= deadline)
|
|
889
|
-
conflict();
|
|
890
|
-
await wait(250);
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
/** Stops only one phase-bound controller and confirms its native background cleanup. */
|
|
894
|
-
const quiesceThread = async (control) => {
|
|
895
|
-
await Promise.allSettled([...admissions]);
|
|
896
|
-
await Promise.allSettled([...tasks].filter((task) => taskOwners.get(task) === control.threadId));
|
|
897
|
-
await lane;
|
|
898
|
-
let thread = await store.getThread(control.threadId);
|
|
899
|
-
if (!thread)
|
|
900
|
-
conflict();
|
|
901
|
-
await validateRoot(thread);
|
|
902
|
-
if (thread.ownership === 'managed' &&
|
|
903
|
-
thread.state === 'inactive' &&
|
|
904
|
-
thread.runtimeEpoch === null)
|
|
905
|
-
return;
|
|
906
|
-
if (thread.ownership !== 'managed' ||
|
|
907
|
-
thread.runtimeEpoch !== epoch ||
|
|
908
|
-
!thread.nativeId ||
|
|
909
|
-
!controlled.has(key(thread.provider, thread.nativeId)))
|
|
910
|
-
conflict();
|
|
911
|
-
if (thread.activeTurnId) {
|
|
912
|
-
const prior = await store.getAction(control.interruptActionId);
|
|
913
|
-
const expectedTurnId = prior?.nativeTurnId ?? thread.activeTurnId;
|
|
914
|
-
const receipt = await admitAndDispatch({
|
|
915
|
-
id: control.interruptActionId,
|
|
916
|
-
runtimeEpoch: epoch,
|
|
917
|
-
command: { kind: 'interrupt', threadId: control.threadId, expectedTurnId },
|
|
918
|
-
});
|
|
919
|
-
if (receipt.delivery === 'failed')
|
|
920
|
-
conflict();
|
|
921
|
-
thread = await waitForThread(control.threadId, (current) => current.activeTurnId === null &&
|
|
922
|
-
!['starting', 'running', 'waiting-input', 'waiting-approval', 'stopping'].includes(current.state));
|
|
923
|
-
}
|
|
924
|
-
const receipt = await admitAndDispatch({
|
|
925
|
-
id: control.closeActionId,
|
|
926
|
-
runtimeEpoch: epoch,
|
|
927
|
-
command: { kind: 'thread-close', threadId: control.threadId },
|
|
928
|
-
});
|
|
929
|
-
if (receipt.delivery === 'failed')
|
|
930
|
-
conflict();
|
|
931
|
-
await waitForThread(control.threadId, (current) => current.state === 'inactive' &&
|
|
932
|
-
current.runtimeEpoch === null &&
|
|
933
|
-
current.ownership === 'managed');
|
|
934
|
-
};
|
|
935
850
|
return {
|
|
936
|
-
/** Registers a runtime-owned event-driven recovery wakeup, without awaiting it on the event lane. */
|
|
937
|
-
setChangeHandler(handler) {
|
|
938
|
-
onChange = handler;
|
|
939
|
-
},
|
|
940
|
-
/** Lets ordinary native queues advance after outcome collection releases the dispatch guard. */
|
|
941
|
-
advanceQueued(thread) {
|
|
942
|
-
advanceQueue(thread.id, thread.provider);
|
|
943
|
-
},
|
|
944
|
-
/**
|
|
945
|
-
* Persists already received native lifecycle evidence before a tool rechecks its session binding.
|
|
946
|
-
* @returns Completion of the current bounded event lane, without polling native execution.
|
|
947
|
-
* @throws
|
|
948
|
-
* - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
|
|
949
|
-
*/
|
|
950
|
-
async flushEvents(provider) {
|
|
951
|
-
await lane.catch(() => undefined);
|
|
952
|
-
if (unavailable || closing || blockedProviders.has(provider))
|
|
953
|
-
agentUnavailable();
|
|
954
|
-
},
|
|
955
851
|
/**
|
|
956
852
|
* Reads live native authentication presentation without replaying an interrupted action.
|
|
957
853
|
* @returns The exact challenge or its known terminal status; restart loses sensitive presentation.
|
|
@@ -999,12 +895,11 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
999
895
|
return (await registry.get(receipt.provider)).readLogin(receipt.nativeRequestId);
|
|
1000
896
|
},
|
|
1001
897
|
live,
|
|
898
|
+
waits,
|
|
1002
899
|
/**
|
|
1003
900
|
* Returns after durable admission; the native operation outlives this client request.
|
|
1004
901
|
* @returns The durable admission receipt after validation.
|
|
1005
902
|
* @throws
|
|
1006
|
-
* - JG_AGENT_HQ_COLLABORATION_FORBIDDEN: The HQ collaboration operation is not authorized
|
|
1007
|
-
* - JG_AGENT_HQ_COLLABORATION_CONFLICT: The HQ collaboration operation conflicts with its recorded state
|
|
1008
903
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
1009
904
|
* - JG_AGENT_HQ_SKILL_UNAVAILABLE: The HQ skill is unavailable
|
|
1010
905
|
* - JG_AGENT_HQ_REQUEST_INVALID: The HQ request is invalid
|
|
@@ -1015,22 +910,9 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
1015
910
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
1016
911
|
* - JG_AGENT_HQ_CLAUDE_HISTORY_UNAVAILABLE: The Claude history is unavailable
|
|
1017
912
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
1018
|
-
* - JG_AGENT_HQ_LOCK_INVALID_ARGUMENTS: The HQ lock acquisition arguments are invalid
|
|
1019
|
-
* - JG_AGENT_HQ_LOCK_UNSUPPORTED_PLATFORM: The HQ lock requires Linux or macOS
|
|
1020
|
-
* - JG_AGENT_HQ_RUNTIME_DIRECTORY_INVALID: The HQ runtime directory must be a real directory
|
|
1021
|
-
* - JG_AGENT_HQ_RUNTIME_DIRECTORY_PERMISSIONS: The HQ runtime directory must be private and owned by the current user
|
|
1022
|
-
* - JG_AGENT_HQ_LOCK_FILE_INVALID: The HQ lock must be a regular file
|
|
1023
|
-
* - JG_AGENT_HQ_LOCK_FILE_PERMISSIONS: The HQ lock must be private and owned by the current user
|
|
1024
|
-
* - JG_AGENT_HQ_LOCK_OWNER_OVERSIZED: The HQ lock owner exceeds the supported size
|
|
1025
|
-
* - JG_AGENT_HQ_LOCK_OWNER_UNREADABLE: The HQ lock owner could not be read. Inspect .runtime/hq.lock
|
|
1026
|
-
* - JG_AGENT_HQ_LOCK_OWNER_INCOMPLETE: The HQ lock owner is incomplete. Inspect .runtime/hq.lock and remove it only after its owner stopped
|
|
1027
|
-
* - JG_AGENT_HQ_LOCK_OWNER_INACTIVE: The HQ lock has an inactive owner
|
|
1028
|
-
* - JG_AGENT_HQ_LOCK_OWNER_UNVERIFIABLE: The HQ lock owner could not be verified
|
|
1029
|
-
* - JG_AGENT_HQ_LOCK_TIMEOUT: Timed out waiting for the HQ lock
|
|
1030
|
-
* - JG_AGENT_HQ_LOCK_OWNERSHIP_CHANGED: HQ lock ownership changed before release
|
|
1031
913
|
*/
|
|
1032
|
-
async submit(action
|
|
1033
|
-
const admission = admitAndDispatch(action
|
|
914
|
+
async submit(action) {
|
|
915
|
+
const admission = admitAndDispatch(action);
|
|
1034
916
|
admissions.add(admission);
|
|
1035
917
|
try {
|
|
1036
918
|
return await admission;
|
|
@@ -1051,29 +933,6 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
1051
933
|
presentation: current ? structuredClone(prompt.native.presentation) : null,
|
|
1052
934
|
};
|
|
1053
935
|
},
|
|
1054
|
-
/**
|
|
1055
|
-
* Quiesces the selected managed cohort without stopping unrelated controllers.
|
|
1056
|
-
* @returns A promise resolved only after interruption, background cleanup and release evidence.
|
|
1057
|
-
* @throws
|
|
1058
|
-
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
1059
|
-
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
1060
|
-
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
1061
|
-
* - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
|
|
1062
|
-
* - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
|
|
1063
|
-
* - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
|
|
1064
|
-
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
1065
|
-
*/
|
|
1066
|
-
async quiescePlan(controls) {
|
|
1067
|
-
const failures = [];
|
|
1068
|
-
for (let index = 0; index < controls.length; index += 4) {
|
|
1069
|
-
const results = await Promise.allSettled(controls.slice(index, index + 4).map(quiesceThread));
|
|
1070
|
-
for (const result of results)
|
|
1071
|
-
if (result.status === 'rejected')
|
|
1072
|
-
failures.push(result.reason);
|
|
1073
|
-
}
|
|
1074
|
-
if (failures.length)
|
|
1075
|
-
throw failures[0];
|
|
1076
|
-
},
|
|
1077
936
|
/**
|
|
1078
937
|
* Stops admission, interrupts active work, cleans native terminals and confirms shutdown.
|
|
1079
938
|
* @returns A promise resolved after native exit and release of durable control ownership.
|
package/dist/actions/reads.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ import type { IHqRequest, IHqResponse } from '../contracts/index.js';
|
|
|
2
2
|
import type { IStore } from '../store/index.js';
|
|
3
3
|
import type { createActions } from './actions.js';
|
|
4
4
|
type IControlRead = Extract<IHqRequest, {
|
|
5
|
-
kind: '
|
|
5
|
+
kind: 'receipt' | 'action-wait' | 'managed-threads' | 'managed-thread' | 'managed-thread-name' | 'actions' | 'provider-actions' | 'login' | 'events' | 'approvals' | 'live-items';
|
|
6
6
|
}>;
|
|
7
7
|
/**
|
|
8
8
|
* Authorizes bounded control reads and binds seek positions to their exact query.
|
|
9
|
-
* @returns The selected record or bounded page.
|
|
9
|
+
* @returns The selected record or bounded page, or a receipt once its wait ends.
|
|
10
10
|
* @throws
|
|
11
11
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
12
12
|
* - JG_AGENT_HQ_CURSOR_INVALID: The HQ cursor does not match this request
|
|
13
13
|
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
14
|
+
* - JG_AGENT_HQ_RUNTIME_NOT_RUNNING: The HQ runtime is not running
|
|
14
15
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
15
16
|
* - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
|
|
16
17
|
* - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
|
package/dist/actions/reads.js
CHANGED
|
@@ -30,11 +30,12 @@ const nextPageCursor = (page, filters) => {
|
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Authorizes bounded control reads and binds seek positions to their exact query.
|
|
33
|
-
* @returns The selected record or bounded page.
|
|
33
|
+
* @returns The selected record or bounded page, or a receipt once its wait ends.
|
|
34
34
|
* @throws
|
|
35
35
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
36
36
|
* - JG_AGENT_HQ_CURSOR_INVALID: The HQ cursor does not match this request
|
|
37
37
|
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
38
|
+
* - JG_AGENT_HQ_RUNTIME_NOT_RUNNING: The HQ runtime is not running
|
|
38
39
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
39
40
|
* - JG_AGENT_HQ_PROVIDER_FAILED: The HQ provider integration failed
|
|
40
41
|
* - JG_AGENT_HQ_CODEX_FAILED: The Codex integration failed
|
|
@@ -60,11 +61,19 @@ export const readControl = async (command, store, actions, roots) => {
|
|
|
60
61
|
result: { data: page.data, nextCursor: nextPageCursor(page, filters) },
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
|
-
if (command.kind === 'receipt') {
|
|
64
|
+
if (command.kind === 'receipt' || command.kind === 'action-wait') {
|
|
64
65
|
const receipt = await store.getAction(command.actionId);
|
|
65
66
|
if (receipt?.threadId)
|
|
66
67
|
await authorize(await store.getThread(receipt.threadId));
|
|
67
|
-
|
|
68
|
+
if (command.kind === 'receipt')
|
|
69
|
+
return { kind: 'receipt', result: receipt };
|
|
70
|
+
// an unknown action has nothing to wait for
|
|
71
|
+
if (!receipt)
|
|
72
|
+
return { kind: 'action-wait', result: { receipt: null, isTimedOut: false } };
|
|
73
|
+
return {
|
|
74
|
+
kind: 'action-wait',
|
|
75
|
+
result: await actions.waits.wait(command.actionId, command.until, command.timeoutMs),
|
|
76
|
+
};
|
|
68
77
|
}
|
|
69
78
|
if (command.kind === 'managed-threads') {
|
|
70
79
|
const { cursor, ...filters } = command;
|
|
@@ -97,8 +106,6 @@ export const readControl = async (command, store, actions, roots) => {
|
|
|
97
106
|
}
|
|
98
107
|
const thread = await store.getThread(command.threadId);
|
|
99
108
|
await authorize(thread);
|
|
100
|
-
if (command.kind === 'thread-plan')
|
|
101
|
-
return { kind: 'thread-plan', result: thread ? await store.getThreadPlan(thread.id) : null };
|
|
102
109
|
if (command.kind === 'managed-thread')
|
|
103
110
|
return { kind: command.kind, result: thread };
|
|
104
111
|
if (!thread)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ActionWaits } from './waits.js';
|