sidekick-shared 0.29.0 → 0.30.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 +48 -0
- package/README.md +198 -56
- package/dist/aggregation/EventAggregator.d.ts +96 -2
- package/dist/aggregation/EventAggregator.js +535 -42
- package/dist/aggregation/snapshot.d.ts +37 -8
- package/dist/aggregation/snapshot.js +31 -9
- package/dist/aggregation/types.d.ts +38 -1
- package/dist/browser.d.ts +9 -1
- package/dist/browser.js +29 -3
- package/dist/context/sessionContext.js +8 -0
- package/dist/esm/aggregation/EventAggregator.js +535 -42
- package/dist/esm/aggregation/snapshot.js +31 -9
- package/dist/esm/browser.js +3 -0
- package/dist/esm/context/sessionContext.js +8 -0
- package/dist/esm/fileContinuity.js +149 -0
- package/dist/esm/formatters/toolSummary.js +4 -1
- package/dist/esm/index.js +7 -2
- package/dist/esm/modelCatalog.js +5 -4
- package/dist/esm/modelContext.js +4 -3
- package/dist/esm/modelInfo.js +4 -3
- package/dist/esm/node.js +3 -1
- package/dist/esm/observedContextWindows.js +2 -1
- package/dist/esm/ownKey.js +26 -0
- package/dist/esm/parsers/codexParser.js +372 -7
- package/dist/esm/parsers/openCodeParser.js +2 -1
- package/dist/esm/parsers/subagentEndState.js +61 -0
- package/dist/esm/parsers/subagentScanner.js +37 -12
- package/dist/esm/parsers/subagentTraceParser.js +103 -37
- package/dist/esm/pricingCatalog.js +3 -2
- package/dist/esm/promptHistory.js +22 -11
- package/dist/esm/providers/claudeCode.js +60 -29
- package/dist/esm/providers/codex.js +235 -201
- package/dist/esm/providers/codexCompressedReader.js +184 -0
- package/dist/esm/providers/codexDatabase.js +47 -2
- package/dist/esm/providers/codexRollouts.js +20 -2
- package/dist/esm/providers/codexSubagents.js +456 -0
- package/dist/esm/providers/compressedRollouts.js +330 -0
- package/dist/esm/providers/factory.js +4 -1
- package/dist/esm/providers/rolloutWalker.js +32 -4
- package/dist/esm/schemas/sessionEvent.js +63 -14
- package/dist/esm/sessionMonitor.js +7 -1
- package/dist/esm/sessionPreviews.js +9 -0
- package/dist/esm/sessionPromptHistory.js +5 -3
- package/dist/esm/subagentActivity.js +125 -0
- package/dist/esm/subagentDisplayState.js +81 -0
- package/dist/esm/subagentSpawn.js +363 -0
- package/dist/esm/testing/codexSubagentFixtures.js +336 -0
- package/dist/esm/toolCallOrigins.js +17 -10
- package/dist/esm/toolCategory.js +6 -2
- package/dist/esm/transcript.js +8 -0
- package/dist/esm/turns/assistantTurn.js +6 -2
- package/dist/esm/usage/claudeUsageDedupe.js +68 -0
- package/dist/esm/usage/usageEvents.js +4 -1
- package/dist/esm/watchers/eventBridge.js +45 -0
- package/dist/esm/watchers/factory.js +5 -3
- package/dist/esm/watchers/jsonlTail.js +82 -48
- package/dist/esm/watchers/jsonlWatcher.js +61 -4
- package/dist/esm/watchers/providerReaderWatcher.js +18 -4
- package/dist/esm/zaiQuota.js +2 -1
- package/dist/fileContinuity.d.ts +95 -0
- package/dist/fileContinuity.js +187 -0
- package/dist/formatters/toolSummary.js +4 -1
- package/dist/index.d.ts +19 -7
- package/dist/index.js +48 -10
- package/dist/modelCatalog.js +5 -4
- package/dist/modelContext.js +4 -3
- package/dist/modelInfo.js +4 -3
- package/dist/node.d.ts +5 -1
- package/dist/node.js +18 -2
- package/dist/observedContextWindows.js +2 -1
- package/dist/ownKey.d.ts +16 -0
- package/dist/ownKey.js +30 -0
- package/dist/parsers/codexParser.d.ts +107 -0
- package/dist/parsers/codexParser.js +373 -7
- package/dist/parsers/openCodeParser.js +2 -1
- package/dist/parsers/subagentEndState.d.ts +20 -0
- package/dist/parsers/subagentEndState.js +65 -0
- package/dist/parsers/subagentScanner.d.ts +19 -6
- package/dist/parsers/subagentScanner.js +37 -12
- package/dist/parsers/subagentTraceParser.d.ts +33 -5
- package/dist/parsers/subagentTraceParser.js +103 -37
- package/dist/pricingCatalog.js +3 -2
- package/dist/promptHistory.d.ts +13 -3
- package/dist/promptHistory.js +22 -11
- package/dist/providers/claudeCode.js +59 -28
- package/dist/providers/codex.d.ts +35 -5
- package/dist/providers/codex.js +232 -198
- package/dist/providers/codexCompressedReader.d.ts +58 -0
- package/dist/providers/codexCompressedReader.js +221 -0
- package/dist/providers/codexDatabase.d.ts +25 -0
- package/dist/providers/codexDatabase.js +48 -2
- package/dist/providers/codexRollouts.d.ts +16 -2
- package/dist/providers/codexRollouts.js +20 -2
- package/dist/providers/codexSubagents.d.ts +66 -0
- package/dist/providers/codexSubagents.js +495 -0
- package/dist/providers/compressedRollouts.d.ts +114 -0
- package/dist/providers/compressedRollouts.js +380 -0
- package/dist/providers/factory.d.ts +5 -0
- package/dist/providers/factory.js +4 -1
- package/dist/providers/rolloutWalker.d.ts +15 -2
- package/dist/providers/rolloutWalker.js +33 -4
- package/dist/providers/types.d.ts +36 -1
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/sessionEvent.d.ts +51 -10
- package/dist/schemas/sessionEvent.js +63 -14
- package/dist/sessionMonitor.d.ts +6 -0
- package/dist/sessionMonitor.js +7 -1
- package/dist/sessionPreviews.js +9 -0
- package/dist/sessionPromptHistory.d.ts +5 -0
- package/dist/sessionPromptHistory.js +5 -36
- package/dist/subagentActivity.d.ts +91 -0
- package/dist/subagentActivity.js +132 -0
- package/dist/subagentDisplayState.d.ts +81 -0
- package/dist/subagentDisplayState.js +86 -0
- package/dist/subagentSpawn.d.ts +175 -0
- package/dist/subagentSpawn.js +385 -0
- package/dist/testing/codexSubagentFixtures.d.ts +48 -0
- package/dist/testing/codexSubagentFixtures.js +344 -0
- package/dist/toolCallOrigins.d.ts +5 -0
- package/dist/toolCallOrigins.js +17 -10
- package/dist/toolCategory.js +6 -2
- package/dist/transcript.js +8 -0
- package/dist/turns/assistantTurn.d.ts +4 -0
- package/dist/turns/assistantTurn.js +6 -2
- package/dist/types/codex.d.ts +71 -2
- package/dist/types/sessionEvent.d.ts +38 -3
- package/dist/usage/claudeUsageDedupe.d.ts +31 -0
- package/dist/usage/claudeUsageDedupe.js +68 -0
- package/dist/usage/usageEvents.d.ts +4 -1
- package/dist/usage/usageEvents.js +4 -1
- package/dist/watchers/eventBridge.js +45 -0
- package/dist/watchers/factory.d.ts +6 -0
- package/dist/watchers/factory.js +5 -3
- package/dist/watchers/jsonlTail.d.ts +27 -4
- package/dist/watchers/jsonlTail.js +84 -48
- package/dist/watchers/jsonlWatcher.d.ts +22 -1
- package/dist/watchers/jsonlWatcher.js +60 -3
- package/dist/watchers/providerReaderWatcher.d.ts +7 -0
- package/dist/watchers/providerReaderWatcher.js +18 -4
- package/dist/watchers/types.d.ts +12 -0
- package/dist/zaiQuota.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How to show a subagent: its lifecycle's outcome once something settled
|
|
3
|
+
* it, otherwise `running`, unless its transcript or its parent says it has
|
|
4
|
+
* stopped in all but name.
|
|
5
|
+
*
|
|
6
|
+
* Some background agents never get a final notification (they stopped after
|
|
7
|
+
* an interim "may resume" notice, the user stopped them from the UI, or a
|
|
8
|
+
* restart killed them). Their lifecycles stay `running`. This rule reads
|
|
9
|
+
* them as:
|
|
10
|
+
*
|
|
11
|
+
* - `finished-unreported`: the transcript ended cleanly (last assistant turn
|
|
12
|
+
* `end_turn` / `stop_sequence`, no tool call unanswered) and has been quiet
|
|
13
|
+
* for {@link SUBAGENT_UNREPORTED_QUIET_MS}.
|
|
14
|
+
* - `ended`: neither the parent session nor the transcript has been active for
|
|
15
|
+
* {@link SUBAGENT_PARENT_IDLE_ENDED_MS}.
|
|
16
|
+
*
|
|
17
|
+
* Neither is stored: the state is recomputed from the latest data on every
|
|
18
|
+
* call, so an agent that resumes (its transcript grows, or a later
|
|
19
|
+
* notification reopens its lifecycle) reads as `running` again. Silence alone
|
|
20
|
+
* is never enough for `finished-unreported`: live agents can be quiet for
|
|
21
|
+
* hours.
|
|
22
|
+
*
|
|
23
|
+
* Pure: no filesystem access. Browser-safe.
|
|
24
|
+
*
|
|
25
|
+
* @module subagentDisplayState
|
|
26
|
+
*/
|
|
27
|
+
import type { SubagentLifecycle } from './aggregation/types';
|
|
28
|
+
/** Quiet time after a clean end before a running agent reads as finished without a report (2 min). */
|
|
29
|
+
export declare const SUBAGENT_UNREPORTED_QUIET_MS: number;
|
|
30
|
+
/** Parent and transcript idle time after which a running agent reads as ended (6 h). */
|
|
31
|
+
export declare const SUBAGENT_PARENT_IDLE_ENDED_MS: number;
|
|
32
|
+
/** How a subagent is shown. The last four are lifecycle outcomes. */
|
|
33
|
+
export type SubagentDisplayStateName = 'running' | 'finished-unreported' | 'ended' | 'completed' | 'failed' | 'stopped' | 'killed';
|
|
34
|
+
/** Why a subagent reads as it does. */
|
|
35
|
+
export type SubagentDisplayReason =
|
|
36
|
+
/** Its lifecycle is settled; the state is the outcome. */
|
|
37
|
+
'settled'
|
|
38
|
+
/** Claude Code's meta flags (`finished`, `stoppedByUser`) on a running lifecycle. */
|
|
39
|
+
| 'meta'
|
|
40
|
+
/** The transcript ended cleanly and has been quiet. */
|
|
41
|
+
| 'clean-end'
|
|
42
|
+
/** The parent session (and the transcript) has been idle. */
|
|
43
|
+
| 'parent-idle';
|
|
44
|
+
export interface SubagentDisplayState {
|
|
45
|
+
state: SubagentDisplayStateName;
|
|
46
|
+
/** Absent for a plain `running`. */
|
|
47
|
+
reason?: SubagentDisplayReason;
|
|
48
|
+
}
|
|
49
|
+
/** The lifecycle fields the rule reads. */
|
|
50
|
+
export type SubagentDisplayLifecycle = Pick<SubagentLifecycle, 'status' | 'outcome'>;
|
|
51
|
+
/**
|
|
52
|
+
* Transcript facts the rule reads; a `SubagentTrace`, or a `SubagentStats`
|
|
53
|
+
* mapped with `lastActivityAt: stats.endTime`.
|
|
54
|
+
*/
|
|
55
|
+
export interface SubagentDisplayTrace {
|
|
56
|
+
/** The transcript ended cleanly (see `SubagentTrace.endedCleanly`). */
|
|
57
|
+
endedCleanly?: boolean;
|
|
58
|
+
/** Time of the transcript's last record. */
|
|
59
|
+
lastActivityAt?: Date | string | number;
|
|
60
|
+
/** Claude Code meta `finished`. */
|
|
61
|
+
finished?: boolean;
|
|
62
|
+
/** Claude Code meta `stoppedByUser`. */
|
|
63
|
+
stoppedByUser?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface SubagentDisplayOptions {
|
|
66
|
+
/** The current time (epoch ms or a Date). */
|
|
67
|
+
now: number | Date;
|
|
68
|
+
/** Time of the parent session's last event, when known. */
|
|
69
|
+
parentLastActivity?: Date | string | number | null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolves how to show a subagent (see the module docs). Settled lifecycles
|
|
73
|
+
* map to their outcome (`completed` when none is recorded). A running one is
|
|
74
|
+
* `stopped` / `completed` when its meta flags say so, `finished-unreported`
|
|
75
|
+
* after a clean end and {@link SUBAGENT_UNREPORTED_QUIET_MS} of quiet,
|
|
76
|
+
* `ended` when the parent and transcript have both been idle for longer than
|
|
77
|
+
* {@link SUBAGENT_PARENT_IDLE_ENDED_MS}, and `running` otherwise.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveSubagentDisplayState(lifecycle: SubagentDisplayLifecycle, trace: SubagentDisplayTrace | null | undefined, options: SubagentDisplayOptions): SubagentDisplayState;
|
|
80
|
+
/** A short label: `running`, `finished (no report)`, `ended`, `completed`, `failed`, `stopped`, `killed`. */
|
|
81
|
+
export declare function subagentDisplayLabel(state: SubagentDisplayStateName): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* How to show a subagent: its lifecycle's outcome once something settled
|
|
4
|
+
* it, otherwise `running`, unless its transcript or its parent says it has
|
|
5
|
+
* stopped in all but name.
|
|
6
|
+
*
|
|
7
|
+
* Some background agents never get a final notification (they stopped after
|
|
8
|
+
* an interim "may resume" notice, the user stopped them from the UI, or a
|
|
9
|
+
* restart killed them). Their lifecycles stay `running`. This rule reads
|
|
10
|
+
* them as:
|
|
11
|
+
*
|
|
12
|
+
* - `finished-unreported`: the transcript ended cleanly (last assistant turn
|
|
13
|
+
* `end_turn` / `stop_sequence`, no tool call unanswered) and has been quiet
|
|
14
|
+
* for {@link SUBAGENT_UNREPORTED_QUIET_MS}.
|
|
15
|
+
* - `ended`: neither the parent session nor the transcript has been active for
|
|
16
|
+
* {@link SUBAGENT_PARENT_IDLE_ENDED_MS}.
|
|
17
|
+
*
|
|
18
|
+
* Neither is stored: the state is recomputed from the latest data on every
|
|
19
|
+
* call, so an agent that resumes (its transcript grows, or a later
|
|
20
|
+
* notification reopens its lifecycle) reads as `running` again. Silence alone
|
|
21
|
+
* is never enough for `finished-unreported`: live agents can be quiet for
|
|
22
|
+
* hours.
|
|
23
|
+
*
|
|
24
|
+
* Pure: no filesystem access. Browser-safe.
|
|
25
|
+
*
|
|
26
|
+
* @module subagentDisplayState
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.SUBAGENT_PARENT_IDLE_ENDED_MS = exports.SUBAGENT_UNREPORTED_QUIET_MS = void 0;
|
|
30
|
+
exports.resolveSubagentDisplayState = resolveSubagentDisplayState;
|
|
31
|
+
exports.subagentDisplayLabel = subagentDisplayLabel;
|
|
32
|
+
/** Quiet time after a clean end before a running agent reads as finished without a report (2 min). */
|
|
33
|
+
exports.SUBAGENT_UNREPORTED_QUIET_MS = 2 * 60_000;
|
|
34
|
+
/** Parent and transcript idle time after which a running agent reads as ended (6 h). */
|
|
35
|
+
exports.SUBAGENT_PARENT_IDLE_ENDED_MS = 6 * 60 * 60_000;
|
|
36
|
+
function toMs(value) {
|
|
37
|
+
if (value === null || value === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
const ms = value instanceof Date ? value.getTime() : new Date(value).getTime();
|
|
40
|
+
return Number.isFinite(ms) ? ms : undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolves how to show a subagent (see the module docs). Settled lifecycles
|
|
44
|
+
* map to their outcome (`completed` when none is recorded). A running one is
|
|
45
|
+
* `stopped` / `completed` when its meta flags say so, `finished-unreported`
|
|
46
|
+
* after a clean end and {@link SUBAGENT_UNREPORTED_QUIET_MS} of quiet,
|
|
47
|
+
* `ended` when the parent and transcript have both been idle for longer than
|
|
48
|
+
* {@link SUBAGENT_PARENT_IDLE_ENDED_MS}, and `running` otherwise.
|
|
49
|
+
*/
|
|
50
|
+
function resolveSubagentDisplayState(lifecycle, trace, options) {
|
|
51
|
+
if (lifecycle.status !== 'running') {
|
|
52
|
+
return { state: lifecycle.outcome ?? 'completed', reason: 'settled' };
|
|
53
|
+
}
|
|
54
|
+
if (trace?.stoppedByUser)
|
|
55
|
+
return { state: 'stopped', reason: 'meta' };
|
|
56
|
+
if (trace?.finished)
|
|
57
|
+
return { state: 'completed', reason: 'meta' };
|
|
58
|
+
const now = toMs(options.now) ?? Date.now();
|
|
59
|
+
const lastActivity = toMs(trace?.lastActivityAt);
|
|
60
|
+
if (trace?.endedCleanly &&
|
|
61
|
+
lastActivity !== undefined &&
|
|
62
|
+
now - lastActivity >= exports.SUBAGENT_UNREPORTED_QUIET_MS) {
|
|
63
|
+
return { state: 'finished-unreported', reason: 'clean-end' };
|
|
64
|
+
}
|
|
65
|
+
const parentLast = toMs(options.parentLastActivity);
|
|
66
|
+
if (parentLast !== undefined) {
|
|
67
|
+
const latest = Math.max(parentLast, lastActivity ?? -Infinity);
|
|
68
|
+
if (now - latest > exports.SUBAGENT_PARENT_IDLE_ENDED_MS) {
|
|
69
|
+
return { state: 'ended', reason: 'parent-idle' };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { state: 'running' };
|
|
73
|
+
}
|
|
74
|
+
const LABELS = {
|
|
75
|
+
running: 'running',
|
|
76
|
+
'finished-unreported': 'finished (no report)',
|
|
77
|
+
ended: 'ended',
|
|
78
|
+
completed: 'completed',
|
|
79
|
+
failed: 'failed',
|
|
80
|
+
stopped: 'stopped',
|
|
81
|
+
killed: 'killed',
|
|
82
|
+
};
|
|
83
|
+
/** A short label: `running`, `finished (no report)`, `ended`, `completed`, `failed`, `stopped`, `killed`. */
|
|
84
|
+
function subagentDisplayLabel(state) {
|
|
85
|
+
return LABELS[state] ?? state;
|
|
86
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recognizes subagent spawns, background-task notifications, and the other
|
|
3
|
+
* records that settle a background agent.
|
|
4
|
+
*
|
|
5
|
+
* Claude Code's subagent tool is `Agent`; `Task` is its earlier name (and the
|
|
6
|
+
* name OpenCode's `task` tool is normalized to). A background agent's spawning
|
|
7
|
+
* tool call gets its result right away ("Async agent launched successfully.")
|
|
8
|
+
* and its completion arrives later as a `<task-notification>` block, delivered
|
|
9
|
+
* either as a user line or as a mid-turn `queued_command` attachment. When no
|
|
10
|
+
* notification comes, a `task_status` attachment, an `agents_killed` system
|
|
11
|
+
* line, or a plain-text "background agents were stopped by the user" notice
|
|
12
|
+
* can still say how it ended.
|
|
13
|
+
*
|
|
14
|
+
* Codex spawns with `spawn_agent` (parsed as `Spawn_agent`); its result
|
|
15
|
+
* (`{"task_name": "/root/x"}`) is always a background launch.
|
|
16
|
+
*
|
|
17
|
+
* Pure: no filesystem access, so it is safe for browser bundles.
|
|
18
|
+
*
|
|
19
|
+
* @module subagentSpawn
|
|
20
|
+
*/
|
|
21
|
+
import type { SubagentOutcome } from './aggregation/types';
|
|
22
|
+
import type { SessionEvent } from './types/sessionEvent';
|
|
23
|
+
/**
|
|
24
|
+
* Claude Code / OpenCode tool names that spawn a subagent: `Agent` (current)
|
|
25
|
+
* and `Task` (earlier name). Codex's `spawn_agent` is not in this list;
|
|
26
|
+
* {@link isSubagentSpawnTool} recognizes it as well.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SUBAGENT_SPAWN_TOOL_NAMES: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Whether a tool call is Codex's `spawn_agent`: by name (`Spawn_agent` as
|
|
31
|
+
* parsed, or the raw `spawn_agent`), or by the raw name the Codex parser keeps
|
|
32
|
+
* in the input (`_sidekickRawToolName`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function isCodexSubagentSpawnTool(name: string | null | undefined, input?: unknown): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a tool call spawns a subagent: one of
|
|
37
|
+
* {@link SUBAGENT_SPAWN_TOOL_NAMES} (`Agent`, `Task`), or Codex's
|
|
38
|
+
* `spawn_agent` (see {@link isCodexSubagentSpawnTool}; pass the call's input
|
|
39
|
+
* to also match on its raw name).
|
|
40
|
+
*/
|
|
41
|
+
export declare function isSubagentSpawnTool(name: string | null | undefined, input?: unknown): boolean;
|
|
42
|
+
/** A Codex `spawn_agent` result: the child was started in the background. */
|
|
43
|
+
export interface CodexSpawnLaunch {
|
|
44
|
+
/** The child's agent path (`task_name` in the result), e.g. `/root/review_builder`. */
|
|
45
|
+
agentPath?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Recognizes a Codex `spawn_agent` result (`{"task_name": "/root/x"}`, as a
|
|
49
|
+
* JSON string or object). `null` for anything else.
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseCodexSpawnLaunch(result: unknown): CodexSpawnLaunch | null;
|
|
52
|
+
/** A spawning tool result that launched the agent in the background. */
|
|
53
|
+
export interface AsyncAgentLaunch {
|
|
54
|
+
/** The agent id Claude Code reported (`agentId: <id>`), when present. */
|
|
55
|
+
agentId?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Plain text of tool-result or message content: a string as-is, or the text
|
|
59
|
+
* blocks of a content array joined by newlines.
|
|
60
|
+
*/
|
|
61
|
+
export declare function contentText(content: unknown): string;
|
|
62
|
+
/**
|
|
63
|
+
* Recognizes the immediate result of a background spawn
|
|
64
|
+
* (`Async agent launched successfully.` … `agentId: <id> …`). Accepts the
|
|
65
|
+
* result text or the raw tool-result content. Returns `null` for anything
|
|
66
|
+
* else, including a finished foreground agent's result.
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseAsyncAgentLaunch(result: unknown): AsyncAgentLaunch | null;
|
|
69
|
+
/** Fields of a `<task-notification>` block. */
|
|
70
|
+
export interface TaskNotification {
|
|
71
|
+
/** `<task-id>`: the background agent's id (or a background shell task's id). */
|
|
72
|
+
taskId: string;
|
|
73
|
+
/** `<tool-use-id>`: the tool call that started the background work. */
|
|
74
|
+
toolUseId?: string;
|
|
75
|
+
/** `<status>` as written, e.g. `completed`, `failed`, `killed`, `stopped`. */
|
|
76
|
+
status?: string;
|
|
77
|
+
/** `<summary>`, e.g. `Agent "Explore auth" finished`. */
|
|
78
|
+
summary?: string;
|
|
79
|
+
/**
|
|
80
|
+
* The agent stopped while background work of its own is still running; it
|
|
81
|
+
* may resume, and the same task id notifies again.
|
|
82
|
+
*/
|
|
83
|
+
interim: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parses the first `<task-notification>` block in `text`. Whitespace and
|
|
87
|
+
* newlines between tags, missing fields, and unknown extra fields are
|
|
88
|
+
* tolerated; the block needs a `<task-id>`. Fields are read before the
|
|
89
|
+
* agent's own `<result>` output, which may quote anything.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseTaskNotification(text: unknown): TaskNotification | null;
|
|
92
|
+
/**
|
|
93
|
+
* The `<task-notification>` prompt of a raw Claude Code attachment line
|
|
94
|
+
* (`{ type: 'attachment', attachment: { type: 'queued_command', commandMode:
|
|
95
|
+
* 'task-notification', prompt } }`), which is how a notification that lands
|
|
96
|
+
* mid-turn is recorded. `null` for any other value.
|
|
97
|
+
*/
|
|
98
|
+
export declare function taskNotificationPromptFromAttachment(raw: unknown): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* The synthetic `system` event `extractSessionEvents(raw, {
|
|
101
|
+
* includeTaskNotifications: true })` makes from a mid-turn task-notification
|
|
102
|
+
* attachment. It is bookkeeping, not a message or a prompt.
|
|
103
|
+
*/
|
|
104
|
+
export declare function isTaskNotificationSystemEvent(event: SessionEvent): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* The task notification an event carries: a user line with
|
|
107
|
+
* `origin.kind === 'task-notification'` or whose text starts with
|
|
108
|
+
* `<task-notification>`, or the opt-in synthetic system event. `null` otherwise.
|
|
109
|
+
*/
|
|
110
|
+
export declare function taskNotificationFromEvent(event: SessionEvent): TaskNotification | null;
|
|
111
|
+
/** Maps a notification `<status>` to an outcome; unknown or missing statuses read as `completed`. */
|
|
112
|
+
export declare function taskNotificationOutcome(status: string | undefined): SubagentOutcome;
|
|
113
|
+
/** A plain-text notice that the user stopped background agents. */
|
|
114
|
+
export interface AgentsStoppedNotice {
|
|
115
|
+
/** The stopped agents' descriptions, as the notice quotes them. */
|
|
116
|
+
descriptions: string[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parses Claude Code's plain-text notice that the user stopped background
|
|
120
|
+
* agents: `2 background agents were stopped by the user: "A", "B".` (a
|
|
121
|
+
* `queued_command` attachment's prompt) or `Background agent "A" was stopped
|
|
122
|
+
* by the user.` (a queue-operation line). `null` for any other text.
|
|
123
|
+
*/
|
|
124
|
+
export declare function parseAgentsStoppedNotice(text: unknown): AgentsStoppedNotice | null;
|
|
125
|
+
/**
|
|
126
|
+
* The stop notice a task-notification event carries (a `queued_command`
|
|
127
|
+
* prompt that is plain text, not a `<task-notification>` block). `null`
|
|
128
|
+
* otherwise.
|
|
129
|
+
*/
|
|
130
|
+
export declare function agentsStoppedNoticeFromEvent(event: SessionEvent): AgentsStoppedNotice | null;
|
|
131
|
+
/** Claude Code's `agents_killed` system line: the user killed every running background agent. */
|
|
132
|
+
export declare const AGENTS_KILLED_SUBTYPE = "agents_killed";
|
|
133
|
+
/**
|
|
134
|
+
* Whether an event, or a raw Claude Code JSONL line, is an `agents_killed`
|
|
135
|
+
* system line (`{ type: 'system', subtype: 'agents_killed' }`).
|
|
136
|
+
*/
|
|
137
|
+
export declare function isAgentsKilledSystemEvent(event: unknown): boolean;
|
|
138
|
+
/** A background agent's status from a Claude Code `task_status` attachment. */
|
|
139
|
+
export interface SubagentTaskStatus {
|
|
140
|
+
/** The background agent's id. */
|
|
141
|
+
taskId: string;
|
|
142
|
+
/** `local_agent` for background agents. */
|
|
143
|
+
taskType: string;
|
|
144
|
+
/** As written: `running`, `completed`, `failed`, `killed`, `stopped`, … */
|
|
145
|
+
status: string;
|
|
146
|
+
description?: string;
|
|
147
|
+
}
|
|
148
|
+
/** `origin.kind` of the opt-in `system` event made from a `task_status` attachment. */
|
|
149
|
+
export declare const TASK_STATUS_ORIGIN_KIND = "task-status";
|
|
150
|
+
/** `type` of the content block that carries the status. */
|
|
151
|
+
export declare const TASK_STATUS_BLOCK_TYPE = "task_status";
|
|
152
|
+
/**
|
|
153
|
+
* The background agent's status a raw Claude Code `task_status` attachment
|
|
154
|
+
* line reports (`{ type: 'attachment', attachment: { type: 'task_status',
|
|
155
|
+
* taskId, taskType: 'local_agent', status, description } }`). `null` for any
|
|
156
|
+
* other value, including background shell tasks (`local_bash`).
|
|
157
|
+
*/
|
|
158
|
+
export declare function taskStatusFromAttachment(raw: unknown): SubagentTaskStatus | null;
|
|
159
|
+
/** Whether a task status is final (anything but `running` / `pending`). */
|
|
160
|
+
export declare function isFinalTaskStatus(status: string | undefined): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* The synthetic `system` event `extractSessionEvents(raw, {
|
|
163
|
+
* includeTaskNotifications: true })` makes from a background agent's
|
|
164
|
+
* `task_status` attachment. It is bookkeeping, not a message or a prompt.
|
|
165
|
+
*/
|
|
166
|
+
export declare function isTaskStatusSystemEvent(event: SessionEvent): boolean;
|
|
167
|
+
/** The status an opt-in task-status `system` event carries; `null` for any other event. */
|
|
168
|
+
export declare function taskStatusFromEvent(event: SessionEvent): SubagentTaskStatus | null;
|
|
169
|
+
/**
|
|
170
|
+
* A one-line description of a stop: `Background agents stopped by the user (2)`,
|
|
171
|
+
* or, for an `agents_killed` line (`null`), `Background agents stopped by the user`.
|
|
172
|
+
*/
|
|
173
|
+
export declare function describeAgentsStopped(notice: AgentsStoppedNotice | null): string;
|
|
174
|
+
/** A one-line description of a task status, e.g. `Background agent "Explore auth" completed`. */
|
|
175
|
+
export declare function describeTaskStatus(status: SubagentTaskStatus): string;
|