jg-agent-hq 3.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +13 -13
  3. package/api/README.md +91 -102
  4. package/dist/actions/actions.js +15 -0
  5. package/dist/cli/cli.js +26 -35
  6. package/dist/cli/utilities.d.ts +1 -1
  7. package/dist/cli/utilities.js +8 -25
  8. package/dist/collaboration/dispatch/types.d.ts +2 -2
  9. package/dist/contracts/actions/types.d.ts +4 -4
  10. package/dist/contracts/browser/index.d.ts +1 -3
  11. package/dist/contracts/browser/index.js +1 -3
  12. package/dist/contracts/browser/types.d.ts +15 -1447
  13. package/dist/contracts/browser/types.js +3 -112
  14. package/dist/contracts/index.d.ts +7 -9
  15. package/dist/contracts/index.js +5 -7
  16. package/dist/contracts/plans/index.d.ts +4 -6
  17. package/dist/contracts/plans/index.js +2 -4
  18. package/dist/contracts/plans/types.d.ts +38 -905
  19. package/dist/contracts/plans/types.js +13 -139
  20. package/dist/contracts/sessions/index.d.ts +2 -0
  21. package/dist/contracts/sessions/index.js +2 -0
  22. package/dist/contracts/sessions/types.d.ts +101 -0
  23. package/dist/contracts/sessions/types.js +43 -0
  24. package/dist/contracts/types.d.ts +461 -1047
  25. package/dist/contracts/types.js +8 -0
  26. package/dist/index.d.ts +2 -4
  27. package/dist/index.js +1 -3
  28. package/dist/plans/admission.d.ts +6 -6
  29. package/dist/plans/admission.js +1 -1
  30. package/dist/plans/authority.js +15 -13
  31. package/dist/plans/documents.d.ts +3 -17
  32. package/dist/plans/documents.js +6 -62
  33. package/dist/plans/files.d.ts +2 -2
  34. package/dist/plans/files.js +2 -4
  35. package/dist/plans/finalization.d.ts +6 -8
  36. package/dist/plans/finalization.js +25 -26
  37. package/dist/plans/index.d.ts +2 -3
  38. package/dist/plans/index.js +1 -2
  39. package/dist/plans/plans.d.ts +8 -8
  40. package/dist/plans/plans.js +33 -82
  41. package/dist/plans/projections.d.ts +2 -2
  42. package/dist/plans/projections.js +44 -82
  43. package/dist/plans/revisions.d.ts +4 -5
  44. package/dist/plans/revisions.js +5 -44
  45. package/dist/plans/types.d.ts +0 -281
  46. package/dist/plans/types.js +2 -30
  47. package/dist/plans/utilities.js +2 -11
  48. package/dist/providers/claude/agents/agents.d.ts +16 -0
  49. package/dist/providers/claude/agents/agents.js +80 -0
  50. package/dist/providers/claude/agents/constants.d.ts +3 -0
  51. package/dist/providers/claude/agents/constants.js +4 -0
  52. package/dist/providers/claude/agents/index.d.ts +1 -0
  53. package/dist/providers/claude/agents/index.js +2 -0
  54. package/dist/providers/claude/agents/types.d.ts +14 -0
  55. package/dist/providers/claude/agents/types.js +9 -0
  56. package/dist/providers/claude/history/history.model.js +2 -0
  57. package/dist/providers/claude/history/types.d.ts +92 -368
  58. package/dist/providers/claude/index.d.ts +1 -0
  59. package/dist/providers/claude/index.js +2 -0
  60. package/dist/providers/codex/adapter.d.ts +1 -1
  61. package/dist/providers/codex/adapter.js +26 -3
  62. package/dist/providers/codex/codex.js +47 -18
  63. package/dist/providers/codex/events.d.ts +2 -1
  64. package/dist/providers/codex/events.js +8 -3
  65. package/dist/providers/codex/index.d.ts +1 -1
  66. package/dist/providers/codex/index.js +1 -1
  67. package/dist/providers/codex/rpc.d.ts +9 -4
  68. package/dist/providers/codex/rpc.js +109 -47
  69. package/dist/providers/codex/skill-roots/constants.d.ts +4 -0
  70. package/dist/providers/codex/skill-roots/constants.js +7 -0
  71. package/dist/providers/codex/skill-roots/index.d.ts +2 -0
  72. package/dist/providers/codex/skill-roots/index.js +4 -0
  73. package/dist/providers/codex/skill-roots/skill-roots.d.ts +35 -0
  74. package/dist/providers/codex/skill-roots/skill-roots.js +93 -0
  75. package/dist/providers/codex/transformers.d.ts +3 -1
  76. package/dist/providers/codex/transformers.js +12 -1
  77. package/dist/providers/codex/types.d.ts +4 -0
  78. package/dist/providers/codex/types.js +4 -1
  79. package/dist/providers/codex/websocket/constants.d.ts +11 -0
  80. package/dist/providers/codex/websocket/constants.js +18 -0
  81. package/dist/providers/codex/websocket/index.d.ts +1 -0
  82. package/dist/providers/codex/websocket/index.js +2 -0
  83. package/dist/providers/codex/websocket/websocket.d.ts +7 -0
  84. package/dist/providers/codex/websocket/websocket.js +219 -0
  85. package/dist/providers/index.d.ts +2 -2
  86. package/dist/providers/index.js +1 -1
  87. package/dist/providers/process.d.ts +2 -2
  88. package/dist/providers/process.js +37 -4
  89. package/dist/providers/registry/registry.js +2 -1
  90. package/dist/providers/types.d.ts +25 -2
  91. package/dist/runtime/runtime.d.ts +0 -2
  92. package/dist/runtime/runtime.js +11 -5
  93. package/dist/runtime/state/state.d.ts +1 -1
  94. package/dist/runtime/state/state.js +2 -2
  95. package/dist/runtime/types.d.ts +0 -2
  96. package/dist/runtime/types.js +0 -3
  97. package/dist/sessions/sessions.js +2 -0
  98. package/dist/snapshots/archive/archive.d.ts +29 -0
  99. package/dist/snapshots/archive/archive.js +342 -0
  100. package/dist/snapshots/archive/constants.d.ts +5 -0
  101. package/dist/snapshots/archive/constants.js +8 -0
  102. package/dist/snapshots/archive/index.d.ts +1 -0
  103. package/dist/snapshots/archive/index.js +2 -0
  104. package/dist/snapshots/artifacts.d.ts +10 -1
  105. package/dist/snapshots/artifacts.js +38 -13
  106. package/dist/snapshots/capture.d.ts +3 -2
  107. package/dist/snapshots/capture.js +29 -13
  108. package/dist/snapshots/database.d.ts +2 -2
  109. package/dist/snapshots/database.js +30 -14
  110. package/dist/snapshots/fences.d.ts +4 -9
  111. package/dist/snapshots/fences.js +9 -22
  112. package/dist/snapshots/index.d.ts +1 -2
  113. package/dist/snapshots/index.js +2 -3
  114. package/dist/snapshots/snapshots.d.ts +6 -5
  115. package/dist/snapshots/snapshots.js +13 -13
  116. package/dist/snapshots/snapshots.worker.js +1 -1
  117. package/dist/snapshots/types.d.ts +26 -5
  118. package/dist/snapshots/types.js +15 -4
  119. package/dist/storage/schema/constants.d.ts +2 -2
  120. package/dist/storage/schema/constants.js +9 -3
  121. package/dist/storage/schema/index.d.ts +2 -3
  122. package/dist/storage/schema/index.js +4 -3
  123. package/dist/storage/schema/schema.d.ts +10 -8
  124. package/dist/storage/schema/schema.js +22 -36
  125. package/dist/storage/schema/types.d.ts +1 -11
  126. package/dist/storage/schema/types.js +2 -2
  127. package/dist/storage/storage.d.ts +1 -1
  128. package/dist/storage/storage.js +2 -2
  129. package/dist/store/collaboration/collaboration.model.d.ts +2 -2
  130. package/dist/store/control/types.d.ts +16 -16
  131. package/dist/store/plans/plans.model.d.ts +3 -105
  132. package/dist/store/plans/plans.model.js +6 -46
  133. package/dist/store/schema.d.ts +0 -2
  134. package/dist/store/schema.js +6 -25
  135. package/dist/store/schema.sql +90 -16
  136. package/dist/store/sessions/index.d.ts +1 -0
  137. package/dist/store/sessions/index.js +2 -0
  138. package/dist/store/sessions/sessions.model.d.ts +28 -0
  139. package/dist/store/sessions/sessions.model.js +105 -0
  140. package/dist/store/store.d.ts +0 -2
  141. package/dist/store/store.js +13 -9
  142. package/dist/store/store.worker.js +16 -11
  143. package/dist/store/types.d.ts +134 -513
  144. package/dist/store/types.js +21 -7
  145. package/docs/recovery.md +6 -16
  146. package/errors/README.md +30 -36
  147. package/package.json +1 -1
  148. package/dist/plans/reconciliation.d.ts +0 -34
  149. package/dist/plans/reconciliation.js +0 -246
  150. package/dist/storage/schema/v1-to-v2.sql +0 -1
  151. package/dist/storage/schema/v1.sql +0 -538
  152. package/dist/storage/upgrade/index.d.ts +0 -2
  153. package/dist/storage/upgrade/index.js +0 -2
  154. package/dist/storage/upgrade/types.d.ts +0 -61
  155. package/dist/storage/upgrade/types.js +0 -42
  156. package/dist/storage/upgrade/upgrade.d.ts +0 -33
  157. package/dist/storage/upgrade/upgrade.js +0 -196
  158. package/dist/storage/upgrade/upgrade.worker.d.ts +0 -1
  159. package/dist/storage/upgrade/upgrade.worker.js +0 -220
package/dist/cli/cli.js CHANGED
@@ -4,7 +4,6 @@ import { parseArgs } from 'node:util';
4
4
  import { setTimeout as wait } from 'node:timers/promises';
5
5
  import { Exception, hasErrorCode, isException } from 'jg-exception';
6
6
  import { HqRequestSchema } from '../contracts/index.js';
7
- import { upgradeHqStorage } from '../storage/upgrade/index.js';
8
7
  import { requestAgentHq } from '../ipc/index.js';
9
8
  import { createAgentHq } from '../runtime/index.js';
10
9
  import { readRuntimeOwner } from '../runtime/state/index.js';
@@ -27,7 +26,6 @@ const main = async () => {
27
26
  allowPositionals: true,
28
27
  options: {
29
28
  'state-root': { type: 'string' },
30
- 'backup-directory': { type: 'string' },
31
29
  'coordination-root': { type: 'string' },
32
30
  directory: { type: 'string' },
33
31
  'workspace-root': { type: 'string', multiple: true },
@@ -45,6 +43,7 @@ const main = async () => {
45
43
  topic: { type: 'string' },
46
44
  cursor: { type: 'string' },
47
45
  limit: { type: 'string' },
46
+ 'after-sequence': { type: 'string' },
48
47
  search: { type: 'string' },
49
48
  provider: { type: 'string' },
50
49
  help: { type: 'boolean', short: 'h' },
@@ -52,7 +51,7 @@ const main = async () => {
52
51
  });
53
52
  const [kind] = positionals;
54
53
  if (values.help || !kind || kind === 'help') {
55
- process.stdout.write('jg-agent-hq serve|upgrade-storage|status|stop|capabilities|threads|thread|turns|items|sessions|session-evidence|usage|account|models|configuration|mcp-servers|mcp-tools|mcp-resources|managed-thread-name|suggest-thread-name|skills|skill-preview|plan-status|plan-milestones|request --state-root <path> [--provider <provider-id>] [--workspace-root <path>] [--native-id <id>] [--limit <1..128>] [--cursor <cursor>] [--name <name>] [--topic <topic>] [--thread-id <id>] [--server-name <name>] [--skill-id <id>] [--arguments <text>] [--directory <path>]\nserve accepts repeated --codex-extra-skill-root and --claude-additional-directory.\nsession-evidence accepts --native-item-id and repeated --evidence-kind.\nrequest reads one validated HQ command as JSON from stdin.\nupgrade-storage --state-root <existing-path> --backup-directory <absent-path> --workspace-root <path> [--workspace-root <path> ...] [--coordination-root <path>]\nStop HQ/native children and independent database/plan writers first. Existing owners are never reclaimed.\nLegacy serve errors require upgrade-storage; startup never migrates. Keep the verified backup. Uncertain outcomes require explicit reconciliation; retry inspects the durable stamp.\n');
54
+ process.stdout.write('jg-agent-hq serve|status|stop|capabilities|threads|thread|turns|items|sessions|session-evidence|usage|account|models|configuration|mcp-servers|mcp-tools|mcp-resources|managed-thread-name|suggest-thread-name|skills|skill-preview|plan-status|plan-milestones|session-states|request --state-root <path> [--provider <provider-id>] [--workspace-root <path>] [--native-id <id>] [--limit <1..128>] [--cursor <cursor>] [--name <name>] [--topic <topic>] [--thread-id <id>] [--server-name <name>] [--skill-id <id>] [--arguments <text>] [--directory <path>] [--after-sequence <sequence>]\nserve accepts repeated --codex-extra-skill-root and --claude-additional-directory, and --coordination-root for a separate existing coordination directory.\nsession-evidence accepts --native-item-id and repeated --evidence-kind.\nrequest reads one validated HQ command as JSON from stdin.\n');
56
55
  return;
57
56
  }
58
57
  if (positionals.length !== 1 || !values['state-root'])
@@ -62,36 +61,6 @@ const main = async () => {
62
61
  });
63
62
  const stateRoot = resolve(values['state-root']);
64
63
  const roots = (values['workspace-root'] ?? []).map((root) => resolve(root));
65
- if (kind === 'upgrade-storage') {
66
- const allowed = new Set([
67
- 'state-root',
68
- 'backup-directory',
69
- 'workspace-root',
70
- 'coordination-root',
71
- ]);
72
- if (!values['backup-directory'] ||
73
- roots.length === 0 ||
74
- Object.keys(values).some((key) => !allowed.has(key)))
75
- throw new Exception('The HQ request is invalid', {
76
- code: 'JG_AGENT_HQ_REQUEST_INVALID',
77
- data: { kind: 'invalid-request' },
78
- });
79
- const result = await upgradeHqStorage({
80
- stateRoot,
81
- backupDirectory: resolve(values['backup-directory']),
82
- allowedRoots: roots,
83
- coordinationRoot: values['coordination-root']
84
- ? resolve(values['coordination-root'])
85
- : undefined,
86
- });
87
- process.stdout.write(`${JSON.stringify({ schemaVersion: 1, kind: 'upgrade-storage', result })}\n`);
88
- return;
89
- }
90
- if (values['backup-directory'] !== undefined)
91
- throw new Exception('The HQ request is invalid', {
92
- code: 'JG_AGENT_HQ_REQUEST_INVALID',
93
- data: { kind: 'invalid-request' },
94
- });
95
64
  if (kind === 'request') {
96
65
  if (Object.keys(values).some((key) => key !== 'state-root'))
97
66
  throw new Exception('The HQ request is invalid', {
@@ -149,7 +118,8 @@ const main = async () => {
149
118
  values.cursor ||
150
119
  values.limit ||
151
120
  values.search ||
152
- values.provider)
121
+ values.provider ||
122
+ values['after-sequence'])
153
123
  throw new Exception('The HQ request is invalid', {
154
124
  code: 'JG_AGENT_HQ_REQUEST_INVALID',
155
125
  data: { kind: 'invalid-request' },
@@ -226,7 +196,28 @@ const main = async () => {
226
196
  process.stdout.write(`${JSON.stringify({ schemaVersion: 1, ...(await requestAgentHq(stateRoot, parsed.data)) })}\n`);
227
197
  return;
228
198
  }
229
- if (values.directory)
199
+ if (kind === 'session-states') {
200
+ const allowed = new Set(['state-root', 'after-sequence', 'limit']);
201
+ if (Object.keys(values).some((key) => !allowed.has(key)))
202
+ throw new Exception('The HQ request is invalid', {
203
+ code: 'JG_AGENT_HQ_REQUEST_INVALID',
204
+ data: { kind: 'invalid-request' },
205
+ });
206
+ const parsed = HqRequestSchema.safeParse({
207
+ kind: 'session-states',
208
+ afterSequence: values['after-sequence'] === undefined ? 0 : Number(values['after-sequence']),
209
+ limit: values.limit === undefined ? 32 : Number(values.limit),
210
+ });
211
+ if (!parsed.success)
212
+ throw new Exception('The HQ request is invalid', {
213
+ code: 'JG_AGENT_HQ_REQUEST_INVALID',
214
+ data: { kind: 'invalid-request' },
215
+ cause: parsed.error,
216
+ });
217
+ process.stdout.write(`${JSON.stringify({ schemaVersion: 1, ...(await requestAgentHq(stateRoot, parsed.data)) })}\n`);
218
+ return;
219
+ }
220
+ if (values.directory || values['after-sequence'])
230
221
  throw new Exception('The HQ request is invalid', {
231
222
  code: 'JG_AGENT_HQ_REQUEST_INVALID',
232
223
  data: { kind: 'invalid-request' },
@@ -1,3 +1,3 @@
1
1
  import { toPublicError } from '../errors/index.js';
2
- /** Presents static storage instructions without exposing diagnostic paths, suffixes or causes. */
2
+ /** Presents static storage diagnoses without exposing diagnostic paths, suffixes or causes. */
3
3
  export declare const toCliError: (error: unknown) => ReturnType<typeof toPublicError>;
@@ -1,30 +1,13 @@
1
1
  import { isException } from 'jg-exception';
2
2
  import { toPublicError } from '../errors/index.js';
3
- // only these operator-facing storage diagnoses bypass the generic IPC presentation
4
- const STORAGE_MESSAGES = {
5
- JG_AGENT_HQ_STORAGE_UPGRADE_REQUIRED: {
6
- kind: 'state-conflict',
7
- message: 'The HQ storage requires an explicit upgrade',
8
- },
9
- JG_AGENT_HQ_STORAGE_VERSION_UNSUPPORTED: {
10
- kind: 'state-conflict',
11
- message: 'The HQ storage version is unsupported',
12
- },
13
- JG_AGENT_HQ_STORAGE_UPGRADE_FAILED: {
14
- kind: 'operation-failed',
15
- message: 'The HQ storage upgrade failed',
16
- },
17
- JG_AGENT_HQ_STORAGE_UPGRADE_UNCERTAIN: {
18
- kind: 'operation-failed',
19
- message: 'The HQ storage upgrade requires reconciliation',
20
- },
21
- };
22
- /** Presents static storage instructions without exposing diagnostic paths, suffixes or causes. */
3
+ // the only storage diagnosis shown: which package version wrote the storage, never its cause
4
+ const WRITER_MESSAGE = /^The HQ storage is invalid: written by (?:jg-agent-hq [0-9A-Za-z.+-]{1,64}|another jg-agent-hq version)(?=$|; \[CAUSE\]: )/;
5
+ /** Presents static storage diagnoses without exposing diagnostic paths, suffixes or causes. */
23
6
  export const toCliError = (error) => {
24
- if (isException(error)) {
25
- for (const [code, presentation] of Object.entries(STORAGE_MESSAGES))
26
- if (error.code === code)
27
- return presentation;
28
- }
7
+ if (isException(error) && error.code === 'JG_AGENT_HQ_STORAGE_INVALID')
8
+ return {
9
+ kind: 'state-conflict',
10
+ message: WRITER_MESSAGE.exec(error.message)?.[0] ?? 'The HQ storage is invalid',
11
+ };
29
12
  return toPublicError(error);
30
13
  };
@@ -410,8 +410,8 @@ export declare const DispatchJobSchema: z.ZodObject<{
410
410
  name: z.ZodString;
411
411
  workspaceRoot: z.ZodString;
412
412
  ownership: z.ZodEnum<{
413
- uncertain: "uncertain";
414
413
  managed: "managed";
414
+ uncertain: "uncertain";
415
415
  }>;
416
416
  runtimeEpoch: z.ZodNullable<z.ZodUUID>;
417
417
  activeTurnId: z.ZodNullable<z.ZodString>;
@@ -422,10 +422,10 @@ export declare const DispatchJobSchema: z.ZodObject<{
422
422
  failed: "failed";
423
423
  interrupted: "interrupted";
424
424
  "waiting-input": "waiting-input";
425
+ running: "running";
425
426
  creating: "creating";
426
427
  inactive: "inactive";
427
428
  starting: "starting";
428
- running: "running";
429
429
  "waiting-approval": "waiting-approval";
430
430
  stopping: "stopping";
431
431
  }>;
@@ -634,10 +634,10 @@ export declare const ActionReceiptSchema: z.ZodObject<{
634
634
  delivery: z.ZodEnum<{
635
635
  failed: "failed";
636
636
  canceled: "canceled";
637
+ uncertain: "uncertain";
637
638
  queued: "queued";
638
639
  submitted: "submitted";
639
640
  acknowledged: "acknowledged";
640
- uncertain: "uncertain";
641
641
  }>;
642
642
  completion: z.ZodNullable<z.ZodEnum<{
643
643
  completed: "completed";
@@ -784,10 +784,10 @@ export declare const ActionSummarySchema: z.ZodObject<{
784
784
  delivery: z.ZodEnum<{
785
785
  failed: "failed";
786
786
  canceled: "canceled";
787
+ uncertain: "uncertain";
787
788
  queued: "queued";
788
789
  submitted: "submitted";
789
790
  acknowledged: "acknowledged";
790
- uncertain: "uncertain";
791
791
  }>;
792
792
  digest: z.ZodString;
793
793
  controlState: z.ZodNullable<z.ZodEnum<{
@@ -837,8 +837,8 @@ export declare const ManagedThreadSchema: z.ZodObject<{
837
837
  name: z.ZodString;
838
838
  workspaceRoot: z.ZodString;
839
839
  ownership: z.ZodEnum<{
840
- uncertain: "uncertain";
841
840
  managed: "managed";
841
+ uncertain: "uncertain";
842
842
  }>;
843
843
  runtimeEpoch: z.ZodNullable<z.ZodUUID>;
844
844
  activeTurnId: z.ZodNullable<z.ZodString>;
@@ -849,10 +849,10 @@ export declare const ManagedThreadSchema: z.ZodObject<{
849
849
  failed: "failed";
850
850
  interrupted: "interrupted";
851
851
  "waiting-input": "waiting-input";
852
+ running: "running";
852
853
  creating: "creating";
853
854
  inactive: "inactive";
854
855
  starting: "starting";
855
- running: "running";
856
856
  "waiting-approval": "waiting-approval";
857
857
  stopping: "stopping";
858
858
  }>;
@@ -1,5 +1,3 @@
1
1
  export { BrowserCommandSchema, BrowserActionSchema, BrowserReceiptSchema } from './types.js';
2
2
  export type { IBrowserAction, IBrowserReceipt } from './types.js';
3
- export { BrowserRepositorySchema, BrowserPlanSummarySchema, BrowserPlanPageSchema, BrowserPlanDetailSchema, BrowserSessionSchema, } from './types.js';
4
- export { BrowserRepositoryPageSchema, BrowserSystemSchema, BrowserThreadDetailSchema, PublicationStatusSchema, } from './types.js';
5
- export type { IPublicationStatus } from './types.js';
3
+ export { BrowserThreadDetailSchema } from './types.js';
@@ -1,6 +1,4 @@
1
1
  // browser requests and durable reconciliation
2
2
  export { BrowserCommandSchema, BrowserActionSchema, BrowserReceiptSchema } from './types.js';
3
- // host read models
4
- export { BrowserRepositorySchema, BrowserPlanSummarySchema, BrowserPlanPageSchema, BrowserPlanDetailSchema, BrowserSessionSchema, } from './types.js';
5
3
  // bounded host views
6
- export { BrowserRepositoryPageSchema, BrowserSystemSchema, BrowserThreadDetailSchema, PublicationStatusSchema, } from './types.js';
4
+ export { BrowserThreadDetailSchema } from './types.js';