diff --git a/skills/rig/rig.ts b/skills/rig/rig.ts index 8650865..c930d6b 100644 --- a/skills/rig/rig.ts +++ b/skills/rig/rig.ts @@ -1,10 +1,10 @@ /** - * @file skills/rig/rig.ts @last-analyzed b88e1d6 @edit-time 2026-07-25T03:20:42Z + * @file skills/rig/rig.ts @last-analyzed 138fb9d @edit-time 2026-07-26T20:52:42Z * @purpose Minimal TypeScript multi-agent harness: typed input/output schemas, prompt intents, sub-agent delegation, Copilot SDK runtime * @deps @github/copilot-sdk (CopilotClient,RuntimeConnection,approveAll); node:path,url,fs/promises,child_process,util * T:Json type null|bool|num|str|Json[]|{[k]:Json} - * T:Schema type StringSchema|NumberSchema|IntegerSchema|BooleanSchema|NullSchema|UnknownSchema|ArraySchema|ObjectSchema|RecordSchema|EnumSchema|OptionalSchema|NullableSchema [NEW] - * T:NullableSchema type {nullable:true;inner:Inner;description?} accepts inner|null [NEW] + * T:Schema type StringSchema|NumberSchema|IntegerSchema|BooleanSchema|NullSchema|UnknownSchema|ArraySchema|ObjectSchema|RecordSchema|EnumSchema|OptionalSchema|NullableSchema + * T:NullableSchema type {nullable:true;inner:Inner;description?} accepts inner|null * T:InferSchema type TS inference from schema descriptor to runtime type * T:AgentInputValue type input accepting raw values or PromptIntent/PromptBuilder at any nesting level * T:Simplify type flattens intersection types for display @@ -17,12 +17,15 @@ * T:AgentAddonContext type context passed to each addon in the chain * T:AgentDefinitionFactory type typeof agent (for passing agent constructor as value) * T:AgentError class error carrying kind,agent,turn,response,schema,schemaText fields + * T:SteeringOptions type {message?:string} options for steering addon [NEW] + * T:TimeoutOptions type {timeout:number} options for timeout addon [NEW] + * T:AgentRegistration type callback invoked once per unique Agent instance for oncePerAgent [NEW] * T:Tool type ToolConfig+name; created by defineTool * T:ToolConfig type {description,parameters,handler} * T:PromptIntent type declarative placeholder {kind:'bash'|'bashEach'|'read'|'readAll'|'write'|'writeOutput'|'writeInput'|'glob'|'env',…} resolved into prompt text * T:PromptBuilder class template-tag result; composes intents+strings into a prompt fragment * T:PromptHelpers type shape of exported p object - * T:PromptVariable type {__rig:'prompt.var';name:string;value:T} named prompt variable [NEW] + * T:PromptVariable type {__rig:'prompt.var';name:string;value:T} named prompt variable * T:ResponseAnalysisResult type {ok:true;output}|{ok:false;error:AgentError} * T:CopilotEngineOptions type CopilotClientOptions minus connection, plus server/token/headers fields * T:LaunchOptions type options for launchRigProgram (server,token,headers,cwd,args) @@ -47,17 +50,17 @@ * p.readOptional(path,fallback?,opts?) PromptIntent file read declaration; returns fallback (default "") if file absent * p.write(path,content,opts?) PromptIntent file write declaration; does NOT expand to path in template — hard-code path in output schema * p.writeOutput(field,path,opts?) PromptIntent post-generation write declaration; writes output field value to path - * p.writeInput(inputPathField,contentOutputField,opts?) PromptIntent post-generation write declaration; writes output field value to the path given by input. [NEW] + * p.writeInput(inputPathField,contentOutputField,opts?) PromptIntent post-generation write declaration; writes output field value to the path given by input. * p.glob(pattern,opts?) PromptIntent glob file-list declaration (not run in-process) * p.readAll(paths,opts?) PromptIntent multi-file read declaration; reads all listed paths and concatenates their contents - * p.readInput(field,opts?) PromptIntent file read declaration using a runtime input field as the path; reads the file at the single path given by input. [NEW] - * p.readAllInput(field,opts?) PromptIntent multi-file read declaration using a runtime input array field; reads all paths in input. and concatenates their contents [NEW] - * p.bashEach(template,inputArrayField,opts?) PromptIntent bash-per-element declaration; runs template once per element in input., substituting {} with each element [NEW] + * p.readInput(field,opts?) PromptIntent file read declaration using a runtime input field as the path; reads the file at the single path given by input. + * p.readAllInput(field,opts?) PromptIntent multi-file read declaration using a runtime input array field; reads all paths in input. and concatenates their contents + * p.bashEach(template,inputArrayField,opts?) PromptIntent bash-per-element declaration; runs template once per element in input., substituting {} with each element * p.env(name,fallback?,opts?) PromptIntent env var read declaration; returns fallback (default "") if not set * p.json(value) string JSON.stringify helper for inlining structured values in prompt templates - * p.inputField(field) string returns "input." for explicit, documented reference to a caller-supplied input field in prompt prose [NEW] - * p.var(name,value) PromptVariable named variable binding for prompt templates [NEW] - * p.region(language,body) string wraps body in a fenced code block for the given language [NEW] + * p.inputField(field) string returns "input." for explicit, documented reference to a caller-supplied input field in prompt prose + * p.var(name,value) PromptVariable named variable binding for prompt templates + * p.region(language,body) string wraps body in a fenced code block for the given language * F:agent(spec) AgentFn; spec={name,description,input,output,prompt,addons,maxTurns} * F:copilotEngine(opts?) AgentFactory wrapping CopilotClient+RuntimeConnection * F:configureAgent(factory) sets global AgentFactory used by agent() calls at module scope @@ -68,14 +71,21 @@ * F:defaultRepairPrompt(spec,err) string re-prompt on parse/validation failure * F:toJsonSchema(schema) JsonSchemaObject converts Schema to plain JSON Schema * F:debug(category) creates a lazy category-filtered JSONL logger + * F:steering(opts?) AgentAddon appends last-turn warning to prompt when model must correct output [NEW] + * F:timeout(opts) AgentAddon applies AbortSignal timeout to each turn [NEW] + * F:oncePerAgent(register) AgentAddon runs registration callback exactly once per unique Agent instance [NEW] + * V:addons {repair,steering,timeout,oncePerAgent} convenience object collecting all built-in addon factories [NEW] * addon:repair re-prompts on JSON/schema failure up to maxTurns (built-in via defaultRepairPrompt) + * addon:steering appends warning on last turn so model knows it must correct output now [NEW] + * addon:timeout wraps each turn with AbortSignal from TimeoutOptions.timeout ms [NEW] + * addon:oncePerAgent runs AgentRegistration callback once per unique Agent (e.g. tool registration) [NEW] * INV:shape-descriptors JS values promote to schemas ("" → string, 0 → number, [""] → string[]) * INV:optional-key trailing _ on spec key means optional field * INV:prompt-intents p.* are declarative placeholders resolved into prompt text, never executed * INV:repair-contract addon intercepts AgentError, appends error to prompt, retries up to maxTurns * INV:json-extraction model response is parsed directly as JSON; fallback strategies: extract ```json fenced block, then extract first balanced {…}/[…] value * INV:schema-symbol Schema objects carry private SCHEMA_SYMBOL; toJSON serializes via serializeSchema - * INV:p-write-no-path p.write() contributes a write instruction to the prompt; it does NOT return the path; hard-code path in agent output [NEW] + * INV:p-write-no-path p.write() contributes a write instruction to the prompt; it does NOT return the path; hard-code path in agent output */ import { basename, dirname, isAbsolute, resolve } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url";