Skip to content

Commit 49bede0

Browse files
authored
Merge pull request #23 from githubnext/rig-header/7476c6d-7377410a3fab7511
2 parents 0f5c394 + 0c053de commit 49bede0

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

skills/rig/rig.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
/**
2+
* @file skills/rig/rig.ts @last-analyzed 7476c6d @edit-time 2026-07-23T07:07:59Z
3+
* @purpose Minimal TypeScript multi-agent harness: typed input/output schemas, prompt intents, sub-agent delegation, Copilot SDK runtime
4+
* @deps @github/copilot-sdk (CopilotClient,RuntimeConnection,approveAll); node:path,url,fs/promises,child_process,util
5+
* T:Json type null|bool|num|str|Json[]|{[k]:Json}
6+
* T:Schema type StringSchema|NumberSchema|BooleanSchema|UnknownSchema|ArraySchema|ObjectSchema|RecordSchema|EnumSchema|OptionalSchema
7+
* T:InferSchema<T> type TS inference from schema descriptor to runtime type
8+
* T:AgentInputValue<T> type input accepting raw values or PromptIntent/PromptBuilder at any nesting level
9+
* T:Simplify<T> type flattens intersection types for display
10+
* T:ValidationResult type {ok:true}|{ok:false;error:string}
11+
* T:AgentSpec<I,O> type {name,description,input,output,prompt,addons?,maxTurns?,agents?} agent declaration; agents? enables sub-agent delegation
12+
* T:AgentFn<I,O> type callable agent with .use(addons) and .spec property
13+
* T:AgentFactory type (options:AgentOptions)=>Agent|Promise<Agent>
14+
* T:Agent interface {ask(input,opts?):Promise<unknown>,close():Promise<void>}
15+
* T:AgentAddon type middleware (ctx,next)=>Promise<void>; ctx exposes spec,turn,prompt,output,completed,nextPrompt
16+
* T:AgentAddonContext type context passed to each addon in the chain
17+
* T:AgentDefinitionFactory type typeof agent (for passing agent constructor as value)
18+
* T:AgentError class error carrying turn,agentName,rawOutput,parseError fields
19+
* T:Tool<TArgs> type ToolConfig+name; created by defineTool
20+
* T:ToolConfig<TArgs> type {description,parameters,handler}
21+
* T:PromptIntent type declarative placeholder {kind:'bash'|'read'|'write',…} resolved into prompt text
22+
* T:PromptBuilder class template-tag result; composes intents+strings into a prompt fragment
23+
* T:PromptHelpers type shape of exported p object
24+
* T:ResponseAnalysisResult type {ok:true;output}|{ok:false;error:AgentError}
25+
* T:CopilotEngineOptions type CopilotClientOptions minus connection, plus server/token/headers fields
26+
* T:LaunchOptions type options for launchRigProgram (server,token,headers,cwd,args)
27+
* T:LauncherIo type {stdin,stdout,stderr} override for launcher subprocess
28+
* T:JsonSchemaObject type {[key:string]:unknown} plain JSON Schema object
29+
* s.string/number/boolean SchemaHelperFactory primitives; call as value or fn(desc)
30+
* s.array(items,desc?) ArraySchema
31+
* s.object(props,desc?) ObjectSchema; s.optional(inner) marks field optional
32+
* s.record(valSchema,desc?) RecordSchema keyed by string
33+
* s.enum(...values|values,desc) EnumSchema
34+
* s.unknown() unconstrained JSON
35+
* p`...` PromptBuilder template tag; interpolates PromptIntent|string|PromptBuilder
36+
* p.bash(cmd,opts?) PromptIntent bash execution declaration (not run in-process)
37+
* p.read(path,opts?) PromptIntent file read declaration
38+
* p.write(path,content,opts?) PromptIntent file write declaration
39+
* F:agent(spec) AgentFn<I,O>; spec={name,description,input,output,prompt,addons,maxTurns}
40+
* F:copilotEngine(opts?) AgentFactory wrapping CopilotClient+RuntimeConnection
41+
* F:configureAgent(factory) sets global AgentFactory used by agent() calls at module scope
42+
* F:launchRigProgram(path,opts?) runs .ts agent file as subprocess via tsx
43+
* F:runLauncherCli(opts?) entry-point CLI: parses argv, wires copilotEngine, runs agent
44+
* F:defineTool(name,config) Tool with handler+parameters schema
45+
* F:analyzeResponse(resp,schema,name,turn) ResponseAnalysisResult parse+validate from <output> XML tag
46+
* F:defaultRepairPrompt(spec,err) string re-prompt on parse/validation failure
47+
* F:toJsonSchema(schema) JsonSchemaObject converts Schema to plain JSON Schema
48+
* addon:repair re-prompts on JSON/schema failure up to maxTurns (built-in via defaultRepairPrompt)
49+
* INV:shape-descriptors JS values promote to schemas ("" → string, 0 → number, [""] → string[])
50+
* INV:optional-key trailing _ on spec key means optional field
51+
* INV:prompt-intents p.* are declarative placeholders resolved into prompt text, never executed
52+
* INV:repair-contract addon intercepts AgentError, appends error to prompt, retries up to maxTurns
53+
* INV:output-tag model response parsed from <output>...</output> XML tag in assistant message
54+
* INV:schema-symbol Schema objects carry private SCHEMA_SYMBOL; toJSON serializes via serializeSchema
55+
*/
156
import { basename, dirname, isAbsolute, resolve } from "node:path";
257
import { fileURLToPath, pathToFileURL } from "node:url";
358
import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";

0 commit comments

Comments
 (0)