agent-afk 5.255.0 → 5.257.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/dist/agent/providers/shared/tool-call-trace.d.ts +1 -0
- package/dist/agent/session/preamble-strip.d.ts +3 -0
- package/dist/agent/trace/events.d.ts +4 -0
- package/dist/agent/trace/types.d.ts +1 -0
- package/dist/agent/whatif-episode-gate.d.ts +5 -0
- package/dist/cli/commands/whatif.d.ts +2 -0
- package/dist/cli/slash/commands/whatif.d.ts +2 -0
- package/dist/cli.mjs +699 -363
- package/dist/config/env.d.ts +23 -0
- package/dist/config/env.paths.d.ts +28 -0
- package/dist/config/env.whatif.d.ts +24 -0
- package/dist/index.mjs +112 -112
- package/dist/paths.d.ts +1 -0
- package/dist/telegram.mjs +138 -137
- package/dist/whatif/args.d.ts +28 -0
- package/dist/whatif/args.usage.d.ts +1 -0
- package/dist/whatif/compile.d.ts +6 -0
- package/dist/whatif/complete.d.ts +2 -0
- package/dist/whatif/complete.retry.d.ts +8 -0
- package/dist/whatif/cost.d.ts +27 -0
- package/dist/whatif/discover.d.ts +15 -0
- package/dist/whatif/episodes.d.ts +12 -0
- package/dist/whatif/index.d.ts +11 -0
- package/dist/whatif/json-extract.d.ts +3 -0
- package/dist/whatif/judge/claude.d.ts +2 -0
- package/dist/whatif/judge/index.d.ts +8 -0
- package/dist/whatif/judge/jev-connect.d.ts +5 -0
- package/dist/whatif/judge/jev.d.ts +9 -0
- package/dist/whatif/ledger.d.ts +10 -0
- package/dist/whatif/observe.d.ts +6 -0
- package/dist/whatif/operators/content-ops.d.ts +4 -0
- package/dist/whatif/operators/index.d.ts +6 -0
- package/dist/whatif/operators/launch-ops.d.ts +4 -0
- package/dist/whatif/operators/memory-ops.d.ts +3 -0
- package/dist/whatif/operators/sandbox-guard.d.ts +2 -0
- package/dist/whatif/operators/skill-plugin-ops.d.ts +3 -0
- package/dist/whatif/predict.d.ts +11 -0
- package/dist/whatif/report.d.ts +9 -0
- package/dist/whatif/run.d.ts +9 -0
- package/dist/whatif/run.limits.d.ts +2 -0
- package/dist/whatif/run.persist.d.ts +2 -0
- package/dist/whatif/run.verify.d.ts +30 -0
- package/dist/whatif/runner/afk-runner.d.ts +10 -0
- package/dist/whatif/runner/afk-runner.run.d.ts +16 -0
- package/dist/whatif/runner/afk-runner.snapshot.d.ts +4 -0
- package/dist/whatif/runner/capture-server.d.ts +9 -0
- package/dist/whatif/runner/child-env.d.ts +2 -0
- package/dist/whatif/runner/tool-log.d.ts +2 -0
- package/dist/whatif/sandbox.d.ts +14 -0
- package/dist/whatif/sandbox.home.d.ts +3 -0
- package/dist/whatif/stats.d.ts +7 -0
- package/dist/whatif/structural.d.ts +2 -0
- package/dist/whatif/structural.normalize.d.ts +5 -0
- package/dist/whatif/surface.d.ts +18 -0
- package/dist/whatif/types.d.ts +260 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Change, ChangeSpec } from './types.js';
|
|
2
|
+
export { WHATIF_USAGE } from './args.usage.js';
|
|
3
|
+
export declare function tokenizeSlashArgs(raw: string): string[];
|
|
4
|
+
export interface WhatifFlagOptions {
|
|
5
|
+
agentModel?: string;
|
|
6
|
+
analystModel?: string;
|
|
7
|
+
verify: boolean;
|
|
8
|
+
turns: number;
|
|
9
|
+
samples: number;
|
|
10
|
+
maxUsd: number;
|
|
11
|
+
judge: 'auto' | 'jev' | 'claude';
|
|
12
|
+
concurrency: number;
|
|
13
|
+
maxTurns: number;
|
|
14
|
+
episodeTimeoutMs: number;
|
|
15
|
+
keepSandboxes: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ParsedWhatifArgs {
|
|
18
|
+
flagChanges: Change[];
|
|
19
|
+
text?: string;
|
|
20
|
+
specFile?: string;
|
|
21
|
+
options: WhatifFlagOptions;
|
|
22
|
+
yes: boolean;
|
|
23
|
+
json: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type ParseResult = ParsedWhatifArgs | string;
|
|
26
|
+
export declare function parseWhatifArgs(argv: string[]): ParseResult;
|
|
27
|
+
export declare function buildFlagSpecTitle(flagChanges: Change[], text?: string): string;
|
|
28
|
+
export declare function loadSpecFile(filePath: string): ChangeSpec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WHATIF_USAGE = "afk whatif \u2014 predict the behavioural impact of a proposed change.\n\nUSAGE\n afk whatif [change text...] [flags]\n /whatif [change text...] [flags]\n\nEXAMPLES\n # Plain English \u2014 compiled to a ChangeSpec, confirmed before running\n afk whatif \"turn off auto-routing\"\n afk whatif \"always ask before using tools\"\n\n # Explicit flags (can be combined and repeated)\n afk whatif --append \"Always ask a clarifying question before running tools.\"\n afk whatif --model claude-haiku-4-5 --verify\n afk whatif --memory-add \"prefers pnpm test:file\" --memory-category preference\n\n # Load a prepared ChangeSpec file\n afk whatif --spec ./my-change.json\n\n # Quick single-turn estimate\n afk whatif \"disable diagnose skill\" --quick\n\n # Full verification with custom judge and budget\n afk whatif --append \"Never use bash\" --verify --judge claude --max-usd 3\n\nCHANGE FLAGS (accumulate in order)\n --append <text> Append text to your AFK.md (user scope)\n --append-project <text> Append text to project AFK.md\n --file <path>=<localfile> Set a file (path: home:<rel> or project:<rel>)\n --hot <localfile> Replace HOT.md with a local file's content\n --memory-add <text> Add a memory fact\n --memory-category <cat> Category for the next --memory-add\n (preference|convention|decision|learning; default: preference)\n --memory-remove <id> Remove a memory fact by numeric id\n --disable-skill <name> Disable a skill by name\n --disable-plugin <name> Disable a plugin by name\n --model <id> Test a different candidate model\n --effort <level> Test a different effort level\n --env KEY=VALUE Set an env var in the candidate sandbox\n --spec <file.json> Load a full ChangeSpec from a JSON file\n\nRUN OPTIONS\n --agent-model <id> Model the agent under test uses (default: current)\n --analyst-model <id> Model for compile/predict/judge (default: sonnet)\n --verify Run episodes and verify predictions empirically\n --quick Single-turn episodes (sets --max-turns 1)\n --turns <n> Real turns to replay (default: 12)\n --samples <n> Samples per episode per environment (default: 3)\n --max-usd <n> Budget cap in USD (default: 5)\n --judge auto|jev|claude Judge to use (default: auto)\n --concurrency <n> Parallel episodes (default: 4)\n --max-turns <n> Max turns per episode (default: 3)\n --timeout <sec> Episode timeout in seconds (default: 180)\n --keep-sandboxes Keep sandbox directories after run\n --yes Skip confirmation of compiled spec\n --json Print results as JSON to stdout\n";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function isRetryableAnalystError(err: unknown): boolean;
|
|
2
|
+
export interface RetryOptions {
|
|
3
|
+
attempts?: number;
|
|
4
|
+
baseDelayMs?: number;
|
|
5
|
+
maxDelayMs?: number;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export declare function withAnalystRetry<T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface VerifyCostInput {
|
|
2
|
+
episodes: number;
|
|
3
|
+
samples: number;
|
|
4
|
+
agentModel: string;
|
|
5
|
+
analystModel: string;
|
|
6
|
+
systemTokens: {
|
|
7
|
+
baseline: number;
|
|
8
|
+
candidate: number;
|
|
9
|
+
};
|
|
10
|
+
judgeExternal: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface VerifyCostEstimate {
|
|
13
|
+
usd: number;
|
|
14
|
+
calls: number;
|
|
15
|
+
breakdown: Record<string, number>;
|
|
16
|
+
approximate?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function estimateVerifyCost(input: VerifyCostInput): VerifyCostEstimate;
|
|
19
|
+
export declare class BudgetTracker {
|
|
20
|
+
private _spent;
|
|
21
|
+
private readonly _max;
|
|
22
|
+
constructor(maxUsd: number);
|
|
23
|
+
add(usd: number): void;
|
|
24
|
+
get spent(): number;
|
|
25
|
+
get exceeded(): boolean;
|
|
26
|
+
remaining(): number;
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CompleteFn, Prediction } from './types.js';
|
|
3
|
+
declare const DiffSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
description: z.ZodString;
|
|
6
|
+
question: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type DiscoveredDiff = z.infer<typeof DiffSchema>;
|
|
9
|
+
export interface OutputPair {
|
|
10
|
+
prompt: string;
|
|
11
|
+
baseline: string;
|
|
12
|
+
candidate: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function discoverDifferences(pairs: OutputPair[], known: Prediction[], complete: CompleteFn, model: string): Promise<DiscoveredDiff[]>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Episode, Prediction } from './types.js';
|
|
2
|
+
interface CollectOpts {
|
|
3
|
+
limit: number;
|
|
4
|
+
excludeSessionIds?: string[];
|
|
5
|
+
sessionsDir?: string;
|
|
6
|
+
now?: Date;
|
|
7
|
+
maxAgeDays?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function collectRealTurns(opts: CollectOpts): Promise<Episode[]>;
|
|
10
|
+
export declare function syntheticEpisodes(predictions: Prediction[]): Episode[];
|
|
11
|
+
export declare function loadSuiteEpisodes(dir: string): Promise<Episode[]>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { runWhatif, WhatifBudgetError } from './run.js';
|
|
2
|
+
export { computeStructuralImpact } from './structural.js';
|
|
3
|
+
export type { Change, ChangeKind, ChangeSpec, LaunchSettings, Environment, OperatorContext, ChangeOperator, RequestSnapshot, StructuralImpact, PredictionDirection, Confidence, Prediction, Episode, ToolRequest, EpisodeTrace, RunnerOptions, AgentRunner, EpisodeFeatures, JudgeQuestion, JudgeInput, JudgeResult, Judge, RateComparison, Verdict, VerifiedPrediction, DiscoveredDifference, FeatureDelta, VerifyResult, WhatifReport, WhatifStage, WhatifProgress, CompleteFn, WhatifOptions, WhatifDeps, } from './types.js';
|
|
4
|
+
export { renderTerminal, renderMarkdown } from './report.js';
|
|
5
|
+
export { createAfkRunner } from './runner/afk-runner.js';
|
|
6
|
+
export { createAnthropicComplete } from './complete.js';
|
|
7
|
+
export { resolveJudge } from './judge/index.js';
|
|
8
|
+
export { connectJev } from './judge/jev-connect.js';
|
|
9
|
+
export { createClaudeJudge } from './judge/claude.js';
|
|
10
|
+
export { compileChangeSpec } from './compile.js';
|
|
11
|
+
export { describeChange } from './operators/index.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CompleteFn, Judge } from '../types.js';
|
|
2
|
+
import type { connectJev } from './jev-connect.js';
|
|
3
|
+
export interface ResolveJudgeDeps {
|
|
4
|
+
complete: CompleteFn;
|
|
5
|
+
model: string;
|
|
6
|
+
connectJev: typeof connectJev;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveJudge(choice: 'auto' | 'jev' | 'claude', deps: ResolveJudgeDeps): Promise<Judge>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Judge, JudgeQuestion, JudgeResult } from '../types.js';
|
|
2
|
+
export interface JevCallToolFn {
|
|
3
|
+
(name: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
4
|
+
}
|
|
5
|
+
export interface JevJudgeOpts {
|
|
6
|
+
callTool: JevCallToolFn;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseJevResult(raw: unknown, questions: JudgeQuestion[]): JudgeResult;
|
|
9
|
+
export declare function createJevJudge(opts: JevJudgeOpts): Judge;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Prediction, Verdict } from './types.js';
|
|
2
|
+
export interface CalibrationRecord {
|
|
3
|
+
ts: string;
|
|
4
|
+
changeKinds: string[];
|
|
5
|
+
prediction: Prediction;
|
|
6
|
+
verdict: Verdict;
|
|
7
|
+
delta: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function appendCalibration(records: CalibrationRecord[], file?: string): Promise<void>;
|
|
10
|
+
export declare function trackRecordSummary(changeKinds: string[], file?: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EpisodeFeatures, EpisodeTrace } from './types.js';
|
|
2
|
+
export declare const FEATURE_LABELS: readonly string[];
|
|
3
|
+
export declare function extractFeatures(trace: EpisodeTrace): EpisodeFeatures;
|
|
4
|
+
export declare function featureIndicators(f: EpisodeFeatures): Record<string, boolean>;
|
|
5
|
+
export declare function meanToolCalls(samples: EpisodeFeatures[]): number;
|
|
6
|
+
export declare function meanResponseChars(samples: EpisodeFeatures[]): number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Change, ChangeKind, ChangeOperator, ChangeSpec, Environment, OperatorContext } from '../types.js';
|
|
2
|
+
export declare function getOperator<K extends ChangeKind>(kind: K): ChangeOperator<K>;
|
|
3
|
+
export declare function applyChanges(spec: ChangeSpec, env: Environment, ctx: OperatorContext): Promise<void>;
|
|
4
|
+
export declare function describeChange(change: Change): string;
|
|
5
|
+
export declare function specTouchesProject(spec: ChangeSpec): boolean;
|
|
6
|
+
export declare function homePathsToCopyFor(spec: ChangeSpec): string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CompleteFn, Prediction, StructuralImpact } from './types.js';
|
|
2
|
+
export interface PredictInput {
|
|
3
|
+
spec: {
|
|
4
|
+
title: string;
|
|
5
|
+
changes: unknown[];
|
|
6
|
+
};
|
|
7
|
+
changeDescriptions: string[];
|
|
8
|
+
structural: StructuralImpact;
|
|
9
|
+
trackRecord?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function predictChanges(input: PredictInput, complete: CompleteFn, model: string): Promise<Prediction[]>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ThemePalette } from '../cli/palette.js';
|
|
2
|
+
import type { WhatifReport } from './types.js';
|
|
3
|
+
export declare function buildHeadline(report: Omit<WhatifReport, 'headline'>): string;
|
|
4
|
+
export declare function renderMarkdown(report: WhatifReport): string;
|
|
5
|
+
export declare function renderTerminal(report: WhatifReport, palette: ThemePalette): string[];
|
|
6
|
+
export declare function standardLimits(opts: {
|
|
7
|
+
verified: boolean;
|
|
8
|
+
judgeExternal: boolean;
|
|
9
|
+
}): string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WhatifDeps, WhatifOptions, WhatifReport } from './types.js';
|
|
2
|
+
export declare class WhatifBudgetError extends Error {
|
|
3
|
+
readonly estimateUsd: number;
|
|
4
|
+
readonly maxUsd: number;
|
|
5
|
+
constructor(estimateUsd: number, maxUsd: number);
|
|
6
|
+
}
|
|
7
|
+
export declare function runWhatif(options: WhatifOptions & {
|
|
8
|
+
sessionsDir?: string;
|
|
9
|
+
}, deps: WhatifDeps): Promise<WhatifReport>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentRunner, CompleteFn, Episode, EpisodeTrace, Environment, Judge, Prediction, StructuralImpact, VerifyResult, WhatifProgress } from './types.js';
|
|
2
|
+
export interface VerifyRunInput {
|
|
3
|
+
episodes: Episode[];
|
|
4
|
+
baseline: Environment;
|
|
5
|
+
candidate: Environment;
|
|
6
|
+
predictions: Prediction[];
|
|
7
|
+
structural: StructuralImpact;
|
|
8
|
+
judge: Judge;
|
|
9
|
+
crossCheckJudge: Judge | undefined;
|
|
10
|
+
runner: AgentRunner;
|
|
11
|
+
complete: CompleteFn;
|
|
12
|
+
analystModel: string;
|
|
13
|
+
options: {
|
|
14
|
+
samples: number;
|
|
15
|
+
concurrency: number;
|
|
16
|
+
maxTurns: number;
|
|
17
|
+
episodeTimeoutMs: number;
|
|
18
|
+
maxUsdRemaining: number;
|
|
19
|
+
changeKinds: string[];
|
|
20
|
+
calibrationFile?: string;
|
|
21
|
+
};
|
|
22
|
+
onProgress?: (p: WhatifProgress) => void;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
export interface VerifyRunOutput {
|
|
26
|
+
verifyResult: VerifyResult;
|
|
27
|
+
allTraces: EpisodeTrace[];
|
|
28
|
+
analystCostUsd: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function verifyRun(input: VerifyRunInput): Promise<VerifyRunOutput>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
2
|
+
import type { AgentRunner } from '../types.js';
|
|
3
|
+
export interface AfkRunnerOptions {
|
|
4
|
+
cliEntry?: {
|
|
5
|
+
command: string;
|
|
6
|
+
args: string[];
|
|
7
|
+
};
|
|
8
|
+
spawnImpl?: typeof nodeSpawn;
|
|
9
|
+
}
|
|
10
|
+
export declare function createAfkRunner(opts?: AfkRunnerOptions): AgentRunner;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SpawnOptions } from 'node:child_process';
|
|
2
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
3
|
+
import type { EpisodeTrace } from '../types.js';
|
|
4
|
+
export type SpawnFn = typeof nodeSpawn;
|
|
5
|
+
export interface RunEpisodeChildArgs {
|
|
6
|
+
command: string;
|
|
7
|
+
spawnArgs: string[];
|
|
8
|
+
spawnOptions: SpawnOptions;
|
|
9
|
+
spawnImpl: SpawnFn;
|
|
10
|
+
episodeId: string;
|
|
11
|
+
envLabel: 'baseline' | 'candidate';
|
|
12
|
+
sample: number;
|
|
13
|
+
timeoutMs: number;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
export declare function runEpisodeChild(args: RunEpisodeChildArgs): Promise<EpisodeTrace>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RequestSnapshot } from '../types.js';
|
|
2
|
+
import type { CapturedRequest } from './capture-server.js';
|
|
3
|
+
export declare function buildSnapshotFromRequests(requests: CapturedRequest[], stderrTail: string): RequestSnapshot;
|
|
4
|
+
export declare function buildSnapshotCliArgs(baseEntryArgs: string[], prompt: string, model?: string, effort?: string): string[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Environment, LaunchSettings, ChangeSpec } from './types.js';
|
|
2
|
+
export interface MaterializeOptions {
|
|
3
|
+
realHome: string;
|
|
4
|
+
realCwd: string;
|
|
5
|
+
runDir: string;
|
|
6
|
+
spec: ChangeSpec;
|
|
7
|
+
baseLaunch: LaunchSettings;
|
|
8
|
+
}
|
|
9
|
+
export interface SandboxResult {
|
|
10
|
+
baseline: Environment;
|
|
11
|
+
candidate: Environment;
|
|
12
|
+
cleanup(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function materializeSandboxes(opts: MaterializeOptions): Promise<SandboxResult>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Prediction, RateComparison, Verdict } from './types.js';
|
|
2
|
+
export declare function compareRates(baseline: number[], candidate: number[]): RateComparison;
|
|
3
|
+
export declare function verdictFor(pred: Prediction, rates: RateComparison): Verdict;
|
|
4
|
+
export declare function predictionAccuracy(verified: ReadonlyArray<{
|
|
5
|
+
verdict: Verdict;
|
|
6
|
+
}>): number | undefined;
|
|
7
|
+
export declare function agreementRate(a: number[], b: number[]): number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ParsedWhatifArgs } from './args.js';
|
|
2
|
+
import type { ChangeSpec, CompleteFn, WhatifDeps, WhatifProgress } from './types.js';
|
|
3
|
+
export interface ResolveSpecDeps {
|
|
4
|
+
complete: CompleteFn;
|
|
5
|
+
analystModel: string;
|
|
6
|
+
realHome: string;
|
|
7
|
+
skills: string[];
|
|
8
|
+
plugins: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveSpec(parsed: ParsedWhatifArgs, deps: ResolveSpecDeps): Promise<ChangeSpec>;
|
|
11
|
+
export interface BuildWhatifDepsOptions {
|
|
12
|
+
token: string;
|
|
13
|
+
analystModel: string;
|
|
14
|
+
onProgress?: (p: WhatifProgress) => void;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildWhatifDeps(opts: BuildWhatifDepsOptions): WhatifDeps;
|
|
18
|
+
export declare function readDirNames(dir: string): string[];
|