agent-afk 5.341.0 → 5.343.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 (43) hide show
  1. package/dist/agent/effect-ledger/store.d.ts +7 -0
  2. package/dist/agent/episodes/extract.d.ts +2 -0
  3. package/dist/agent/episodes/index.d.ts +6 -0
  4. package/dist/agent/episodes/session-end-hook.d.ts +2 -0
  5. package/dist/agent/episodes/synthesize.d.ts +2 -0
  6. package/dist/agent/episodes/types.d.ts +24 -0
  7. package/dist/agent/episodes/writer.d.ts +4 -0
  8. package/dist/agent/facets/derive.aggregate.d.ts +1 -0
  9. package/dist/agent/facets/journal-adapter.d.ts +1 -0
  10. package/dist/agent/outcomes/commit-survival-artifacts.d.ts +6 -0
  11. package/dist/agent/outcomes/compute-outcomes.d.ts +21 -0
  12. package/dist/agent/outcomes/git-range.d.ts +6 -0
  13. package/dist/agent/outcomes/index.d.ts +5 -0
  14. package/dist/agent/outcomes/outcomes-input.d.ts +22 -0
  15. package/dist/agent/outcomes/outcomes-ledger.d.ts +13 -0
  16. package/dist/agent/outcomes/outcomes-v1.schema.d.ts +93 -0
  17. package/dist/agent/outcomes/schema.d.ts +47 -0
  18. package/dist/agent/outcomes/session-end-hook.d.ts +3 -0
  19. package/dist/agent/outcomes/session-outcomes.d.ts +9 -0
  20. package/dist/agent/provider.d.ts +0 -5
  21. package/dist/agent/providers/anthropic-direct/query/cwd-dependents.d.ts +1 -0
  22. package/dist/agent/providers/anthropic-direct/query-runtime.d.ts +0 -5
  23. package/dist/agent/providers/openai-compatible/index.d.ts +2 -1
  24. package/dist/agent/providers/openai-compatible/index.options.d.ts +1 -0
  25. package/dist/agent/providers/openai-compatible/provider-schemas.d.ts +3 -0
  26. package/dist/agent/providers/router/provider-router.d.ts +0 -5
  27. package/dist/agent/session/agent-session.d.ts +0 -5
  28. package/dist/agent/session/ledger-lifecycle.d.ts +6 -0
  29. package/dist/agent/session/session-config.d.ts +0 -5
  30. package/dist/agent/session/session-meta.d.ts +8 -0
  31. package/dist/agent/trace/receipt.d.ts +4 -76
  32. package/dist/agent/trace/receipt.types.d.ts +79 -0
  33. package/dist/bundled-plugins/awa-bundled/skills/consumer-map/SKILL.md +154 -0
  34. package/dist/bundled-plugins/awa-bundled/skills/devils-advocate/SKILL.md +12 -0
  35. package/dist/bundled-plugins/awa-bundled/skills/ground-state/SKILL.md +8 -11
  36. package/dist/cli/commands/episode.d.ts +2 -0
  37. package/dist/cli.mjs +532 -497
  38. package/dist/config/env.d.ts +8 -0
  39. package/dist/config/env.episode.d.ts +9 -0
  40. package/dist/index.mjs +368 -368
  41. package/dist/telegram.mjs +435 -410
  42. package/package.json +1 -1
  43. package/dist/cli/slash/commands/reauth.d.ts +0 -2
@@ -1,3 +1,4 @@
1
+ import { type InputBudget } from '../outcomes/outcomes-input.js';
1
2
  import type { EffectRecord, EffectQuery, PendingEffectInput, ExecuteEffectInput } from './types.js';
2
3
  export declare class EffectStore {
3
4
  private readonly path;
@@ -12,3 +13,9 @@ export declare class EffectStore {
12
13
  query(filters?: EffectQuery): Promise<EffectRecord[]>;
13
14
  all(): Promise<EffectRecord[]>;
14
15
  }
16
+ export interface ReadEffectsForSessionOptions {
17
+ path?: string;
18
+ maxRecords?: number;
19
+ budget?: InputBudget;
20
+ }
21
+ export declare function readEffectsForSession(sessionId: string, opts?: ReadEffectsForSessionOptions): Promise<EffectRecord[]>;
@@ -0,0 +1,2 @@
1
+ import type { EpisodeInput } from './types.js';
2
+ export declare function extractEpisodeInput(sessionId: string): EpisodeInput;
@@ -0,0 +1,6 @@
1
+ export type { EpisodeRecord, EpisodeInput } from './types.js';
2
+ export { extractEpisodeInput } from './extract.js';
3
+ export { synthesizeEpisode } from './synthesize.js';
4
+ export { writeEpisode, formatEpisodeContent, sanitizeNarrative } from './writer.js';
5
+ import type { EpisodeRecord } from './types.js';
6
+ export declare function synthesizeAndWriteEpisode(sessionId: string): Promise<EpisodeRecord>;
@@ -0,0 +1,2 @@
1
+ import type { HookHandler } from '../hooks.js';
2
+ export declare function createEpisodeSessionEndHook(): HookHandler;
@@ -0,0 +1,2 @@
1
+ import type { EpisodeInput, EpisodeRecord } from './types.js';
2
+ export declare function synthesizeEpisode(input: EpisodeInput): Promise<EpisodeRecord>;
@@ -0,0 +1,24 @@
1
+ export interface EpisodeRecord {
2
+ sessionId: string;
3
+ goal: string;
4
+ approach: string;
5
+ pivots: string[];
6
+ decisions: string[];
7
+ outcome: string;
8
+ openQuestions: string[];
9
+ filesKey: string[];
10
+ tags: string[];
11
+ narrative: string;
12
+ synthesizedAt: string;
13
+ }
14
+ export interface EpisodeInput {
15
+ sessionId: string;
16
+ firstUserMessage: string;
17
+ markSequence: string[];
18
+ toolsUsed: string[];
19
+ toolErrors: string[];
20
+ lastAssistantMessage: string;
21
+ facetSummary?: string;
22
+ durationMs?: number;
23
+ costUsd?: number;
24
+ }
@@ -0,0 +1,4 @@
1
+ import type { EpisodeRecord } from './types.js';
2
+ export declare function sanitizeNarrative(text: string): string;
3
+ export declare function formatEpisodeContent(episode: EpisodeRecord): string;
4
+ export declare function writeEpisode(episode: EpisodeRecord, memoryDir?: string): Promise<void>;
@@ -2,6 +2,7 @@ import { type SubagentInvocation, type ToolEventInput } from './schema.js';
2
2
  export declare const EVIDENCE_CAP = 50;
3
3
  export declare function parseInput(input: string | undefined): Record<string, unknown> | undefined;
4
4
  export declare function asString(v: unknown): string | undefined;
5
+ export declare function patchApplyPaths(parsed: Record<string, unknown> | undefined): string[];
5
6
  export declare function dedupeToolEvents(events: ToolEventInput[]): ToolEventInput[];
6
7
  export interface AggregateToolEventsResult {
7
8
  toolCounts: Record<string, number>;
@@ -2,6 +2,7 @@ import type { SubagentToolSummary, ToolEventInput } from './schema.js';
2
2
  import type { JournalRecord } from '../journal/types.js';
3
3
  export interface JournalAdapterOptions {
4
4
  resultTextCap?: number;
5
+ checkBudget?: () => void;
5
6
  }
6
7
  export declare function journalRecordsToToolEvents(records: readonly JournalRecord[], options?: JournalAdapterOptions): ToolEventInput[];
7
8
  export declare function summarizeSubagentJournal(subagentId: string, records: readonly JournalRecord[]): SubagentToolSummary;
@@ -0,0 +1,6 @@
1
+ import type { Artifacts, Vote } from './schema.js';
2
+ import { type CheckAncestor, type CheckRevert } from './lf-delayed.js';
3
+ export declare function commitSurvivalForArtifacts(artifacts: Artifacts, deps: {
4
+ checkAncestor: CheckAncestor;
5
+ checkRevert: CheckRevert;
6
+ }, now: string): Promise<Vote[]>;
@@ -0,0 +1,21 @@
1
+ import type { EffectRecord } from '../effect-ledger/types.js';
2
+ import type { ToolEventInput } from '../facets/schema.js';
3
+ import { type OutcomeCommit, type OutcomeSchedule, type OutcomesV1 } from './outcomes-v1.schema.js';
4
+ export interface GitLogEntry {
5
+ sha: string;
6
+ subject: string;
7
+ repo: string;
8
+ }
9
+ export interface ComputeOutcomesInput {
10
+ cwd: string;
11
+ startHead: string | null;
12
+ endHead: string | null;
13
+ gitLog?: readonly GitLogEntry[];
14
+ ledgerEntries: readonly (EffectRecord | unknown)[];
15
+ toolEvents: readonly ToolEventInput[];
16
+ lastAssistantMessage: string | null;
17
+ }
18
+ export declare function mergeCommits(gitLog: readonly OutcomeCommit[], ledger: readonly OutcomeCommit[]): OutcomeCommit[];
19
+ export declare function filesFromToolEvents(events: readonly ToolEventInput[], cwd: string): string[];
20
+ export declare function schedulesFromToolEvents(events: readonly ToolEventInput[]): OutcomeSchedule[];
21
+ export declare function computeOutcomes(input: ComputeOutcomesInput): OutcomesV1;
@@ -0,0 +1,6 @@
1
+ import type { GitLogEntry } from './compute-outcomes.js';
2
+ export interface GitLogRangeOptions {
3
+ timeoutMs?: number;
4
+ signal?: AbortSignal;
5
+ }
6
+ export declare function gitLogRange(cwd: string, startHead: string | null, endHead: string | null, opts?: GitLogRangeOptions): Promise<GitLogEntry[]>;
@@ -5,3 +5,8 @@ export { lfPrFate, lfCommitSurvival } from './lf-delayed.js';
5
5
  export { combine } from './combine.js';
6
6
  export { createOutcomeSessionEndHook } from './session-end-hook.js';
7
7
  export { createChildAttributionHook } from './child-attribution.js';
8
+ export { computeOutcomes } from './compute-outcomes.js';
9
+ export type { ComputeOutcomesInput, GitLogEntry } from './compute-outcomes.js';
10
+ export { gitLogRange } from './git-range.js';
11
+ export { OutcomesV1Schema } from './outcomes-v1.schema.js';
12
+ export type { OutcomesV1 } from './outcomes-v1.schema.js';
@@ -0,0 +1,22 @@
1
+ import type { SessionMeta } from '../session/session-meta.js';
2
+ export interface InputBudget {
3
+ signal: AbortSignal;
4
+ deadline: number;
5
+ }
6
+ export declare function checkBudget(budget: InputBudget): void;
7
+ export declare function boundedLines(path: string, budget: InputBudget, maxBytes?: number): AsyncGenerator<string>;
8
+ export declare function readOutcomesMeta(sessionId: string, budget: InputBudget): Promise<SessionMeta | null>;
9
+ export declare function readOutcomesJournal(sessionId: string, budget: InputBudget): Promise<{
10
+ toolEvents: {
11
+ [x: string]: unknown;
12
+ toolName: string;
13
+ toolUseId?: string | undefined;
14
+ input?: string | undefined;
15
+ inputRaw?: string | undefined;
16
+ result?: string | undefined;
17
+ isError?: boolean | undefined;
18
+ incomplete?: boolean | undefined;
19
+ partialNodeCount?: number | undefined;
20
+ }[];
21
+ lastAssistantMessage: string | null;
22
+ }>;
@@ -0,0 +1,13 @@
1
+ import type { OutcomeCommit, OutcomePr, OutcomeService, PrAction } from './outcomes-v1.schema.js';
2
+ interface LedgerEffect {
3
+ command: string;
4
+ result: string;
5
+ }
6
+ export declare function settledEffects(entries: readonly unknown[]): LedgerEffect[];
7
+ export declare function repoFromCommand(command: string, cwd: string): string;
8
+ export declare function ledgerCommits(effects: readonly LedgerEffect[], cwd: string): OutcomeCommit[];
9
+ export declare function prActionFromCommand(command: string): PrAction;
10
+ export declare function addPr(list: OutcomePr[], pr: OutcomePr): void;
11
+ export declare function ledgerPrs(effects: readonly LedgerEffect[]): OutcomePr[];
12
+ export declare function ledgerServices(effects: readonly LedgerEffect[]): OutcomeService[];
13
+ export {};
@@ -0,0 +1,93 @@
1
+ import { z } from 'zod';
2
+ export declare const OUTCOMES_COMMITS_CAP = 200;
3
+ export declare const OUTCOMES_PRS_CAP = 50;
4
+ export declare const OUTCOMES_FILES_CAP = 500;
5
+ export declare const ShaSchema: z.ZodString;
6
+ export declare const OutcomeCommitSchema: z.ZodObject<{
7
+ sha: z.ZodString;
8
+ repo: z.ZodString;
9
+ subject: z.ZodString;
10
+ source: z.ZodEnum<{
11
+ tool_result: "tool_result";
12
+ git_log: "git_log";
13
+ effect_ledger: "effect_ledger";
14
+ }>;
15
+ }, z.core.$strip>;
16
+ export type OutcomeCommit = z.infer<typeof OutcomeCommitSchema>;
17
+ export declare const PrActionSchema: z.ZodEnum<{
18
+ unknown: "unknown";
19
+ create: "create";
20
+ merge: "merge";
21
+ update: "update";
22
+ }>;
23
+ export type PrAction = z.infer<typeof PrActionSchema>;
24
+ export declare const OutcomePrSchema: z.ZodObject<{
25
+ url: z.ZodString;
26
+ action: z.ZodEnum<{
27
+ unknown: "unknown";
28
+ create: "create";
29
+ merge: "merge";
30
+ update: "update";
31
+ }>;
32
+ }, z.core.$strip>;
33
+ export type OutcomePr = z.infer<typeof OutcomePrSchema>;
34
+ export declare const OutcomeScheduleSchema: z.ZodObject<{
35
+ id: z.ZodString;
36
+ action: z.ZodEnum<{
37
+ cancel: "cancel";
38
+ create: "create";
39
+ update: "update";
40
+ }>;
41
+ }, z.core.$strip>;
42
+ export type OutcomeSchedule = z.infer<typeof OutcomeScheduleSchema>;
43
+ export declare const OutcomeServiceSchema: z.ZodObject<{
44
+ name: z.ZodString;
45
+ action: z.ZodString;
46
+ }, z.core.$strip>;
47
+ export type OutcomeService = z.infer<typeof OutcomeServiceSchema>;
48
+ export declare const OutcomesV1Schema: z.ZodObject<{
49
+ schemaVersion: z.ZodLiteral<1>;
50
+ cwd: z.ZodString;
51
+ startHead: z.ZodNullable<z.ZodString>;
52
+ endHead: z.ZodNullable<z.ZodString>;
53
+ commits: z.ZodArray<z.ZodObject<{
54
+ sha: z.ZodString;
55
+ repo: z.ZodString;
56
+ subject: z.ZodString;
57
+ source: z.ZodEnum<{
58
+ tool_result: "tool_result";
59
+ git_log: "git_log";
60
+ effect_ledger: "effect_ledger";
61
+ }>;
62
+ }, z.core.$strip>>;
63
+ prs: z.ZodArray<z.ZodObject<{
64
+ url: z.ZodString;
65
+ action: z.ZodEnum<{
66
+ unknown: "unknown";
67
+ create: "create";
68
+ merge: "merge";
69
+ update: "update";
70
+ }>;
71
+ }, z.core.$strip>>;
72
+ filesChanged: z.ZodArray<z.ZodString>;
73
+ filesChangedTruncated: z.ZodBoolean;
74
+ schedules: z.ZodArray<z.ZodObject<{
75
+ id: z.ZodString;
76
+ action: z.ZodEnum<{
77
+ cancel: "cancel";
78
+ create: "create";
79
+ update: "update";
80
+ }>;
81
+ }, z.core.$strip>>;
82
+ services: z.ZodArray<z.ZodObject<{
83
+ name: z.ZodString;
84
+ action: z.ZodString;
85
+ }, z.core.$strip>>;
86
+ terminalState: z.ZodNullable<z.ZodEnum<{
87
+ blocked: "blocked";
88
+ done: "done";
89
+ interrupted: "interrupted";
90
+ asking: "asking";
91
+ }>>;
92
+ }, z.core.$strip>;
93
+ export type OutcomesV1 = z.infer<typeof OutcomesV1Schema>;
@@ -31,6 +31,7 @@ export declare const ArtifactsSchema: z.ZodObject<{
31
31
  commits: z.ZodArray<z.ZodString>;
32
32
  prs: z.ZodArray<z.ZodString>;
33
33
  repo: z.ZodNullable<z.ZodString>;
34
+ commitRepos: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
34
35
  }, z.core.$strip>;
35
36
  export type Artifacts = z.infer<typeof ArtifactsSchema>;
36
37
  export declare const VerifiedOutcomeSchema: z.ZodObject<{
@@ -64,6 +65,7 @@ export declare const VerifiedOutcomeSchema: z.ZodObject<{
64
65
  commits: z.ZodArray<z.ZodString>;
65
66
  prs: z.ZodArray<z.ZodString>;
66
67
  repo: z.ZodNullable<z.ZodString>;
68
+ commitRepos: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
67
69
  }, z.core.$strip>;
68
70
  votes: z.ZodArray<z.ZodObject<{
69
71
  lf: z.ZodString;
@@ -98,6 +100,51 @@ export declare const VerifiedOutcomeSchema: z.ZodObject<{
98
100
  normal: "normal";
99
101
  }>>;
100
102
  session_ended_at: z.ZodOptional<z.ZodString>;
103
+ outcomes: z.ZodOptional<z.ZodNullable<z.ZodObject<{
104
+ schemaVersion: z.ZodLiteral<1>;
105
+ cwd: z.ZodString;
106
+ startHead: z.ZodNullable<z.ZodString>;
107
+ endHead: z.ZodNullable<z.ZodString>;
108
+ commits: z.ZodArray<z.ZodObject<{
109
+ sha: z.ZodString;
110
+ repo: z.ZodString;
111
+ subject: z.ZodString;
112
+ source: z.ZodEnum<{
113
+ tool_result: "tool_result";
114
+ git_log: "git_log";
115
+ effect_ledger: "effect_ledger";
116
+ }>;
117
+ }, z.core.$strip>>;
118
+ prs: z.ZodArray<z.ZodObject<{
119
+ url: z.ZodString;
120
+ action: z.ZodEnum<{
121
+ unknown: "unknown";
122
+ create: "create";
123
+ merge: "merge";
124
+ update: "update";
125
+ }>;
126
+ }, z.core.$strip>>;
127
+ filesChanged: z.ZodArray<z.ZodString>;
128
+ filesChangedTruncated: z.ZodBoolean;
129
+ schedules: z.ZodArray<z.ZodObject<{
130
+ id: z.ZodString;
131
+ action: z.ZodEnum<{
132
+ cancel: "cancel";
133
+ create: "create";
134
+ update: "update";
135
+ }>;
136
+ }, z.core.$strip>>;
137
+ services: z.ZodArray<z.ZodObject<{
138
+ name: z.ZodString;
139
+ action: z.ZodString;
140
+ }, z.core.$strip>>;
141
+ terminalState: z.ZodNullable<z.ZodEnum<{
142
+ blocked: "blocked";
143
+ done: "done";
144
+ interrupted: "interrupted";
145
+ asking: "asking";
146
+ }>>;
147
+ }, z.core.$strip>>>;
101
148
  }, z.core.$strip>;
102
149
  export type VerifiedOutcome = z.infer<typeof VerifiedOutcomeSchema>;
103
150
  export type OutcomeLabel = VerifiedOutcome['label'];
@@ -1,2 +1,5 @@
1
1
  import type { HookHandler } from '../hooks.js';
2
+ import type { OutcomesV1 } from './outcomes-v1.schema.js';
3
+ import type { Artifacts } from './schema.js';
2
4
  export declare function createOutcomeSessionEndHook(): HookHandler;
5
+ export declare function artifactsFromOutcomes(o: OutcomesV1): Artifacts;
@@ -0,0 +1,9 @@
1
+ import { type OutcomesV1 } from './outcomes-v1.schema.js';
2
+ export interface SessionOutcomesContext {
3
+ cwd?: string;
4
+ }
5
+ export declare function _resetSessionOutcomesCache(): void;
6
+ export declare function readEndHead(cwd: string, signal?: AbortSignal): Promise<string | null>;
7
+ export declare function getSessionOutcomes(sessionId: string, ctx?: SessionOutcomesContext, opts?: {
8
+ timeoutMs?: number;
9
+ }): Promise<OutcomesV1 | null>;
@@ -194,11 +194,6 @@ export interface ProviderQuery extends AsyncIterable<ProviderEvent> {
194
194
  setBeforeTurnEnd?(cb: ((continuation: number, assistantText?: string) => Promise<{
195
195
  continueWith?: string;
196
196
  } | undefined>) | undefined): void;
197
- reauth?(): Promise<{
198
- accountId: string;
199
- oldAccountId: string;
200
- swapped: boolean;
201
- } | null>;
202
197
  close(): void | Promise<void>;
203
198
  }
204
199
  export interface ProviderCommandInfo {
@@ -12,6 +12,7 @@ export type CwdDependentsFactory = (newCwd: string) => {
12
12
  export interface CwdDependentsFactoryArgs {
13
13
  stableSystemPrefix: StableSystemParts;
14
14
  config: AgentConfig;
15
+ resolvedSessionId: string | undefined;
15
16
  surface: string;
16
17
  runtimeStateSource: RuntimeStateSource;
17
18
  getCurrentCwd: () => string | undefined;
@@ -57,11 +57,6 @@ export declare class AnthropicDirectQuery implements ProviderQuery {
57
57
  getContextUsage(): Promise<ProviderContextUsage>;
58
58
  mcpServerStatus(): Promise<ProviderMcpServerStatus[]>;
59
59
  accountInfo(): Promise<ProviderAccountInfo>;
60
- reauth(): Promise<{
61
- accountId: string;
62
- oldAccountId: string;
63
- swapped: boolean;
64
- } | null>;
65
60
  rewindFiles(userMessageId: string, options?: {
66
61
  dryRun?: boolean;
67
62
  }): Promise<ProviderRewindResult>;
@@ -9,7 +9,7 @@ export declare class OpenAICompatibleProvider implements ModelProvider {
9
9
  private _stateStore;
10
10
  private readonly _injectedMemoryStore;
11
11
  private readonly _injectedStateStore;
12
- private readonly schemas;
12
+ private schemas;
13
13
  private _defaultHeaders;
14
14
  private _sharedReadRoots;
15
15
  private _sharedWriteRoots;
@@ -23,6 +23,7 @@ export declare class OpenAICompatibleProvider implements ModelProvider {
23
23
  baseURL?: string;
24
24
  defaultHeaders?: Record<string, string>;
25
25
  }): void;
26
+ setSubscribeHandler(handler: import('../../tools/types.js').ToolHandler): void;
26
27
  query(args: ProviderQueryArgs): ProviderQuery;
27
28
  private buildDispatcher;
28
29
  private ensureSharedRoots;
@@ -20,6 +20,7 @@ export interface OpenAICompatibleProviderOptions extends ChildSessionOptions {
20
20
  composeExecutor?: ComposeExecutor;
21
21
  memoryStore?: MemoryStore;
22
22
  workspaceStore?: WorkspaceStore;
23
+ subscribeHandler?: import('../../tools/types.js').ToolHandler;
23
24
  stateStore?: StateStore;
24
25
  surface?: string;
25
26
  readOnlyMemory?: boolean;
@@ -0,0 +1,3 @@
1
+ import type { OpenAICompatibleProviderOptions } from './index.options.js';
2
+ import type { AnthropicToolDef } from '../anthropic-direct/types.js';
3
+ export declare function buildProviderSchemas(opts: OpenAICompatibleProviderOptions): AnthropicToolDef[];
@@ -46,11 +46,6 @@ export declare class ProviderRouter implements ProviderQuery {
46
46
  setPermissionMode(mode: string): Promise<void>;
47
47
  setCwd(cwd: string): void;
48
48
  setSystemPrompt(basePrompt: string | undefined): boolean;
49
- reauth(): Promise<{
50
- accountId: string;
51
- oldAccountId: string;
52
- swapped: boolean;
53
- } | null>;
54
49
  supportedCommands(): Promise<ProviderCommandInfo[]>;
55
50
  supportedModels(): Promise<ProviderModelInfo[]>;
56
51
  supportedAgents(): Promise<ProviderAgentInfo[]>;
@@ -57,11 +57,6 @@ export declare class AgentSession implements IAgentSession {
57
57
  setPermissionMode(mode: PermissionMode): Promise<void>;
58
58
  setSystemPrompt(basePrompt: string | undefined): boolean;
59
59
  setCwd(cwd: string): void;
60
- reauth(): Promise<{
61
- accountId: string;
62
- oldAccountId: string;
63
- swapped: boolean;
64
- } | null>;
65
60
  getPrePlanMode(): PermissionMode | undefined;
66
61
  setPlanExitQueueCheck(fn: () => boolean): void;
67
62
  takePendingPlanExitSeed(): Promise<{
@@ -14,6 +14,12 @@ export interface LedgerEnsureContext {
14
14
  export declare class LedgerLifecycle {
15
15
  private writer;
16
16
  private initAttempted;
17
+ private start;
18
+ initialize(ctx: {
19
+ depth?: number;
20
+ parentSessionId?: string;
21
+ cwd?: string;
22
+ }): void;
17
23
  ensure(ctx: LedgerEnsureContext): void;
18
24
  recordUser(text: string, input?: string): void;
19
25
  recordEvent(event: OutputEvent): void;
@@ -17,11 +17,6 @@ export declare function setModel(model: AgentModelInput | undefined, deps: Confi
17
17
  export declare function setPermissionMode(mode: PermissionMode, deps: ConfigDeps): Promise<void>;
18
18
  export declare function setSystemPrompt(basePrompt: string | undefined, deps: ConfigDeps): boolean;
19
19
  export declare function setCwd(cwd: string, deps: ConfigDeps): void;
20
- export declare function reauth(deps: ConfigDeps): Promise<{
21
- accountId: string;
22
- oldAccountId: string;
23
- swapped: boolean;
24
- } | null>;
25
20
  export declare function takePendingPlanExitSeed(deps: ConfigDeps): Promise<{
26
21
  message: string;
27
22
  mode: PermissionMode;
@@ -9,6 +9,14 @@ export interface SessionMeta {
9
9
  startedAt?: number;
10
10
  afkVersion?: string;
11
11
  forkedFrom?: string;
12
+ gitHead?: SessionStart | null;
12
13
  }
14
+ export interface SessionStart {
15
+ branch: string | null;
16
+ headSha: string | null;
17
+ capturedAt: number;
18
+ }
19
+ export declare function captureGitHead(cwd: string): SessionStart;
13
20
  export declare function writeSessionMeta(meta: SessionMeta): Promise<void>;
14
21
  export declare function readSessionMeta(sessionId: string): SessionMeta | null;
22
+ export declare function readSessionStart(sessionId: string): SessionStart | null;
@@ -1,83 +1,10 @@
1
1
  import { renderReceiptMarkdown } from './receipt.render.js';
2
2
  import type { HookHandler } from '../hooks.js';
3
- import { type CostTokens, type SessionCostSource } from './cost.js';
4
- import { type JournalSummary } from './receipt.journal.js';
5
- import { type ClosureReason, type ToolFailureClass, type TraceEvent, type TraceEventKind } from './types.js';
3
+ import { type TraceEvent } from './types.js';
6
4
  export { renderReceiptMarkdown };
5
+ export { RECEIPT_SCHEMA_VERSION, type ReceiptMeta, type ReceiptToolFailure, type RunReceipt } from './receipt.types.js';
6
+ import { type ReceiptMeta, type RunReceipt } from './receipt.types.js';
7
7
  export { extractJournalSummary, type JournalSummary } from './receipt.journal.js';
8
- export declare const RECEIPT_SCHEMA_VERSION: 2;
9
- export interface ReceiptToolFailure {
10
- toolUseId: string;
11
- name: string;
12
- failureClass?: ToolFailureClass;
13
- durationMs: number;
14
- ts: string;
15
- truncated: boolean;
16
- exempt: boolean;
17
- subagentId?: string;
18
- }
19
- export interface RunReceipt {
20
- schemaVersion: typeof RECEIPT_SCHEMA_VERSION;
21
- generatedAt: string;
22
- witnessLabel: string;
23
- tracePath: string;
24
- sessionId?: string;
25
- endReason?: string;
26
- status: 'succeeded' | 'failed' | 'cancelled' | 'unknown';
27
- closureReason?: ClosureReason;
28
- lastStopReason?: string;
29
- guidance?: string;
30
- incomplete: boolean;
31
- startedAt?: string;
32
- endedAt?: string;
33
- durationMs?: number;
34
- toolCalls: {
35
- total: number;
36
- succeeded: number;
37
- errored: number;
38
- erroredNotable: number;
39
- refused: number;
40
- circuitBreakerHits: number;
41
- byTool: Record<string, {
42
- total: number;
43
- errored: number;
44
- }>;
45
- byFailureClass: Record<string, number>;
46
- };
47
- events: {
48
- total: number;
49
- byKind: Partial<Record<TraceEventKind, number>>;
50
- };
51
- subagents: {
52
- started: number;
53
- succeeded: number;
54
- failed: number;
55
- cancelled: number;
56
- };
57
- cost: {
58
- finalCostUsd?: number;
59
- turnCount?: number;
60
- tokens?: CostTokens;
61
- rootCostUsd?: number;
62
- subagentCostUsd?: number;
63
- totalCostUsd?: number;
64
- totalTokens?: CostTokens;
65
- costSource?: SessionCostSource;
66
- };
67
- failures: ReceiptToolFailure[];
68
- humanReviewRequired: boolean;
69
- humanReviewReasons: string[];
70
- limitations: string[];
71
- journalSummary?: JournalSummary;
72
- }
73
- export interface ReceiptMeta {
74
- tracePath: string;
75
- witnessLabel: string;
76
- sessionId?: string;
77
- endReason?: string;
78
- now?: Date;
79
- journalSummary?: JournalSummary;
80
- }
81
8
  export declare function parseTraceJsonl(raw: string): TraceEvent[];
82
9
  export declare function receiptPathsFor(tracePath: string): {
83
10
  label: string;
@@ -90,6 +17,7 @@ export interface WriteRunReceiptOptions {
90
17
  sessionId?: string;
91
18
  reason?: string;
92
19
  now?: Date;
20
+ cwd?: string;
93
21
  }
94
22
  export declare function writeRunReceipt(opts: WriteRunReceiptOptions): Promise<{
95
23
  label: string;
@@ -0,0 +1,79 @@
1
+ import type { CostTokens, SessionCostSource } from './cost.js';
2
+ import type { JournalSummary } from './receipt.journal.js';
3
+ import type { OutcomesV1 } from '../outcomes/outcomes-v1.schema.js';
4
+ import type { ClosureReason, ToolFailureClass, TraceEventKind } from './types.js';
5
+ export declare const RECEIPT_SCHEMA_VERSION: 3;
6
+ export interface ReceiptToolFailure {
7
+ toolUseId: string;
8
+ name: string;
9
+ failureClass?: ToolFailureClass;
10
+ durationMs: number;
11
+ ts: string;
12
+ truncated: boolean;
13
+ exempt: boolean;
14
+ subagentId?: string;
15
+ }
16
+ export interface RunReceipt {
17
+ schemaVersion: typeof RECEIPT_SCHEMA_VERSION;
18
+ generatedAt: string;
19
+ witnessLabel: string;
20
+ tracePath: string;
21
+ sessionId?: string;
22
+ endReason?: string;
23
+ status: 'succeeded' | 'failed' | 'cancelled' | 'unknown';
24
+ closureReason?: ClosureReason;
25
+ lastStopReason?: string;
26
+ guidance?: string;
27
+ incomplete: boolean;
28
+ startedAt?: string;
29
+ endedAt?: string;
30
+ durationMs?: number;
31
+ toolCalls: {
32
+ total: number;
33
+ succeeded: number;
34
+ errored: number;
35
+ erroredNotable: number;
36
+ refused: number;
37
+ circuitBreakerHits: number;
38
+ byTool: Record<string, {
39
+ total: number;
40
+ errored: number;
41
+ }>;
42
+ byFailureClass: Record<string, number>;
43
+ };
44
+ events: {
45
+ total: number;
46
+ byKind: Partial<Record<TraceEventKind, number>>;
47
+ };
48
+ subagents: {
49
+ started: number;
50
+ succeeded: number;
51
+ failed: number;
52
+ cancelled: number;
53
+ };
54
+ cost: {
55
+ finalCostUsd?: number;
56
+ turnCount?: number;
57
+ tokens?: CostTokens;
58
+ rootCostUsd?: number;
59
+ subagentCostUsd?: number;
60
+ totalCostUsd?: number;
61
+ totalTokens?: CostTokens;
62
+ costSource?: SessionCostSource;
63
+ };
64
+ failures: ReceiptToolFailure[];
65
+ humanReviewRequired: boolean;
66
+ humanReviewReasons: string[];
67
+ limitations: string[];
68
+ journalSummary?: JournalSummary;
69
+ outcomes?: OutcomesV1 | null;
70
+ }
71
+ export interface ReceiptMeta {
72
+ tracePath: string;
73
+ witnessLabel: string;
74
+ sessionId?: string;
75
+ endReason?: string;
76
+ now?: Date;
77
+ journalSummary?: JournalSummary;
78
+ outcomes?: OutcomesV1 | null;
79
+ }