agent-conveyor 0.1.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 (85) hide show
  1. package/README.md +1123 -0
  2. package/dist/cli/main.d.ts +2 -0
  3. package/dist/cli/main.js +19 -0
  4. package/dist/cli/main.js.map +1 -0
  5. package/dist/cli/program-name.d.ts +2 -0
  6. package/dist/cli/program-name.js +12 -0
  7. package/dist/cli/program-name.js.map +1 -0
  8. package/dist/cli/typescript-runtime.d.ts +52 -0
  9. package/dist/cli/typescript-runtime.js +18009 -0
  10. package/dist/cli/typescript-runtime.js.map +1 -0
  11. package/dist/index.d.ts +37 -0
  12. package/dist/index.js +20 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/runtime/audit.d.ts +96 -0
  15. package/dist/runtime/audit.js +298 -0
  16. package/dist/runtime/audit.js.map +1 -0
  17. package/dist/runtime/classify.d.ts +8 -0
  18. package/dist/runtime/classify.js +128 -0
  19. package/dist/runtime/classify.js.map +1 -0
  20. package/dist/runtime/codex-session.d.ts +103 -0
  21. package/dist/runtime/codex-session.js +408 -0
  22. package/dist/runtime/codex-session.js.map +1 -0
  23. package/dist/runtime/commands.d.ts +92 -0
  24. package/dist/runtime/commands.js +408 -0
  25. package/dist/runtime/commands.js.map +1 -0
  26. package/dist/runtime/dispatch.d.ts +74 -0
  27. package/dist/runtime/dispatch.js +669 -0
  28. package/dist/runtime/dispatch.js.map +1 -0
  29. package/dist/runtime/export.d.ts +22 -0
  30. package/dist/runtime/export.js +77 -0
  31. package/dist/runtime/export.js.map +1 -0
  32. package/dist/runtime/ingest.d.ts +28 -0
  33. package/dist/runtime/ingest.js +177 -0
  34. package/dist/runtime/ingest.js.map +1 -0
  35. package/dist/runtime/loop-evidence.d.ts +87 -0
  36. package/dist/runtime/loop-evidence.js +448 -0
  37. package/dist/runtime/loop-evidence.js.map +1 -0
  38. package/dist/runtime/manager-config.d.ts +20 -0
  39. package/dist/runtime/manager-config.js +34 -0
  40. package/dist/runtime/manager-config.js.map +1 -0
  41. package/dist/runtime/manager-permissions.d.ts +7 -0
  42. package/dist/runtime/manager-permissions.js +85 -0
  43. package/dist/runtime/manager-permissions.js.map +1 -0
  44. package/dist/runtime/notifications.d.ts +89 -0
  45. package/dist/runtime/notifications.js +208 -0
  46. package/dist/runtime/notifications.js.map +1 -0
  47. package/dist/runtime/replay.d.ts +29 -0
  48. package/dist/runtime/replay.js +331 -0
  49. package/dist/runtime/replay.js.map +1 -0
  50. package/dist/runtime/tasks.d.ts +54 -0
  51. package/dist/runtime/tasks.js +195 -0
  52. package/dist/runtime/tasks.js.map +1 -0
  53. package/dist/runtime/tmux.d.ts +61 -0
  54. package/dist/runtime/tmux.js +189 -0
  55. package/dist/runtime/tmux.js.map +1 -0
  56. package/dist/runtime/visual-diff.d.ts +23 -0
  57. package/dist/runtime/visual-diff.js +234 -0
  58. package/dist/runtime/visual-diff.js.map +1 -0
  59. package/dist/state/database.d.ts +21 -0
  60. package/dist/state/database.js +142 -0
  61. package/dist/state/database.js.map +1 -0
  62. package/dist/state/files.d.ts +38 -0
  63. package/dist/state/files.js +73 -0
  64. package/dist/state/files.js.map +1 -0
  65. package/dist/state/schema-v22.d.ts +1 -0
  66. package/dist/state/schema-v22.js +566 -0
  67. package/dist/state/schema-v22.js.map +1 -0
  68. package/dist/state/sqlite-contract.d.ts +4 -0
  69. package/dist/state/sqlite-contract.js +78 -0
  70. package/dist/state/sqlite-contract.js.map +1 -0
  71. package/dist/state/status.d.ts +12 -0
  72. package/dist/state/status.js +40 -0
  73. package/dist/state/status.js.map +1 -0
  74. package/docs/typescript-migration/cli-contract.md +147 -0
  75. package/docs/typescript-migration/dashboard-contract.md +76 -0
  76. package/docs/typescript-migration/package-install-contract.md +98 -0
  77. package/docs/typescript-migration/qa-gate-matrix.md +103 -0
  78. package/docs/typescript-migration/sqlite-state-contract.md +92 -0
  79. package/docs/typescript-migration/t005-runtime-parity.md +47 -0
  80. package/package.json +88 -0
  81. package/scripts/capture-static-html-screenshot.mjs +88 -0
  82. package/skills/codex-review/SKILL.md +116 -0
  83. package/skills/codex-review/scripts/codex-review +344 -0
  84. package/skills/manage-codex-workers/SKILL.md +696 -0
  85. package/skills/manage-codex-workers/agents/openai.yaml +5 -0
@@ -0,0 +1,37 @@
1
+ export { programNameFromArgv } from "./cli/program-name.js";
2
+ export type { CliProgram } from "./cli/program-name.js";
3
+ export { captureMetaPath, configPath, defaultDbPath, eventsPath, loadJsonSync, stateRoot, statusPath, transcriptPath, validateWorkerName, workerDir, WorkerctlStateError, writeJsonSync, } from "./state/files.js";
4
+ export { latestStatusSync } from "./state/status.js";
5
+ export type { WorkerStatus } from "./state/status.js";
6
+ export { configureConnectionSync, databaseHealthSync, initializeDatabaseSync, openDatabaseSync, WorkerctlDatabaseError, } from "./state/database.js";
7
+ export type { DatabaseCheck, DatabaseHealth } from "./state/database.js";
8
+ export { taskAuditSync, TaskAuditError } from "./runtime/audit.js";
9
+ export type { TaskAuditCorrelationChain, TaskAuditEvent, TaskAuditManagerDecision, TaskAuditResult, TaskAuditRoutedNotification, TaskAuditTask, } from "./runtime/audit.js";
10
+ export { exportTaskAuditSubsetSync, TaskExportError } from "./runtime/export.js";
11
+ export type { TaskExportManifest, TaskExportResult } from "./runtime/export.js";
12
+ export { replayEntriesFromAudit, replayResultFromAudit } from "./runtime/replay.js";
13
+ export type { ReplayEntry, ReplayMode, ReplayResult, ReplayRole } from "./runtime/replay.js";
14
+ export { classifyBusyWait, classifyStartupOutput } from "./runtime/classify.js";
15
+ export type { BusyWaitClassification, StartupState } from "./runtime/classify.js";
16
+ export { claimableDispatchCommandsSync, claimNextDispatchCommandSync, createCommandSync, finishCommandAttemptSync, markCommandAttemptSideEffectStartedSync, recoverStaleDispatchClaimsSync, CommandQueueError, } from "./runtime/commands.js";
17
+ export type { ClaimedCommand, CommandAttemptRecord, CommandRecord, RecoveredDispatchClaim } from "./runtime/commands.js";
18
+ export { checkDispatchRequiredPermissionSync, executeDispatchCommandSync, resolveDispatchCommandRouteSync, DispatchPermissionError, DispatchRoutingError, } from "./runtime/dispatch.js";
19
+ export type { DispatchCommandResult, DispatchCommandRoute, DispatchPermissionCheck } from "./runtime/dispatch.js";
20
+ export { managerConfigPermissionAllowed, managerConfigSync } from "./runtime/manager-config.js";
21
+ export type { ManagerConfigRecord } from "./runtime/manager-config.js";
22
+ export { canonicalManagerPermissionNames, flattenManagerPermissions, managerPermissionAllowed, normalizeManagerPermissions, } from "./runtime/manager-permissions.js";
23
+ export type { ManagerPermissions, ManagerPermissionCategory } from "./runtime/manager-permissions.js";
24
+ export { consumeNextSessionInboxItemSync, deferRoutedNotificationBeforeSideEffectSync, deliveryModeForTargetSessionSync, finishRoutedNotificationSync, insertRoutedNotificationSync, markRoutedNotificationSideEffectStartedSync, routedNotificationsSync, sessionInboxSync, RoutedNotificationError, } from "./runtime/notifications.js";
25
+ export type { RoutedNotificationDeliveryMode, RoutedNotificationRecord, RoutedNotificationState, SessionInboxRecord, } from "./runtime/notifications.js";
26
+ export { discoverSession, findNativeCodexPid, findRolloutPathForPid, findRolloutPathInLsof, readSessionMeta } from "./runtime/codex-session.js";
27
+ export type { CodexSessionDiscovery, CodexSessionMeta } from "./runtime/codex-session.js";
28
+ export { inferState, ingestSessionSync, parseJsonlEvents, parseJsonlEventsWithStats } from "./runtime/ingest.js";
29
+ export type { IngestResult, ParsedCodexEvent } from "./runtime/ingest.js";
30
+ export { acceptanceCriteriaForTaskSync, loopEvidenceCriterion, recordAdversarialLoopEvidenceSync, recordLoopEvidenceSync, recordVisualDiffLoopEvidenceSync, LoopEvidenceError, } from "./runtime/loop-evidence.js";
31
+ export type { AcceptanceCriterionRecord, AcceptanceCriterionSource, AcceptanceCriterionStatus, LoopEvidenceRecordResult, RalphLoopRunRecord, VisualDiffLoopEvidenceResult, } from "./runtime/loop-evidence.js";
32
+ export { computeVisualDiffSync, writePngRgba, VisualDiffError } from "./runtime/visual-diff.js";
33
+ export type { VisualDiffReport } from "./runtime/visual-diff.js";
34
+ export { activeBindingForTaskSync, bindSessionsSync, createTaskSync, latestSessionBindingForTaskSync, listTasksSync, unbindTaskSync, TaskLifecycleError, } from "./runtime/tasks.js";
35
+ export type { SessionBindingRecord, TaskBudget, TaskRecord } from "./runtime/tasks.js";
36
+ export { capturePaneArgs, hasSessionArgs, isTmuxPermissionError, listPanesArgs, raiseForTmuxPermissionFailure, sendTextCommandSequence, sendTextToSessionWithRunner, sendTextWithRunner, sessionTmuxTarget, sessionExists, tmuxCommandFailureMessage, tmuxPermissionErrorMessage, tmuxSession, tmuxSessionRunning, tmuxTarget, } from "./runtime/tmux.js";
37
+ export type { SendTextResult, TmuxCommandResult, TmuxRunner } from "./runtime/tmux.js";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ export { programNameFromArgv } from "./cli/program-name.js";
2
+ export { captureMetaPath, configPath, defaultDbPath, eventsPath, loadJsonSync, stateRoot, statusPath, transcriptPath, validateWorkerName, workerDir, WorkerctlStateError, writeJsonSync, } from "./state/files.js";
3
+ export { latestStatusSync } from "./state/status.js";
4
+ export { configureConnectionSync, databaseHealthSync, initializeDatabaseSync, openDatabaseSync, WorkerctlDatabaseError, } from "./state/database.js";
5
+ export { taskAuditSync, TaskAuditError } from "./runtime/audit.js";
6
+ export { exportTaskAuditSubsetSync, TaskExportError } from "./runtime/export.js";
7
+ export { replayEntriesFromAudit, replayResultFromAudit } from "./runtime/replay.js";
8
+ export { classifyBusyWait, classifyStartupOutput } from "./runtime/classify.js";
9
+ export { claimableDispatchCommandsSync, claimNextDispatchCommandSync, createCommandSync, finishCommandAttemptSync, markCommandAttemptSideEffectStartedSync, recoverStaleDispatchClaimsSync, CommandQueueError, } from "./runtime/commands.js";
10
+ export { checkDispatchRequiredPermissionSync, executeDispatchCommandSync, resolveDispatchCommandRouteSync, DispatchPermissionError, DispatchRoutingError, } from "./runtime/dispatch.js";
11
+ export { managerConfigPermissionAllowed, managerConfigSync } from "./runtime/manager-config.js";
12
+ export { canonicalManagerPermissionNames, flattenManagerPermissions, managerPermissionAllowed, normalizeManagerPermissions, } from "./runtime/manager-permissions.js";
13
+ export { consumeNextSessionInboxItemSync, deferRoutedNotificationBeforeSideEffectSync, deliveryModeForTargetSessionSync, finishRoutedNotificationSync, insertRoutedNotificationSync, markRoutedNotificationSideEffectStartedSync, routedNotificationsSync, sessionInboxSync, RoutedNotificationError, } from "./runtime/notifications.js";
14
+ export { discoverSession, findNativeCodexPid, findRolloutPathForPid, findRolloutPathInLsof, readSessionMeta } from "./runtime/codex-session.js";
15
+ export { inferState, ingestSessionSync, parseJsonlEvents, parseJsonlEventsWithStats } from "./runtime/ingest.js";
16
+ export { acceptanceCriteriaForTaskSync, loopEvidenceCriterion, recordAdversarialLoopEvidenceSync, recordLoopEvidenceSync, recordVisualDiffLoopEvidenceSync, LoopEvidenceError, } from "./runtime/loop-evidence.js";
17
+ export { computeVisualDiffSync, writePngRgba, VisualDiffError } from "./runtime/visual-diff.js";
18
+ export { activeBindingForTaskSync, bindSessionsSync, createTaskSync, latestSessionBindingForTaskSync, listTasksSync, unbindTaskSync, TaskLifecycleError, } from "./runtime/tasks.js";
19
+ export { capturePaneArgs, hasSessionArgs, isTmuxPermissionError, listPanesArgs, raiseForTmuxPermissionFailure, sendTextCommandSequence, sendTextToSessionWithRunner, sendTextWithRunner, sessionTmuxTarget, sessionExists, tmuxCommandFailureMessage, tmuxPermissionErrorMessage, tmuxSession, tmuxSessionRunning, tmuxTarget, } from "./runtime/tmux.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EACL,eAAe,EACf,UAAU,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EAC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BAAyB,EAAE,MAAM,qBAAqB,CAAC;AAEjH,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,iCAAiC,EACjC,sBAAsB,EACtB,gCAAgC,EAChC,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhG,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,+BAA+B,EAC/B,aAAa,EACb,cAAc,EACd,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,6BAA6B,EAC7B,uBAAuB,EACvB,2BAA2B,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,yBAAyB,EACzB,0BAA0B,EAC1B,WAAW,EACX,kBAAkB,EAClB,UAAU,GACX,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import type { AcceptanceCriterionRecord } from "./loop-evidence.js";
3
+ import type { CommandAttemptRecord, CommandRecord } from "./commands.js";
4
+ import type { RoutedNotificationDeliveryMode, RoutedNotificationState } from "./notifications.js";
5
+ export interface TaskAuditTask {
6
+ created_at: string;
7
+ goal: string;
8
+ id: string;
9
+ name: string;
10
+ state: string;
11
+ summary: string | null;
12
+ updated_at: string;
13
+ }
14
+ export interface TaskAuditEvent {
15
+ actor: string;
16
+ command_id: string | null;
17
+ correlation_id: string | null;
18
+ created_at: string;
19
+ id: number;
20
+ manager_id: string | null;
21
+ payload: Record<string, unknown>;
22
+ task_id: string;
23
+ type: string;
24
+ worker_id: string | null;
25
+ }
26
+ export interface TaskAuditManagerDecision {
27
+ created_at: string;
28
+ decision: string;
29
+ id: number;
30
+ manager_cycle_id: number | null;
31
+ manager_id: string | null;
32
+ payload: Record<string, unknown>;
33
+ reason: string;
34
+ task_id: string;
35
+ }
36
+ export interface TaskAuditRoutedNotification {
37
+ binding_id: string;
38
+ claimed_at: string | null;
39
+ claimed_by: string | null;
40
+ claim_expires_at: string | null;
41
+ command_id: string | null;
42
+ correlation_id: string;
43
+ created_at: string;
44
+ consumed_at: string | null;
45
+ consumed_by_session_id: string | null;
46
+ consumed_by_session_name: string | null;
47
+ consumed_by_session_role: string | null;
48
+ consumed_manager_cycle_id: number | null;
49
+ dedupe_key: string;
50
+ delivered_at: string | null;
51
+ delivery_mode: RoutedNotificationDeliveryMode;
52
+ error: string | null;
53
+ id: number;
54
+ payload: Record<string, unknown>;
55
+ side_effect_completed: boolean;
56
+ side_effect_started: boolean;
57
+ signal_type: string;
58
+ source_event_id: number | null;
59
+ source_event_timestamp: string | null;
60
+ source_session_id: string;
61
+ source_session_name: string;
62
+ source_session_role: string;
63
+ state: RoutedNotificationState;
64
+ target_session_id: string;
65
+ target_session_name: string;
66
+ target_session_role: string;
67
+ task_id: string;
68
+ }
69
+ export interface TaskAuditCorrelationChain {
70
+ attempt_ids: number[];
71
+ command_id: string | null;
72
+ command_state: string;
73
+ command_type: string;
74
+ correlation_id: string | null;
75
+ created_at: string;
76
+ manager_cycle_id: number | null;
77
+ manager_decision_cycle_id?: number | null;
78
+ manager_decision_id: number | null;
79
+ routed_notification_ids: number[];
80
+ signal_type?: string;
81
+ source_event_id?: number | null;
82
+ }
83
+ export interface TaskAuditResult {
84
+ acceptance_criteria: AcceptanceCriterionRecord[];
85
+ command_attempts: CommandAttemptRecord[];
86
+ commands: CommandRecord[];
87
+ correlation_chains: TaskAuditCorrelationChain[];
88
+ events: TaskAuditEvent[];
89
+ manager_decisions: TaskAuditManagerDecision[];
90
+ routed_notifications: TaskAuditRoutedNotification[];
91
+ task: TaskAuditTask;
92
+ }
93
+ export declare class TaskAuditError extends Error {
94
+ constructor(message: string);
95
+ }
96
+ export declare function taskAuditSync(database: DatabaseSync, task: string): TaskAuditResult;
@@ -0,0 +1,298 @@
1
+ import { acceptanceCriteriaForTaskSync } from "./loop-evidence.js";
2
+ export class TaskAuditError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "TaskAuditError";
6
+ }
7
+ }
8
+ export function taskAuditSync(database, task) {
9
+ const taskRow = taskRowSync(database, task);
10
+ const commands = commandRecordsForTaskSync(database, taskRow.id);
11
+ const commandAttempts = commandAttemptRecordsForTaskSync(database, taskRow.id);
12
+ const routedNotifications = routedNotificationRecordsForTaskSync(database, taskRow.id);
13
+ const managerDecisions = managerDecisionRecordsForTaskSync(database, taskRow.id);
14
+ return {
15
+ acceptance_criteria: acceptanceCriteriaForTaskSync(database, { taskId: taskRow.id }),
16
+ command_attempts: commandAttempts,
17
+ commands,
18
+ correlation_chains: buildCorrelationChains({
19
+ commandAttempts,
20
+ commands,
21
+ managerDecisions,
22
+ routedNotifications,
23
+ }),
24
+ events: eventRecordsForTaskSync(database, taskRow.id),
25
+ manager_decisions: managerDecisions,
26
+ routed_notifications: routedNotifications,
27
+ task: taskRow,
28
+ };
29
+ }
30
+ function taskRowSync(database, task) {
31
+ const row = database.prepare(`
32
+ select id, name, goal, summary, state, created_at, updated_at
33
+ from tasks
34
+ where id = ? or name = ?
35
+ order by created_at desc
36
+ limit 1
37
+ `).get(task, task);
38
+ if (!row) {
39
+ throw new TaskAuditError(`Unknown task: ${task}`);
40
+ }
41
+ return {
42
+ created_at: row.created_at,
43
+ goal: row.goal,
44
+ id: row.id,
45
+ name: row.name,
46
+ state: row.state,
47
+ summary: row.summary,
48
+ updated_at: row.updated_at,
49
+ };
50
+ }
51
+ function eventRecordsForTaskSync(database, taskId) {
52
+ const rows = database.prepare(`
53
+ select id, created_at, actor, command_id, correlation_id, task_id,
54
+ worker_id, manager_id, type, payload_json
55
+ from events
56
+ where task_id = ?
57
+ order by id
58
+ `).all(taskId);
59
+ return rows.map((row) => ({
60
+ actor: row.actor,
61
+ command_id: row.command_id,
62
+ correlation_id: row.correlation_id,
63
+ created_at: row.created_at,
64
+ id: row.id,
65
+ manager_id: row.manager_id,
66
+ payload: parseJsonObject(row.payload_json),
67
+ task_id: row.task_id,
68
+ type: row.type,
69
+ worker_id: row.worker_id,
70
+ }));
71
+ }
72
+ function commandRecordsForTaskSync(database, taskId) {
73
+ const rows = database.prepare(`
74
+ select id, idempotency_key, created_at, updated_at, task_id, worker_id,
75
+ manager_id, correlation_id, type, state, available_at, claimed_by,
76
+ claimed_at, claim_expires_at, attempts, max_attempts, payload_json,
77
+ required_permission, result_json, error
78
+ from commands
79
+ where task_id = ?
80
+ order by created_at, id
81
+ `).all(taskId);
82
+ return rows.map(commandRecord);
83
+ }
84
+ function commandAttemptRecordsForTaskSync(database, taskId) {
85
+ const rows = database.prepare(`
86
+ select command_attempts.id, command_attempts.command_id,
87
+ command_attempts.correlation_id, command_attempts.dispatcher_id,
88
+ command_attempts.started_at, command_attempts.finished_at,
89
+ command_attempts.state, command_attempts.result_json,
90
+ command_attempts.error, command_attempts.side_effect_started,
91
+ command_attempts.side_effect_completed
92
+ from command_attempts
93
+ join commands on commands.id = command_attempts.command_id
94
+ where commands.task_id = ?
95
+ order by command_attempts.started_at, command_attempts.id
96
+ `).all(taskId);
97
+ return rows.map(commandAttemptRecord);
98
+ }
99
+ function routedNotificationRecordsForTaskSync(database, taskId) {
100
+ const rows = database.prepare(`
101
+ select rn.id, rn.task_id, rn.binding_id, rn.correlation_id,
102
+ rn.source_session_id, rn.target_session_id, rn.signal_type,
103
+ rn.source_event_id, rn.source_event_timestamp, rn.dedupe_key,
104
+ rn.command_id, rn.created_at, rn.delivered_at,
105
+ rn.consumed_manager_cycle_id, rn.consumed_by_session_id,
106
+ rn.consumed_at, rn.delivery_mode, rn.state, rn.claimed_by,
107
+ rn.claimed_at, rn.claim_expires_at,
108
+ rn.side_effect_started, rn.side_effect_completed, rn.payload_json,
109
+ rn.error,
110
+ ss.name as source_session_name, ss.role as source_session_role,
111
+ ts.name as target_session_name, ts.role as target_session_role,
112
+ cs.name as consumed_by_session_name,
113
+ cs.role as consumed_by_session_role
114
+ from routed_notifications rn
115
+ join sessions ss on ss.id = rn.source_session_id
116
+ join sessions ts on ts.id = rn.target_session_id
117
+ left join sessions cs on cs.id = rn.consumed_by_session_id
118
+ where rn.task_id = ?
119
+ order by rn.created_at, rn.id
120
+ `).all(taskId);
121
+ return rows.map(routedNotificationRecord);
122
+ }
123
+ function managerDecisionRecordsForTaskSync(database, taskId) {
124
+ const rows = database.prepare(`
125
+ select id, task_id, manager_id, manager_cycle_id, decision, reason,
126
+ created_at, payload_json
127
+ from manager_decisions
128
+ where task_id = ?
129
+ order by id
130
+ `).all(taskId);
131
+ return rows.map((row) => ({
132
+ created_at: row.created_at,
133
+ decision: row.decision,
134
+ id: row.id,
135
+ manager_cycle_id: row.manager_cycle_id,
136
+ manager_id: row.manager_id,
137
+ payload: parseJsonObject(row.payload_json),
138
+ reason: row.reason,
139
+ task_id: row.task_id,
140
+ }));
141
+ }
142
+ function buildCorrelationChains(options) {
143
+ const decisionsById = new Map(options.managerDecisions.map((decision) => [decision.id, decision]));
144
+ const attemptsByCommand = groupBy(options.commandAttempts, (attempt) => attempt.command_id);
145
+ const notificationsByCommand = groupBy(options.routedNotifications.filter((notification) => notification.command_id), (notification) => notification.command_id ?? "");
146
+ const chains = [];
147
+ for (const command of options.commands) {
148
+ const managerDecisionId = commandManagerDecisionId(command);
149
+ const decision = managerDecisionId === null ? null : decisionsById.get(managerDecisionId) ?? null;
150
+ const attempts = attemptsByCommand.get(command.id) ?? [];
151
+ const notifications = notificationsByCommand.get(command.id) ?? [];
152
+ if (!(decision || attempts.length > 0 || notifications.length > 0 || command.correlation_id)) {
153
+ continue;
154
+ }
155
+ const consumedCycleId = notifications.find((notification) => notification.consumed_manager_cycle_id !== null)?.consumed_manager_cycle_id ?? null;
156
+ chains.push({
157
+ attempt_ids: attempts.map((attempt) => attempt.id),
158
+ command_id: command.id,
159
+ command_state: command.state,
160
+ command_type: command.type,
161
+ correlation_id: command.correlation_id,
162
+ created_at: command.created_at,
163
+ manager_cycle_id: consumedCycleId ?? decision?.manager_cycle_id ?? null,
164
+ manager_decision_cycle_id: decision?.manager_cycle_id ?? null,
165
+ manager_decision_id: decision?.id ?? null,
166
+ routed_notification_ids: notifications.map((notification) => notification.id),
167
+ });
168
+ }
169
+ for (const notification of options.routedNotifications.filter((item) => !item.command_id)) {
170
+ chains.push({
171
+ attempt_ids: [],
172
+ command_id: null,
173
+ command_state: notification.state,
174
+ command_type: notification.signal_type,
175
+ correlation_id: notification.correlation_id,
176
+ created_at: notification.created_at,
177
+ manager_cycle_id: notification.consumed_manager_cycle_id,
178
+ manager_decision_id: null,
179
+ routed_notification_ids: [notification.id],
180
+ signal_type: notification.signal_type,
181
+ source_event_id: notification.source_event_id,
182
+ });
183
+ }
184
+ return chains.sort((left, right) => {
185
+ const time = left.created_at.localeCompare(right.created_at);
186
+ if (time !== 0) {
187
+ return time;
188
+ }
189
+ return String(left.command_id ?? "").localeCompare(String(right.command_id ?? ""));
190
+ });
191
+ }
192
+ function commandManagerDecisionId(command) {
193
+ for (const root of [command.payload, command.result ?? {}]) {
194
+ const managerDecision = root.manager_decision;
195
+ if (!isRecord(managerDecision)) {
196
+ continue;
197
+ }
198
+ const decisionRecord = isRecord(managerDecision.decision) ? managerDecision.decision : managerDecision;
199
+ const decisionId = managerDecision.decision_id ?? decisionRecord.id;
200
+ if (typeof decisionId === "number" && Number.isInteger(decisionId)) {
201
+ return decisionId;
202
+ }
203
+ if (typeof decisionId === "string" && /^\d+$/.test(decisionId)) {
204
+ return Number(decisionId);
205
+ }
206
+ }
207
+ return null;
208
+ }
209
+ function groupBy(items, keyFor) {
210
+ const grouped = new Map();
211
+ for (const item of items) {
212
+ const key = keyFor(item);
213
+ grouped.set(key, [...(grouped.get(key) ?? []), item]);
214
+ }
215
+ return grouped;
216
+ }
217
+ function commandRecord(row) {
218
+ return {
219
+ attempts: row.attempts,
220
+ available_at: row.available_at,
221
+ claim_expires_at: row.claim_expires_at,
222
+ claimed_at: row.claimed_at,
223
+ claimed_by: row.claimed_by,
224
+ correlation_id: row.correlation_id,
225
+ created_at: row.created_at,
226
+ error: row.error,
227
+ id: row.id,
228
+ idempotency_key: row.idempotency_key,
229
+ manager_id: row.manager_id,
230
+ max_attempts: row.max_attempts,
231
+ payload: parseJsonObject(row.payload_json),
232
+ required_permission: row.required_permission,
233
+ result: row.result_json ? parseJsonObject(row.result_json) : null,
234
+ state: row.state,
235
+ task_id: row.task_id,
236
+ type: row.type,
237
+ updated_at: row.updated_at,
238
+ worker_id: row.worker_id,
239
+ };
240
+ }
241
+ function commandAttemptRecord(row) {
242
+ return {
243
+ command_id: row.command_id,
244
+ correlation_id: row.correlation_id,
245
+ dispatcher_id: row.dispatcher_id,
246
+ error: row.error,
247
+ finished_at: row.finished_at,
248
+ id: row.id,
249
+ result: row.result_json ? parseJsonObject(row.result_json) : null,
250
+ side_effect_completed: Boolean(row.side_effect_completed),
251
+ side_effect_started: Boolean(row.side_effect_started),
252
+ started_at: row.started_at,
253
+ state: row.state,
254
+ };
255
+ }
256
+ function routedNotificationRecord(row) {
257
+ return {
258
+ binding_id: row.binding_id,
259
+ claimed_at: row.claimed_at,
260
+ claimed_by: row.claimed_by,
261
+ claim_expires_at: row.claim_expires_at,
262
+ command_id: row.command_id,
263
+ consumed_at: row.consumed_at,
264
+ consumed_by_session_id: row.consumed_by_session_id,
265
+ consumed_by_session_name: row.consumed_by_session_name,
266
+ consumed_by_session_role: row.consumed_by_session_role,
267
+ consumed_manager_cycle_id: row.consumed_manager_cycle_id,
268
+ correlation_id: row.correlation_id,
269
+ created_at: row.created_at,
270
+ dedupe_key: row.dedupe_key,
271
+ delivered_at: row.delivered_at,
272
+ delivery_mode: row.delivery_mode,
273
+ error: row.error,
274
+ id: row.id,
275
+ payload: parseJsonObject(row.payload_json),
276
+ side_effect_completed: Boolean(row.side_effect_completed),
277
+ side_effect_started: Boolean(row.side_effect_started),
278
+ signal_type: row.signal_type,
279
+ source_event_id: row.source_event_id,
280
+ source_event_timestamp: row.source_event_timestamp,
281
+ source_session_id: row.source_session_id,
282
+ source_session_name: row.source_session_name,
283
+ source_session_role: row.source_session_role,
284
+ state: row.state,
285
+ target_session_id: row.target_session_id,
286
+ target_session_name: row.target_session_name,
287
+ target_session_role: row.target_session_role,
288
+ task_id: row.task_id,
289
+ };
290
+ }
291
+ function parseJsonObject(json) {
292
+ const value = JSON.parse(json);
293
+ return isRecord(value) ? value : {};
294
+ }
295
+ function isRecord(value) {
296
+ return value !== null && typeof value === "object" && !Array.isArray(value);
297
+ }
298
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/runtime/audit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAmGnE,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,QAAsB,EAAE,IAAY;IAChE,MAAM,OAAO,GAAG,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,yBAAyB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACjE,MAAM,eAAe,GAAG,gCAAgC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/E,MAAM,mBAAmB,GAAG,oCAAoC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACvF,MAAM,gBAAgB,GAAG,iCAAiC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACjF,OAAO;QACL,mBAAmB,EAAE,6BAA6B,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;QACpF,gBAAgB,EAAE,eAAe;QAC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AC,CAAC,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,8 @@
1
+ export interface BusyWaitClassification {
2
+ pattern: string;
3
+ reason: string;
4
+ recommended_action: string;
5
+ }
6
+ export type StartupState = "error" | "needs_trust" | "ready" | "starting" | "working";
7
+ export declare function classifyStartupOutput(output: string): [StartupState, string];
8
+ export declare function classifyBusyWait(output: string, statusAge: number | null, busyWaitSeconds: number, recentEventCount?: number): BusyWaitClassification | null;
@@ -0,0 +1,128 @@
1
+ const RECENT_EVENT_QUIET_THRESHOLD = 10;
2
+ const CURRENT_PROMPT_REGION_LINES = 12;
3
+ const APPROVAL_TRANSCRIPT_TOKENS = [
4
+ "approval_prompt",
5
+ "inspect_or_approve",
6
+ "notable_pane_pattern",
7
+ ];
8
+ const APPROVAL_WORDS = ["approval", "approve"];
9
+ const APPROVAL_ACTIVE_MARKERS = [
10
+ "allow",
11
+ "deny",
12
+ "permission",
13
+ "requires approval",
14
+ "needs approval",
15
+ "approve command",
16
+ ];
17
+ const BUSY_WAIT_PATTERNS = [
18
+ [
19
+ "mcp_startup",
20
+ "Starting MCP servers",
21
+ "terminal shows Codex waiting on MCP server startup",
22
+ "inspect_or_interrupt",
23
+ ],
24
+ [
25
+ "rate_limit_prompt",
26
+ "Approaching rate limits",
27
+ "terminal shows a rate-limit model switch prompt",
28
+ "inspect_or_interrupt",
29
+ ],
30
+ [
31
+ "enter_to_confirm",
32
+ "Press enter to confirm",
33
+ "terminal is waiting for Enter confirmation",
34
+ "inspect_or_confirm",
35
+ ],
36
+ [
37
+ "trust_prompt",
38
+ "Do you trust the contents of this directory",
39
+ "terminal is waiting for workspace trust confirmation",
40
+ "inspect_or_accept_trust",
41
+ ],
42
+ [
43
+ "plan_prompt",
44
+ "Create a plan?",
45
+ "terminal is waiting at Codex plan-mode suggestion",
46
+ "inspect_or_confirm",
47
+ ],
48
+ [
49
+ "approval_prompt",
50
+ "approval",
51
+ "terminal appears to mention an approval prompt",
52
+ "inspect_or_approve",
53
+ ],
54
+ ];
55
+ export function classifyStartupOutput(output) {
56
+ const normalized = output.toLowerCase();
57
+ if (normalized.includes("do you trust the contents of this directory")) {
58
+ return ["needs_trust", "Codex is waiting for workspace trust confirmation"];
59
+ }
60
+ if (normalized.includes("openai codex") && output.includes("›")) {
61
+ return ["ready", "Codex input prompt is visible"];
62
+ }
63
+ if (normalized.includes("working") && normalized.includes("esc to interrupt")) {
64
+ return ["working", "Codex is already working"];
65
+ }
66
+ if (normalized.includes("error") || normalized.includes("failed")) {
67
+ return ["error", "terminal output contains an error-like message"];
68
+ }
69
+ if (!output.trim()) {
70
+ return ["starting", "terminal output is empty"];
71
+ }
72
+ return ["starting", "Codex has not reached a recognized startup state"];
73
+ }
74
+ export function classifyBusyWait(output, statusAge, busyWaitSeconds, recentEventCount = 0) {
75
+ if (statusAge !== null && statusAge < busyWaitSeconds) {
76
+ return null;
77
+ }
78
+ const normalized = output.toLowerCase();
79
+ for (const [pattern, needle, reason, recommendedAction] of BUSY_WAIT_PATTERNS) {
80
+ if (pattern === "approval_prompt") {
81
+ if (!looksLikeActiveApprovalPrompt(output)) {
82
+ continue;
83
+ }
84
+ }
85
+ else if (!normalized.includes(needle.toLowerCase())) {
86
+ continue;
87
+ }
88
+ return {
89
+ pattern,
90
+ reason,
91
+ recommended_action: recommendedAction,
92
+ };
93
+ }
94
+ if (normalized.includes("esc to interrupt")
95
+ && statusAge !== null
96
+ && statusAge >= busyWaitSeconds) {
97
+ if (recentEventCount >= RECENT_EVENT_QUIET_THRESHOLD) {
98
+ return null;
99
+ }
100
+ return {
101
+ pattern: "long_running_interruptible",
102
+ reason: "terminal shows an interruptible Codex operation while status.json is stale",
103
+ recommended_action: "inspect_or_interrupt",
104
+ };
105
+ }
106
+ return null;
107
+ }
108
+ function currentPromptRegion(output, lineCount = CURRENT_PROMPT_REGION_LINES) {
109
+ return output
110
+ .split(/\r?\n/)
111
+ .map((line) => line.trim())
112
+ .filter(Boolean)
113
+ .slice(-lineCount)
114
+ .join("\n");
115
+ }
116
+ function looksLikeActiveApprovalPrompt(output) {
117
+ const region = currentPromptRegion(output).toLowerCase();
118
+ if (!region) {
119
+ return false;
120
+ }
121
+ const filtered = region
122
+ .split(/\r?\n/)
123
+ .filter((line) => !APPROVAL_TRANSCRIPT_TOKENS.some((token) => line.includes(token)))
124
+ .join("\n");
125
+ return (APPROVAL_WORDS.some((word) => filtered.includes(word))
126
+ && APPROVAL_ACTIVE_MARKERS.some((marker) => filtered.includes(marker)));
127
+ }
128
+ //# sourceMappingURL=classify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify.js","sourceRoot":"","sources":["../../src/runtime/classify.ts"],"names":[],"mappings":"AAAA,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AAEvC,MAAM,0BAA0B,GAAG;IACjC,iBAAiB;IACjB,oBAAoB;IACpB,sBAAsB;CACvB,CAAC;AACF,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAC/C,MAAM,uBAAuB,GAAG;IAC9B,OAAO;IACP,MAAM;IACN,YAAY;IACZ,mBAAmB;IACnB,gBAAgB;IAChB,iBAAiB;CAClB,CAAC;AAEF,MAAM,kBAAkB,GAKnB;IACH;QACE,aAAa;QACb,sBAAsB;QACtB,oDAAoD;QACpD,sBAAsB;KACvB;IACD;QACE,mBAAmB;QACnB,yBAAyB;QACzB,iDAAiD;QACjD,sBAAsB;KACvB;IACD;QACE,kBAAkB;QAClB,wBAAwB;QACxB,4CAA4C;QAC5C,oBAAoB;KACrB;IACD;QACE,cAAc;QACd,6CAA6C;QAC7C,sDAAsD;QACtD,yBAAyB;KAC1B;IACD;QACE,aAAa;QAC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