agim-cli 1.1.1 → 1.1.3

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 (76) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +8 -1
  3. package/README.zh-CN.md +8 -1
  4. package/dist/cli.js +265 -30
  5. package/dist/cli.js.map +1 -1
  6. package/dist/core/a2a.d.ts +55 -0
  7. package/dist/core/a2a.d.ts.map +1 -0
  8. package/dist/core/a2a.js +254 -0
  9. package/dist/core/a2a.js.map +1 -0
  10. package/dist/core/approval-bus.d.ts +40 -0
  11. package/dist/core/approval-bus.d.ts.map +1 -1
  12. package/dist/core/approval-bus.js +125 -0
  13. package/dist/core/approval-bus.js.map +1 -1
  14. package/dist/core/approval-router.d.ts.map +1 -1
  15. package/dist/core/approval-router.js +31 -2
  16. package/dist/core/approval-router.js.map +1 -1
  17. package/dist/core/artifacts.d.ts +86 -0
  18. package/dist/core/artifacts.d.ts.map +1 -0
  19. package/dist/core/artifacts.js +306 -0
  20. package/dist/core/artifacts.js.map +1 -0
  21. package/dist/core/commands/a2a.d.ts +3 -0
  22. package/dist/core/commands/a2a.d.ts.map +1 -0
  23. package/dist/core/commands/a2a.js +162 -0
  24. package/dist/core/commands/a2a.js.map +1 -0
  25. package/dist/core/commands/job.d.ts.map +1 -1
  26. package/dist/core/commands/job.js +11 -2
  27. package/dist/core/commands/job.js.map +1 -1
  28. package/dist/core/commands/outbox.d.ts +3 -0
  29. package/dist/core/commands/outbox.d.ts.map +1 -0
  30. package/dist/core/commands/outbox.js +92 -0
  31. package/dist/core/commands/outbox.js.map +1 -0
  32. package/dist/core/job-board.d.ts +122 -1
  33. package/dist/core/job-board.d.ts.map +1 -1
  34. package/dist/core/job-board.js +432 -21
  35. package/dist/core/job-board.js.map +1 -1
  36. package/dist/core/job-recovery.d.ts +48 -0
  37. package/dist/core/job-recovery.d.ts.map +1 -0
  38. package/dist/core/job-recovery.js +185 -0
  39. package/dist/core/job-recovery.js.map +1 -0
  40. package/dist/core/message-sink.d.ts +63 -0
  41. package/dist/core/message-sink.d.ts.map +1 -0
  42. package/dist/core/message-sink.js +296 -0
  43. package/dist/core/message-sink.js.map +1 -0
  44. package/dist/core/outbox.d.ts +71 -0
  45. package/dist/core/outbox.d.ts.map +1 -0
  46. package/dist/core/outbox.js +301 -0
  47. package/dist/core/outbox.js.map +1 -0
  48. package/dist/core/reminders.d.ts.map +1 -1
  49. package/dist/core/reminders.js +12 -1
  50. package/dist/core/reminders.js.map +1 -1
  51. package/dist/core/restart-completion.d.ts.map +1 -1
  52. package/dist/core/restart-completion.js +18 -1
  53. package/dist/core/restart-completion.js.map +1 -1
  54. package/dist/core/router.d.ts +8 -0
  55. package/dist/core/router.d.ts.map +1 -1
  56. package/dist/core/router.js +16 -0
  57. package/dist/core/router.js.map +1 -1
  58. package/dist/core/types.d.ts +22 -0
  59. package/dist/core/types.d.ts.map +1 -1
  60. package/dist/plugins/agents/claude-code/index.d.ts.map +1 -1
  61. package/dist/plugins/agents/claude-code/index.js +5 -0
  62. package/dist/plugins/agents/claude-code/index.js.map +1 -1
  63. package/dist/plugins/agents/claude-code/mcp-approval-server.d.ts +46 -0
  64. package/dist/plugins/agents/claude-code/mcp-approval-server.d.ts.map +1 -1
  65. package/dist/plugins/agents/claude-code/mcp-approval-server.js +158 -0
  66. package/dist/plugins/agents/claude-code/mcp-approval-server.js.map +1 -1
  67. package/dist/plugins/agents/codex/index.d.ts.map +1 -1
  68. package/dist/plugins/agents/codex/index.js +5 -0
  69. package/dist/plugins/agents/codex/index.js.map +1 -1
  70. package/dist/plugins/agents/opencode/opencode-stdio-adapter.d.ts.map +1 -1
  71. package/dist/plugins/agents/opencode/opencode-stdio-adapter.js +5 -0
  72. package/dist/plugins/agents/opencode/opencode-stdio-adapter.js.map +1 -1
  73. package/dist/web/server.d.ts.map +1 -1
  74. package/dist/web/server.js +28 -16
  75. package/dist/web/server.js.map +1 -1
  76. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ // /outbox — inspect and operate the message-sink delivery queue.
2
+ //
3
+ // Subcommands:
4
+ // /outbox — same as `status`
5
+ // /outbox status — aggregate counts (pending / delivered / giving_up)
6
+ // /outbox list [N] — last N rows (default 10)
7
+ // /outbox failed [N] — last N rows in 'giving_up' state
8
+ // /outbox retry <id> — move a 'giving_up' row back to 'pending'
9
+ //
10
+ // Why expose this:
11
+ // - Operators need quick visibility into stuck deliveries without
12
+ // opening sqlite (`sqlite3 ~/.agim/outbox.db` works but isn't IM-friendly).
13
+ // - 'giving_up' is terminal by design — without a retry knob, a transient
14
+ // IM-side outage that spans the 6-step backoff (~2h cumulative) would
15
+ // leave good messages permanently dead-lettered.
16
+ //
17
+ // Permission model: the underlying outbox table is global. Phase 1 keeps
18
+ // this command admin-only / not multi-tenant — every IM user sees the same
19
+ // rows. If multi-tenant slicing becomes a requirement, gate by ctx.userId
20
+ // the same way job-board does (createJob's creator_id column).
21
+ import { getOutboxStats, listOutbox, retryGivingUp, } from '../outbox.js';
22
+ function fmtRow(r) {
23
+ const icon = r.status === 'delivered' ? '✅'
24
+ : r.status === 'giving_up' ? '💀'
25
+ : '📤';
26
+ const ts = new Date(`${r.created_at}Z`).toLocaleTimeString('zh-CN', {
27
+ hour: '2-digit', minute: '2-digit',
28
+ });
29
+ const preview = r.payload.replace(/\n/g, ' ').slice(0, 40)
30
+ + (r.payload.length > 40 ? '…' : '');
31
+ const errTail = r.last_error ? ` · err: ${r.last_error.slice(0, 60)}` : '';
32
+ return `${icon} #${r.id} ${r.platform}/${r.thread_id} [${r.status} · ${r.attempts}x] ${preview} · ${ts}${errTail}`;
33
+ }
34
+ function fmtStatus() {
35
+ const stats = getOutboxStats();
36
+ const total = stats.pending + stats.delivered + stats.giving_up;
37
+ return [
38
+ `📬 outbox · 共 ${total}`,
39
+ ` ⏳ pending: ${stats.pending}`,
40
+ ` ✅ delivered: ${stats.delivered}`,
41
+ ` 💀 giving_up: ${stats.giving_up}`,
42
+ '',
43
+ `提示: /outbox list · /outbox failed · /outbox retry <id>`,
44
+ ].join('\n');
45
+ }
46
+ export async function handleOutboxCommand(args, _ctx) {
47
+ const parts = args.trim().split(/\s+/).filter(Boolean);
48
+ const sub = parts[0] || 'status';
49
+ switch (sub) {
50
+ case 'status':
51
+ case 's':
52
+ return fmtStatus();
53
+ case 'list':
54
+ case 'ls': {
55
+ const n = Math.max(1, Math.min(parseInt(parts[1] || '10', 10) || 10, 50));
56
+ const rows = listOutbox({ limit: n });
57
+ if (rows.length === 0)
58
+ return '📬 outbox 为空。';
59
+ return [`📬 outbox · 最近 ${rows.length} 条:`, '', ...rows.map(fmtRow)].join('\n');
60
+ }
61
+ case 'failed': {
62
+ const n = Math.max(1, Math.min(parseInt(parts[1] || '10', 10) || 10, 50));
63
+ const rows = listOutbox({ status: 'giving_up', limit: n });
64
+ if (rows.length === 0)
65
+ return '✅ 没有 giving_up 行。';
66
+ return [
67
+ `💀 outbox 失败列表 · ${rows.length} 条`,
68
+ '',
69
+ ...rows.map(fmtRow),
70
+ '',
71
+ `回执 /outbox retry <id> 可重新入队`,
72
+ ].join('\n');
73
+ }
74
+ case 'retry': {
75
+ const id = parseInt(parts[1] || '', 10);
76
+ if (!Number.isFinite(id) || id <= 0) {
77
+ return '❌ 用法: /outbox retry <id>';
78
+ }
79
+ const ok = retryGivingUp(id);
80
+ return ok
81
+ ? `✅ outbox #${id} 已重新入队 (attempts 重置)`
82
+ : `❌ outbox #${id} 不存在或不在 giving_up 状态`;
83
+ }
84
+ default:
85
+ return [
86
+ `❓ 未知子命令: ${sub}`,
87
+ '',
88
+ '可用: /outbox · /outbox list [N] · /outbox failed [N] · /outbox retry <id>',
89
+ ].join('\n');
90
+ }
91
+ }
92
+ //# sourceMappingURL=outbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../../src/core/commands/outbox.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,eAAe;AACf,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BACF,0EAA0E;aAC3E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC;AACH,CAAC"}
@@ -1,6 +1,23 @@
1
1
  import type Database from 'better-sqlite3';
2
2
  import type { Logger } from 'pino';
3
- export type JobStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
3
+ export type JobKind = 'job' | 'inline';
4
+ /** Lifecycle states.
5
+ * - pending : created, not yet picked up
6
+ * - running : agent currently executing
7
+ * - completed : agent finished, result captured; for inline kind the
8
+ * reply still has to go through the outbox before terminal
9
+ * 'delivered' (or 'failed' if the outbox gives up).
10
+ * - delivered : (inline only) reply confirmed sent via outbox.
11
+ * - failed : agent threw OR outbox gave up
12
+ * - cancelled : user-initiated cancel
13
+ * - interrupted : (Phase 3) running row was killed by agim shutdown — the
14
+ * startup scan offers the user a retry.
15
+ * - replaced : (Phase 3) interrupted row whose user picked "retry"; the
16
+ * new row's id lands in `replaced_by`.
17
+ * - abandoned : (Phase 3) interrupted row past the 10-minute window — no
18
+ * notification fired, archived for audit.
19
+ */
20
+ export type JobStatus = 'pending' | 'running' | 'completed' | 'delivered' | 'failed' | 'cancelled' | 'interrupted' | 'replaced' | 'abandoned';
4
21
  export interface Job {
5
22
  id: number;
6
23
  status: JobStatus;
@@ -14,8 +31,60 @@ export interface Job {
14
31
  creator_id: string;
15
32
  /** Workspace this job was created under, or '' if unknown. */
16
33
  workspace_id: string;
34
+ /** `${platform}:${channelId}:${threadId}` — empty for legacy / system rows. */
35
+ thread_key: string;
36
+ /** 'job' = explicit /job (30d retention), 'inline' = auto-tracked inbound
37
+ * message (24h retention + Phase 3 lifecycle hooks). */
38
+ kind: JobKind;
39
+ /** ISO when status first transitioned to 'running'. Null for never-run rows. */
40
+ started_at: string | null;
41
+ /** ISO when the outbox confirmed delivery to IM. Inline kind only. */
42
+ delivered_at: string | null;
43
+ /** Id of the new job that replaced this one (Phase 3 retry flow). */
44
+ replaced_by: number | null;
45
+ /** Last outbox row id that tried to deliver this job's result. Reverse
46
+ * link to `outbox.job_id`. */
47
+ last_outbox_id: number | null;
48
+ /** A2A-L1: id of the inline job whose agent invoked us via
49
+ * mcp__imhub__call_agent. NULL for user-originated rows. */
50
+ parent_id: number | null;
51
+ /** A2A-L1: how deep in the call chain this row sits. 0 = user;
52
+ * caller.call_depth + 1 for each A2A hop. Used to enforce
53
+ * IMHUB_A2A_MAX_DEPTH. */
54
+ call_depth: number;
17
55
  }
18
56
  type JobRunner = (job: Job, logger: Logger, signal: AbortSignal) => AsyncGenerator<string>;
57
+ /** Phase 3 — shutdown step. Mark every running inline job as 'interrupted'
58
+ * so the next startup can offer the user a retry. Returns the row count for
59
+ * logging. Safe to call on a degraded DB (returns 0). */
60
+ export declare function markRunningInlineJobsInterrupted(reason?: string): number;
61
+ /** Phase 3 — startup scan. Return interrupted inline jobs that finished
62
+ * within the recovery window (default 10 min via IMHUB_RECOVERY_WINDOW_MS).
63
+ * Caller iterates the result, sends a per-thread "retry / cancel" prompt,
64
+ * and tracks the user's reply via the in-memory pending-retry map.
65
+ *
66
+ * Older interrupted rows are NOT returned — they get swept to 'abandoned'
67
+ * by sweepAbandonedInterrupted() so they don't pile up in the table. */
68
+ export declare function findRecoverableInterrupted(windowMs?: number): Job[];
69
+ /** Phase 3 — startup sweep. Any 'interrupted' inline row past the recovery
70
+ * window transitions to 'abandoned' (preserved for audit but never
71
+ * notified). Returns the row count. */
72
+ export declare function sweepAbandonedInterrupted(windowMs?: number): number;
73
+ /** Phase 3 — link an old interrupted row to its replacement once the user
74
+ * picks "1 重发". The new row's id lands in `replaced_by`; the old row
75
+ * transitions interrupted → replaced so it stops showing up in any future
76
+ * recovery scan. */
77
+ export declare function markJobReplacedBy(oldId: number, newId: number): void;
78
+ /** Phase 3 — user picked "2 取消" on the retry prompt. Interrupted → cancelled. */
79
+ export declare function markInterruptedCancelled(id: number): void;
80
+ /** Exported for the recovery module so it can use the same window for the
81
+ * user-facing "10 min 内有效" copy. */
82
+ export declare function getRecoveryWindowMs(): number;
83
+ /** Test hook: artificially age a row's completed_at (or created_at) by a
84
+ * SQLite modifier like '-2 hours' or '-40 days'. Production code must NOT
85
+ * call this; it's the only practical way to exercise retention without
86
+ * sleeping in tests. */
87
+ export declare function _backdateForTests(id: number, modifier: string): void;
19
88
  /** Stop the retention sweep (used by tests + graceful shutdown). */
20
89
  export declare function stopJobRetentionSweep(): void;
21
90
  /** Close the underlying SQLite handle. Called by cli.ts on graceful
@@ -43,10 +112,62 @@ export interface OwnerOpts {
43
112
  export interface CreateJobOpts {
44
113
  creatorId?: string;
45
114
  workspaceId?: string;
115
+ /** 'job' (default) for explicit /job, 'inline' for cli auto-tracking. */
116
+ kind?: JobKind;
117
+ /** `${platform}:${channelId}:${threadId}` — required for inline kind so
118
+ * Phase 3 can route recovery notifications back to the originating IM
119
+ * thread. Optional for kind='job' (legacy CLI / scheduler callers). */
120
+ threadKey?: string;
121
+ /** A2A-L1: id of the inline job whose agent invoked this one. NULL on
122
+ * user-originated rows. */
123
+ parentId?: number | null;
124
+ /** A2A-L1: call depth (caller.call_depth + 1). 0 for user-originated. */
125
+ callDepth?: number;
46
126
  }
47
127
  export declare function createJob(agent: string, prompt: string, opts?: CreateJobOpts): number;
128
+ /** Inline-job convenience: same as createJob but never throws — returns -1
129
+ * when the board is disabled / locked. Caller is expected to log + carry
130
+ * on with the in-memory fast path. The whole tracking machinery short-
131
+ * circuits when env IMHUB_INLINE_JOB_TRACKING=0.
132
+ *
133
+ * parentId/callDepth are A2A-L1 hand-offs: when an agent tool-calls
134
+ * another agent via mcp__imhub__call_agent, the bus routes through here
135
+ * to record the parent/depth relationship. User-originated rows leave
136
+ * these undefined → NULL parent, depth=0. */
137
+ export declare function createInlineJob(opts: {
138
+ agent: string;
139
+ prompt: string;
140
+ threadKey: string;
141
+ creatorId?: string;
142
+ workspaceId?: string;
143
+ parentId?: number | null;
144
+ callDepth?: number;
145
+ }): number;
48
146
  export declare function getJob(id: number, opts?: OwnerOpts): Job | null;
49
147
  export declare function listJobs(limit?: number, status?: JobStatus, opts?: OwnerOpts): Job[];
148
+ /** Replace the agent column. Used by inline jobs: cli.ts creates the row with
149
+ * the default agent name before routing resolves the actual agent, then this
150
+ * fires inside onAgentResolved to correct the record. No-op when status is
151
+ * past 'running' so we don't rewrite history. */
152
+ export declare function updateJobAgent(id: number, agent: string): void;
153
+ /** pending → running. Stamps started_at. Idempotent: an already-running row
154
+ * keeps its original started_at. */
155
+ export declare function markJobRunning(id: number): void;
156
+ /** running → completed (result captured). For inline kind 'delivered' is the
157
+ * next hop, triggered by the outbox worker once the IM platform confirms.
158
+ * For 'job' kind this is the terminal success state (no delivery channel). */
159
+ export declare function markJobCompleted(id: number, result: string): void;
160
+ /** Link a job row to the outbox row that will (try to) deliver its result.
161
+ * Worker uses outbox.job_id to find this row; this column is the reverse
162
+ * link for /job inspection ("which outbox row carried this reply"). */
163
+ export declare function linkJobOutbox(id: number, outboxId: number): void;
164
+ /** completed → delivered. Called by the outbox worker after the IM platform
165
+ * ack. No-op if the row isn't in 'completed' (e.g. user cancelled meanwhile). */
166
+ export declare function markJobDelivered(id: number): void;
167
+ /** Terminal failure (agent threw, outbox gave up, etc.). Captures the error
168
+ * on the row. completed_at gets stamped so retention sweeps treat the row
169
+ * the same as a normal terminal state. */
170
+ export declare function markJobFailed(id: number, error: string): void;
50
171
  /**
51
172
  * Acquire a job slot. Returns immediately when capacity available, otherwise
52
173
  * queues the caller and returns a promise that resolves when a slot frees.
@@ -1 +1 @@
1
- {"version":3,"file":"job-board.d.ts","sourceRoot":"","sources":["../../src/core/job-board.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAE1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA+DlC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEpF,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE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