agent-afk 5.256.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.
Files changed (47) hide show
  1. package/dist/cli/commands/whatif.d.ts +2 -0
  2. package/dist/cli/slash/commands/whatif.d.ts +2 -0
  3. package/dist/cli.mjs +699 -364
  4. package/dist/index.mjs +112 -112
  5. package/dist/telegram.mjs +131 -131
  6. package/dist/whatif/args.d.ts +28 -0
  7. package/dist/whatif/args.usage.d.ts +1 -0
  8. package/dist/whatif/compile.d.ts +6 -0
  9. package/dist/whatif/complete.d.ts +2 -0
  10. package/dist/whatif/complete.retry.d.ts +8 -0
  11. package/dist/whatif/cost.d.ts +27 -0
  12. package/dist/whatif/discover.d.ts +15 -0
  13. package/dist/whatif/episodes.d.ts +12 -0
  14. package/dist/whatif/index.d.ts +11 -0
  15. package/dist/whatif/json-extract.d.ts +3 -0
  16. package/dist/whatif/judge/claude.d.ts +2 -0
  17. package/dist/whatif/judge/index.d.ts +8 -0
  18. package/dist/whatif/judge/jev-connect.d.ts +5 -0
  19. package/dist/whatif/judge/jev.d.ts +9 -0
  20. package/dist/whatif/ledger.d.ts +10 -0
  21. package/dist/whatif/observe.d.ts +6 -0
  22. package/dist/whatif/operators/content-ops.d.ts +4 -0
  23. package/dist/whatif/operators/index.d.ts +6 -0
  24. package/dist/whatif/operators/launch-ops.d.ts +4 -0
  25. package/dist/whatif/operators/memory-ops.d.ts +3 -0
  26. package/dist/whatif/operators/sandbox-guard.d.ts +2 -0
  27. package/dist/whatif/operators/skill-plugin-ops.d.ts +3 -0
  28. package/dist/whatif/predict.d.ts +11 -0
  29. package/dist/whatif/report.d.ts +9 -0
  30. package/dist/whatif/run.d.ts +9 -0
  31. package/dist/whatif/run.limits.d.ts +2 -0
  32. package/dist/whatif/run.persist.d.ts +2 -0
  33. package/dist/whatif/run.verify.d.ts +30 -0
  34. package/dist/whatif/runner/afk-runner.d.ts +10 -0
  35. package/dist/whatif/runner/afk-runner.run.d.ts +16 -0
  36. package/dist/whatif/runner/afk-runner.snapshot.d.ts +4 -0
  37. package/dist/whatif/runner/capture-server.d.ts +9 -0
  38. package/dist/whatif/runner/child-env.d.ts +2 -0
  39. package/dist/whatif/runner/tool-log.d.ts +2 -0
  40. package/dist/whatif/sandbox.d.ts +14 -0
  41. package/dist/whatif/sandbox.home.d.ts +3 -0
  42. package/dist/whatif/stats.d.ts +7 -0
  43. package/dist/whatif/structural.d.ts +2 -0
  44. package/dist/whatif/structural.normalize.d.ts +5 -0
  45. package/dist/whatif/surface.d.ts +18 -0
  46. package/dist/whatif/types.d.ts +260 -0
  47. 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,6 @@
1
+ import type { ChangeSpec, CompleteFn } from './types.js';
2
+ export interface CompileCtx {
3
+ skills: string[];
4
+ plugins: string[];
5
+ }
6
+ export declare function compileChangeSpec(text: string, complete: CompleteFn, model: string, ctx: CompileCtx): Promise<ChangeSpec>;
@@ -0,0 +1,2 @@
1
+ import type { CompleteFn } from './types.js';
2
+ export declare function createAnthropicComplete(token: string): CompleteFn;
@@ -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,3 @@
1
+ import { z } from 'zod';
2
+ export declare function extractJson(text: string): unknown;
3
+ export declare function extractJsonAs<T>(text: string, schema: z.ZodType<T>): T;
@@ -0,0 +1,2 @@
1
+ import type { CompleteFn, Judge } from '../types.js';
2
+ export declare function createClaudeJudge(complete: CompleteFn, model: string): Judge;
@@ -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,5 @@
1
+ export interface JevConnection {
2
+ callTool(name: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
3
+ close(): Promise<void>;
4
+ }
5
+ export declare function connectJev(): Promise<JevConnection | undefined>;
@@ -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,4 @@
1
+ import type { ChangeOperator } from '../types.js';
2
+ export declare const appendOperator: ChangeOperator<'append'>;
3
+ export declare const fileOperator: ChangeOperator<'file'>;
4
+ export declare const hotOperator: ChangeOperator<'hot'>;
@@ -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,4 @@
1
+ import type { ChangeOperator } from '../types.js';
2
+ export declare const modelOperator: ChangeOperator<'model'>;
3
+ export declare const effortOperator: ChangeOperator<'effort'>;
4
+ export declare const envOperator: ChangeOperator<'env'>;
@@ -0,0 +1,3 @@
1
+ import type { ChangeOperator } from '../types.js';
2
+ export declare const memoryAddOperator: ChangeOperator<'memory-add'>;
3
+ export declare const memoryRemoveOperator: ChangeOperator<'memory-remove'>;
@@ -0,0 +1,2 @@
1
+ import type { Environment } from '../types.js';
2
+ export declare function assertInsideSandbox(dir: string, env: Environment): void;
@@ -0,0 +1,3 @@
1
+ import type { ChangeOperator } from '../types.js';
2
+ export declare const disableSkillOperator: ChangeOperator<'disable-skill'>;
3
+ export declare const disablePluginOperator: ChangeOperator<'disable-plugin'>;
@@ -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,2 @@
1
+ import type { VerifyResult } from './types.js';
2
+ export declare function verifyShortfallLimits(v: VerifyResult): string[];
@@ -0,0 +1,2 @@
1
+ import type { EpisodeTrace, WhatifReport } from './types.js';
2
+ export declare function persistRun(runDir: string, report: WhatifReport, traces: EpisodeTrace[]): Promise<void>;
@@ -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,9 @@
1
+ export interface CapturedRequest {
2
+ body: unknown;
3
+ }
4
+ export interface CaptureServer {
5
+ port: number;
6
+ requests: CapturedRequest[];
7
+ close(): Promise<void>;
8
+ }
9
+ export declare function startCaptureServer(): Promise<CaptureServer>;
@@ -0,0 +1,2 @@
1
+ import type { Environment } from '../types.js';
2
+ export declare function buildChildEnv(env: Environment, extra: Record<string, string>): Record<string, string>;
@@ -0,0 +1,2 @@
1
+ import type { ToolRequest } from '../types.js';
2
+ export declare function readToolLog(path: string): Promise<ToolRequest[]>;
@@ -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,3 @@
1
+ export declare function sandboxedAfkEnvKeys(realHome: string): string[];
2
+ export declare function buildSandboxHome(realHome: string, sandboxHome: string): void;
3
+ export declare function materializeSymlinks(sandboxHome: string, relPaths: string[]): void;
@@ -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,2 @@
1
+ import type { RequestSnapshot, StructuralImpact } from './types.js';
2
+ export declare function computeStructuralImpact(baseline: RequestSnapshot, candidate: RequestSnapshot): StructuralImpact;
@@ -0,0 +1,5 @@
1
+ import type { Environment, RequestSnapshot } from './types.js';
2
+ export declare function normalizeSnapshot(snap: RequestSnapshot, env: Environment, real: {
3
+ home: string;
4
+ cwd: string;
5
+ }): RequestSnapshot;
@@ -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[];