/** * LLM planning surface: one-shot JSON proposal/review generation through an * injected `Complete` seam, so planning is testable without a live model. * @module dsh-continual-harness */ import type { RequestMessage, ToolSchema } from '@deepseek-ai/dsh-llm'; import type { SessionId } from '@deepseek-ai/dsh-session'; import type { AutoRefineReview, AutoRefineReviewContext, RefinementPlanInput, RefinementProposal } from './types.ts'; /** Optional request-level context forwarded to the completion seam (Route A). */ export interface CompleteContext { /** Route A: host-loop tool schemas — reproduce the loop's cache key. */ tools?: readonly ToolSchema[]; /** Route A: session identity stamped on the request. */ sessionId?: SessionId; /** Output budget override derived from the remaining context window. */ maxTokens?: number; } /** One non-reasoning LLM call: system + user prompt in, plain text out. */ export type Complete = ( /** * System slot for the request. `undefined` sends NO system slot at all — * the shape of a loop-built host request on dsh 0.1.5, whose system prompt * rides as the leading system-role message of `prefix`. Route A passes the * host's own value (usually `undefined`) so the reused prefix stays warm; * Route B passes an explicit prompt. */ system: string | undefined, user: string, signal?: AbortSignal, /** Route A: warm session messages prepended before the trailing user message. */ prefix?: readonly RequestMessage[], /** Request-level context (tools/sessionId/output budget) for Route A. */ context?: CompleteContext) => Promise; /** Raised when the model reply is truncated before its JSON object completes. */ export declare const TRUNCATED_JSON_ERROR = "the model stopped before completing its JSON object; the reply was truncated or empty"; /** Raised when the model reply parses but is not a valid proposal shape. */ export declare const MALFORMED_PROPOSAL_ERROR = "malformed refinement proposal"; /** Raised when the model reply parses but is not a valid review shape. */ export declare const MALFORMED_REVIEW_ERROR = "malformed auto-refine review"; /** * True when a planner failure message means the reply was truncated or * malformed rather than a transport/planning failure: the same shapes the * coordinator classifies as `invalid-proposal` and the Route A→B fallback * retries as a truncated reply. */ export declare function isTruncatedReply(message: string): boolean; /** System prompt for refinement planning. */ export declare const REFINEMENT_SYSTEM_PROMPT = "You are the continual harness refiner of an agent loop. The agent learns by persisting small, reusable, evidence-backed entries \u2014 prompt notes, memories, skill contracts, or subagent specs \u2014 and by pruning stale ones.\n\nYou receive the current harness state, the recent refinement history, a tail-biased trajectory excerpt of the current session, and the store scope. Propose a minimal set of edits that capture durable lessons. Rules:\n\n- Edits must be small and evidence-backed by the trajectory; never invent facts.\n- ids are lowercase kebab-case, unique within (scope, kind).\n- 'prompt' entries are supplemental prompt notes; the base system prompt is immutable and never edited.\n- 'memory' entries are durable facts, decisions, failures, preferences, and outcomes.\n- 'skill' entries are real dsh skills, materialized as SKILL.md bundles: \"description\" is a one-line summary, \"content\" is the markdown body (step-by-step instructions), and the id must be kebab-case.\n- Skill \"content\" keeps the SKILL.md body self-contained step-by-step instructions. Templates and scripts go into a structured \"files\" map: keys are relative paths under scripts/ or references/ (e.g. \"scripts/oq_quantize.py\"), values are the file contents. Use forward slashes only. Never include SKILL.md in files \u2014 it is generated from content. Keep each file small and total under the bundle limits (sizes count in UTF-8 bytes). files must be complete \u2014 every file the skill needs must be present. files are text-only \u2014 do not embed binary content.\n- The harness refine path never performs a full skill-authoring loop (interviews, evals, packaging); route those to a dedicated skill-authoring capability.\n- 'subagent' entries are reusable delegation specs: purpose, instructions, when to invoke.\n- Prefer 'update' over creating near-duplicates; 'delete' entries that are stale, contradicted, or never useful.\n- Scope policy: 'global' is only for stable cross-session lessons, durable preferences, reusable skills, and project-scoped facts; everything else belongs in 'local'. Local entries shadow same-id global entries.\n- Update preference, in this order: 1) update a related entry used this session; 2) update an existing class-level umbrella entry; 3) add supporting content to an existing entry (references/templates/scripts analog); 4) only then create a new class-level entry. Never create one skill per session, and never name entries after PR numbers, raw error strings, or \"fix-X-today\"-style titles.\n- 'reason': every 'update'/'delete' edit MUST carry a one-line 'reason' stating why this write is made; 'create' may omit it. Rollback reasons are system-generated \u2014 never supply them.\n- 'blastRadius' is REQUIRED on every edit: one of general|project|session. It is your declaration of how far this edit reaches, and an edit that omits it is rejected \u2014 never rely on a default. 'general' (reach across projects) cannot be stored in the local layer, and 'session' (reach of this one session) cannot be stored in the global layer.\n- Do NOT capture environment-dependent failures (missing binaries, missing commands, unconfigured credentials), negative assertions about tools or features (\"tool X is broken\"), transient session errors, one-off task narratives, or unresolved failed attempts as durable rules. Only the fix \u2014 the install command or config steps \u2014 may be captured.\n- If nothing durable is worth persisting, return edits: [].\n- The summary is one line.\n\nRespond with ONLY a JSON object:\n{\"id\":\"refine_\",\"summary\":\"one line\",\"edits\":[{\"action\":\"create|update|delete\",\"kind\":\"prompt|memory|skill|subagent\",\"id\":\"kebab-case\",\"content\":\"...\",\"description\":\"...\",\"files\":{\"scripts/oq_quantize.py\":\"...\"},\"reason\":\"...\",\"blastRadius\":\"general\"}]}"; /** System prompt for the automatic refinement review gate. */ export declare const AUTO_REFINE_REVIEW_SYSTEM_PROMPT = "You are the gatekeeper of an agent's continual harness. Given the current harness state, the recent refinement history, and a tail-biased trajectory excerpt, decide whether persisting a refinement NOW would materially help future steps of this session.\n\nApprove only when the trajectory shows durable lessons: a repeated failure with an identified fix, a reusable tactic or delegation role, or a fact worth remembering. Reject when the session is too short, nothing new emerged, or the evidence is thin. You cannot see the future; base the verdict only on the evidence presented.\n\nNegative assertions about tools or features and environment-dependent failures are NOT durable lessons (Do NOT capture).\n\nRespond with ONLY a JSON object:\n{\"approved\":true|false,\"rationale\":\"one sentence\"}"; /** Extract the first `{...}` span from model text, tolerating prose and code fences. */ export declare function extractJsonObject(text: string): string; /** Parse a refinement proposal from model text; JSON code fences are tolerated. */ export declare function parseProposal(text: string): RefinementProposal; /** Parse a review verdict from model text; JSON code fences are tolerated. */ export declare function parseAutoRefineReview(text: string): AutoRefineReview; /** Plan a refinement through the injected seam. */ export declare function planRefinement(input: RefinementPlanInput, complete: Complete, signal?: AbortSignal, prefix?: readonly RequestMessage[], system?: string, context?: CompleteContext): Promise; /** Run the automatic refinement review gate through the injected seam. */ export declare function reviewAutoRefine(context: AutoRefineReviewContext, complete: Complete, signal?: AbortSignal): Promise; /** Build the store-scope instruction line for the planner. */ export declare function scopeInstruction(global: boolean): string; /** Build the instruction line for an auto-triggered plan. */ export declare function autoRefineInstructions(reason: AutoRefineReviewContext['reason'], review: AutoRefineReview): string; //# sourceMappingURL=planner.d.ts.map