agent-contracts-runtime 0.31.4 → 0.32.1
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/README.md +77 -96
- package/cli-contract.yaml +411 -22
- package/dist/{chunk-IAIG5VCJ.js → chunk-W5YWUFAH.js} +7 -3
- package/dist/chunk-W5YWUFAH.js.map +1 -0
- package/dist/cli/index.js +1011 -12
- package/dist/cli/index.js.map +1 -1
- package/dist/generator/index.js +1 -1
- package/docs/cli-reference.md +1370 -216
- package/dsl/agent-runtime.config.yaml +2 -0
- package/dsl/agents/implementation-auditor.yaml +195 -0
- package/dsl/agents/llm-feature-implementer.yaml +298 -0
- package/dsl/handoff-types.yaml +184 -0
- package/dsl/implement-dsl.yaml +119 -0
- package/dsl/tasks.yaml +635 -0
- package/package.json +3 -1
- package/templates/implement-reference-templates.md +823 -0
- package/templates/implement-reference.md +240 -0
- package/templates/workflows.ts.hbs +2 -2
- package/dist/chunk-IAIG5VCJ.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
checkFreshness,
|
|
10
10
|
generate,
|
|
11
11
|
loadConfig
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-W5YWUFAH.js";
|
|
13
13
|
|
|
14
14
|
// src/cli/index.ts
|
|
15
|
-
import { existsSync as
|
|
16
|
-
import { resolve as
|
|
15
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
16
|
+
import { resolve as resolve4 } from "path";
|
|
17
17
|
import { register } from "tsx/esm/api";
|
|
18
18
|
|
|
19
19
|
// src/generated/cli/program.ts
|
|
@@ -49,6 +49,22 @@ function createProgram(handlers2, version) {
|
|
|
49
49
|
program2.command("show-prompt").description("Display the generated prompt for a task.").argument("<task-id>", "ID of the task to show the prompt for (e.g. plan-and-implement, audit-tests).").option("-u, --user-request <value>", "User request text to include in the prompt preview.", "(preview)").option("--format <value>", "Output format.", "markdown").option("--with-plugins", "Apply registered plugin prompt enhancers to the output.", false).action(async (taskId, opts, cmd) => {
|
|
50
50
|
await handlers2.showPrompt(taskId, opts, cmd.optsWithGlobals());
|
|
51
51
|
});
|
|
52
|
+
program2.command("implement").description("Implement LLM-powered commands in a CLI tool.").argument("<description>", 'Natural language description of the LLM feature(s) to implement. Examples: "Add an audit command for migration safety", "Add propose and explain commands for SQL optimization".').option("-a, --adapter <value>", "SDK adapter to use. Must be an agentic adapter (claude, cursor).", "claude").option("-p, --project-dir <value>", "Path to the target project directory.", ".").option("-n, --dry-run", "Output the prompt context without calling the LLM.", false).option("--model <value>", "Model name override for the selected adapter.").option("--fail-on <value>", "Minimum finding severity that causes a non-zero exit.", "error").option("-o, --output <value>", "Write the result to a file instead of stdout.").option("--report-format <value>", "Output format for the result.", "text").option("--show-prompt", "Output the constructed prompt without calling the LLM API.", false).action(async (description, opts, cmd) => {
|
|
53
|
+
if (opts.showPrompt) {
|
|
54
|
+
const prompt = await handlers2.implement(description, opts, cmd.optsWithGlobals());
|
|
55
|
+
if (typeof prompt === "string") process.stdout.write(prompt + "\n");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
await handlers2.implement(description, opts, cmd.optsWithGlobals());
|
|
59
|
+
});
|
|
60
|
+
program2.command("audit-implementation").description("Audit an LLM command integration for pattern conformance.").argument("[project-dir]", "Path to the project directory to audit. Defaults to current directory.").option("-a, --adapter <value>", "SDK adapter to use for the audit agent.", "claude").option("--focus <value>", "Limit audit to a specific layer. Defaults to all layers.", "all").option("-n, --dry-run", "Output the prompt context without calling the LLM.", false).option("--fail-on <value>", "Minimum finding severity that causes a non-zero exit.", "error").option("--model <value>", "Model name override for the selected adapter.").option("-o, --output <value>", "Write the result to a file instead of stdout.").option("--report-format <value>", "Output format for the audit report.", "text").option("--show-prompt", "Output the constructed prompt without calling the LLM API.", false).action(async (projectDir, opts, cmd) => {
|
|
61
|
+
if (opts.showPrompt) {
|
|
62
|
+
const prompt = await handlers2.auditImplementation(projectDir, opts, cmd.optsWithGlobals());
|
|
63
|
+
if (typeof prompt === "string") process.stdout.write(prompt + "\n");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await handlers2.auditImplementation(projectDir, opts, cmd.optsWithGlobals());
|
|
67
|
+
});
|
|
52
68
|
program2.command("doctor").description("Verify configuration, generated files, and SDK connectivity.").action(async (opts, cmd) => {
|
|
53
69
|
await handlers2.doctor({}, cmd.optsWithGlobals());
|
|
54
70
|
});
|
|
@@ -388,17 +404,922 @@ async function runInit(options) {
|
|
|
388
404
|
return { files_created };
|
|
389
405
|
}
|
|
390
406
|
|
|
407
|
+
// src/lib/implement.ts
|
|
408
|
+
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
409
|
+
import { resolve as resolve2, join as join3 } from "path";
|
|
410
|
+
import { fileURLToPath } from "url";
|
|
411
|
+
|
|
412
|
+
// src/builtin-agents/generated/agents.ts
|
|
413
|
+
var implementationAuditor = {
|
|
414
|
+
id: "implementation-auditor",
|
|
415
|
+
role_name: "Implementation Auditor",
|
|
416
|
+
purpose: "Audits an existing LLM command integration to verify it correctly\nfollows the agent-contracts + agent-contracts-runtime + cli-contracts\nstack conventions. Detects architectural violations, missing patterns,\nincorrect API usage, and deviations from the canonical\nintegrate-llm-commands pattern.\n\nThis agent is read-only \u2014 it analyzes code but does not modify it.\nIt produces structured findings (AgentAuditResult) that identify\nexactly what is wrong and how to fix it.\n\n## What This Agent Checks\n\n### Layer 1: agent-contracts DSL\n- DSL entry has version:1 and system block with id/name\n- Agents defined with all required fields (role_name, purpose, mode,\n can_read_artifacts, can_write_artifacts, responsibilities, constraints)\n- Tasks have target_agent, workflow, result_handoff, completion_criteria\n- Handoff type schemas conform to AgentAuditResult base shape\n- Workflows define steps with correct task/agent cross-references\n- Guardrails and guardrail_policies are defined\n- agent-runtime.config.yaml exists with dsl and generated_dir\n\n### Layer 2: agent-contracts-runtime Integration\n- orchestrator.ts uses runTask() or runWorkflow(), NOT adapter.send()\n- Adapters imported from agent-contracts-runtime/adapters/*, not custom\n- Dynamic import pattern for graceful degradation (exit 11/12)\n- Generated registries imported from src/generated/dsl/index.js\n- Registries passed to runTask/runWorkflow as options\n- Plugin hooks not bypassed\n- No hand-rolled prompt building (use buildTaskPrompt or let runTask do it)\n\n### Layer 3: cli-contracts Compliance\n- cli-contract.yaml has LLM commands with all standard options:\n --adapter, --model, --dry-run, --fail-on, --output, --report-format\n- x-agent metadata present (riskLevel, safeDryRunOption, expectedDurationMs)\n- Exit codes follow convention (0, 1, 3, 10, 11, 12)\n- components/schemas includes AgentAuditResult and related types\n- --report-format used (not --format) for LLM commands\n\n### Architecture & Patterns\n- src/agents/ module structure (orchestrator, context-builder, formatter, types)\n- Context builder caps input at 16KB\n- Formatter implements computeExitCode with correct threshold logic\n- --dry-run returns prompt without LLM call\n- No direct LLM API calls anywhere in the codebase\n",
|
|
417
|
+
mode: "read-only",
|
|
418
|
+
dispatch_only: false,
|
|
419
|
+
can_read_artifacts: [],
|
|
420
|
+
can_write_artifacts: [],
|
|
421
|
+
can_execute_tools: [],
|
|
422
|
+
can_invoke_agents: [],
|
|
423
|
+
can_return_handoffs: [
|
|
424
|
+
"audit-result"
|
|
425
|
+
],
|
|
426
|
+
responsibilities: [
|
|
427
|
+
"Verify the DSL directory structure exists: dsl/{project}-dsl.yaml, dsl/agents/*.yaml, dsl/tasks.yaml, dsl/handoff-types.yaml, dsl/agent-runtime.config.yaml.",
|
|
428
|
+
"Check that the main DSL entry has version:1, a system block with id and name, and uses $ref for agents/tasks/handoff_types.",
|
|
429
|
+
"Validate agent definitions have all required fields: role_name, purpose, mode, can_read_artifacts:[], can_write_artifacts:[], responsibilities, constraints. Check that rules use R-PREFIX-NNN format and severity is mandatory|recommended|optional.",
|
|
430
|
+
"Validate task definitions: target_agent matches a defined agent, workflow matches a defined workflow, result_handoff matches a defined handoff type, completion_criteria are specific and testable.",
|
|
431
|
+
"Verify handoff type schemas conform to AgentAuditResult shape when applicable (summary, riskLevel, findings[], recommendedActions[], metadata). Check $ref usage and SSoT comments for inlined schemas.",
|
|
432
|
+
"Check that guardrails and guardrail_policies are defined, and that output-schema-conformance is included.",
|
|
433
|
+
"Scan src/agents/orchestrator.ts for: (1) imports from agent-contracts-runtime (not custom SDK wrappers), (2) usage of runTask() or runWorkflow() (not adapter.send/sendExecution), (3) dynamic import pattern with exit code 11 for missing runtime and exit code 12 for adapter errors, (4) generated registries imported and passed to runTask/runWorkflow.",
|
|
434
|
+
"Verify no file in the project calls adapter.send(), adapter.followUp(), or adapter.sendExecution() directly \u2014 all LLM invocations must go through the runtime's task/workflow runner.",
|
|
435
|
+
"Check that src/generated/dsl/ exists and contains the expected files (agents.ts, tasks.ts, workflows.ts, handoffs.ts, index.ts). Verify the .manifest.json exists and is not stale.",
|
|
436
|
+
"Verify adapter creation uses the correct constructors: CursorSdkAdapter.create() (async static), ClaudeAgentSdkAdapter constructor, OpenAIAgentsSdkAdapter constructor, etc.",
|
|
437
|
+
"Check cli-contract.yaml for each LLM command: all six standard options present (--adapter, --model, --dry-run, --fail-on, --output, --report-format). Verify --report-format is used (not --format).",
|
|
438
|
+
'Verify x-agent metadata on each LLM command: riskLevel, safeDryRunOption (must be "dry-run"), expectedDurationMs. Flag high-risk commands without requiresConfirmation.',
|
|
439
|
+
"Check exit code definitions: 0 (success), 1 (error), 3 (validation), 10 (findings), 11 (runtime missing), 12 (adapter error).",
|
|
440
|
+
"Verify components/schemas includes AgentAuditResult, AgentFinding, AgentRecommendedAction, and AgentEvidence definitions.",
|
|
441
|
+
"Verify src/agents/ directory structure: types.ts (TaskId, AgentConfig, AgentOptions, AgentRunResult), orchestrator.ts (createAdapter, runAgentTask with dynamic imports), context-builder.ts (build*Context functions with 16KB cap), formatter.ts (computeExitCode, formatResultText, formatResultJson).",
|
|
442
|
+
"Check that --dry-run mode returns the constructed prompt without making any LLM API call.",
|
|
443
|
+
"Scan for direct LLM API imports (@anthropic-ai/sdk, openai, @google/genai, @cursor/sdk) used outside of adapter files \u2014 application code must not import these directly."
|
|
444
|
+
],
|
|
445
|
+
constraints: [
|
|
446
|
+
"This agent is read-only. It must not create, modify, or delete any files. Output is a structured audit report only.",
|
|
447
|
+
"Findings must include specific file paths, line references where possible, and concrete remediation steps.",
|
|
448
|
+
"Severity classification: critical = breaks the integration pattern (direct API calls, missing runtime usage), error = missing required element (no x-agent, missing standard option), warning = deviation from best practice (context not capped, missing guardrail), info = improvement suggestion.",
|
|
449
|
+
"Category vocabulary: dsl-structure, dsl-agent, dsl-task, dsl-handoff, dsl-workflow, dsl-guardrail, runtime-adapter, runtime-orchestrator, runtime-registry, runtime-plugin, cli-contract-options, cli-contract-xagent, cli-contract-exits, cli-contract-schema, architecture-modules, architecture-dry-run, architecture-context-builder, architecture-formatter.",
|
|
450
|
+
"Every finding with severity warning or above must include a recommendation field with a concrete fix.",
|
|
451
|
+
"The confidence field should reflect how certain the finding is: 1.0 for pattern matches (e.g., adapter.send() found in code), 0.8+ for structural checks (e.g., missing file), 0.5-0.8 for heuristic assessments (e.g., context might exceed 16KB)."
|
|
452
|
+
],
|
|
453
|
+
rules: [
|
|
454
|
+
{
|
|
455
|
+
"id": "R-AUDIT-001",
|
|
456
|
+
"description": "Every finding must specify target (file path) and category (from the defined category vocabulary). Findings without a target are not actionable.",
|
|
457
|
+
"severity": "mandatory"
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
"id": "R-AUDIT-002",
|
|
461
|
+
"description": "The audit must check all three layers (DSL, runtime, CLI contract). Skipping a layer or returning partial results is not acceptable.",
|
|
462
|
+
"severity": "mandatory"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
"id": "R-AUDIT-003",
|
|
466
|
+
"description": "Critical findings must be surfaced for: (1) direct adapter.send() calls bypassing runTask, (2) custom adapter classes not from agent-contracts-runtime, (3) missing generated registries in runTask/runWorkflow calls.",
|
|
467
|
+
"severity": "mandatory"
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
"id": "R-AUDIT-004",
|
|
471
|
+
"description": "The riskLevel in the audit result must be derived from the most severe finding: any critical \u2192 critical, any error \u2192 high, any warning \u2192 medium, info only \u2192 low.",
|
|
472
|
+
"severity": "mandatory"
|
|
473
|
+
}
|
|
474
|
+
],
|
|
475
|
+
escalation_criteria: [
|
|
476
|
+
{
|
|
477
|
+
"condition": "Target project has no LLM command integration to audit",
|
|
478
|
+
"action": "stop_and_report"
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"condition": "Target project uses a completely different integration pattern (not agent-contracts stack)",
|
|
482
|
+
"action": "stop_and_report"
|
|
483
|
+
}
|
|
484
|
+
]
|
|
485
|
+
};
|
|
486
|
+
var llmFeatureImplementer = {
|
|
487
|
+
id: "llm-feature-implementer",
|
|
488
|
+
role_name: "LLM Feature Implementer",
|
|
489
|
+
purpose: 'Expert implementation agent for the agent-contracts toolchain.\nAdds LLM-powered commands (audit, propose, explain, etc.) to CLI tools\nusing the three-layer stack:\n\n1. **agent-contracts** \u2014 DSL package. Defines agents, tasks, workflows,\n handoff types, guardrails, and guardrail policies in YAML. The\n `resolve()` function handles `$ref`, `extends`, and merge operators.\n Installed as a devDependency. CLI: `agent-contracts audit`.\n\n2. **agent-contracts-runtime** \u2014 Runtime bridge. Generates typed\n TypeScript contracts from DSL via Handlebars templates, then\n executes workflows through pluggable SDK adapters. Provides\n `runTask()`, `runWorkflow()`, `createRuntime()`, plugin system,\n and guardrail hooks. CLI: `agent-runtime generate|run|list|doctor`.\n\n3. **cli-contracts** \u2014 CLI contract package. Defines command-line\n interfaces in YAML (`cli-contract.yaml`): command sets, arguments,\n options, exit codes, stdout/stderr schemas, `x-agent` metadata,\n and `effects`. Generates typed Commander programs, Zod validators,\n and markdown docs. CLI: `cli-contracts init|generate|validate`.\n\nThe canonical integration pattern ("integrate-llm-commands") produces:\n- DSL definitions under `dsl/` (agents, tasks, workflows, handoff-types)\n- Pre-generated TypeScript contracts under `src/generated/dsl/`\n- Runtime integration module under `src/agents/` (orchestrator,\n context-builder, formatter, types)\n- CLI command handlers under `src/commands/`\n- Updated `cli-contract.yaml` with new commands and `x-agent` metadata\n',
|
|
490
|
+
mode: "read-write",
|
|
491
|
+
dispatch_only: false,
|
|
492
|
+
can_read_artifacts: [],
|
|
493
|
+
can_write_artifacts: [],
|
|
494
|
+
can_execute_tools: [],
|
|
495
|
+
can_invoke_agents: [],
|
|
496
|
+
can_return_handoffs: [
|
|
497
|
+
"implementation-result"
|
|
498
|
+
],
|
|
499
|
+
responsibilities: [
|
|
500
|
+
"Read and analyze the target project's cli-contract.yaml, package.json, tsconfig.json, and existing source code to understand the CLI structure, existing commands, component schemas, and TypeScript configuration.",
|
|
501
|
+
"Identify which LLM commands to add based on the user's description. Canonical command types: audit (semantic review), propose (structured proposal generation), explain (human-readable explanation of machine output).",
|
|
502
|
+
"Create the DSL directory structure: dsl/{project}-dsl.yaml (main entry with version:1, system block, $ref to sub-files), dsl/agents/{name}.yaml, dsl/tasks.yaml, dsl/handoff-types.yaml, dsl/agent-runtime.config.yaml.",
|
|
503
|
+
"Define agents with: role_name, purpose (domain expertise), mode (read-only for analysis agents), can_read_artifacts:[], can_write_artifacts:[], can_return_handoffs, responsibilities, constraints, rules (R-PREFIX-NNN format), escalation_criteria.",
|
|
504
|
+
"Define tasks with: description, target_agent, allowed_from_agents, workflow (must match a workflow ID), invocation_handoff, result_handoff, responsibilities, completion_criteria.",
|
|
505
|
+
"Define handoff types with: version:1, description, schema (JSON Schema). Result types should conform to AgentAuditResult shape (summary, riskLevel, findings[], recommendedActions[], metadata). Use $ref to cli-contract.yaml components/schemas as SSoT when possible; inline with SSoT comment as fallback.",
|
|
506
|
+
"Define workflows with trigger, entry_conditions, and steps (delegate or gate). Each delegate step references a task and from_agent. Gate steps pause for user approval.",
|
|
507
|
+
"Define guardrails (output-schema-conformance, domain-specific safety) and guardrail_policies grouping them with severity and action.",
|
|
508
|
+
"Create agent-runtime.config.yaml: dsl points to main DSL file, generated_dir points to src/generated/dsl.",
|
|
509
|
+
"Implement src/agents/types.ts: TaskId union type, AgentConfig interface (adapter, model, temperature), AgentOptions interface (dryRun, failOn), AgentRunResult interface (taskId, data, raw, prompt, dryRun, status, errorMessage, followUpsUsed, retriesUsed).",
|
|
510
|
+
"Implement src/agents/orchestrator.ts: createAdapter() with dynamic imports from agent-contracts-runtime/adapters/*, runAgentTask() that imports runTask from agent-contracts-runtime, loads generated registries from src/generated/dsl/index.js, and calls runTask with registries.",
|
|
511
|
+
"Implement src/agents/context-builder.ts: build{Command}Context() functions that transform CLI inputs into structured markdown prompts. Cap context at 16KB. Structure: # Request, ## Configuration, ## Target, ## Instructions.",
|
|
512
|
+
"Implement src/agents/formatter.ts: computeExitCode() mapping findings to exit codes via --fail-on threshold, formatResultText() with severity icons, formatResultJson() for structured output.",
|
|
513
|
+
"Create src/commands/{command}.ts handlers: load config, call context builder, call runAgentTask, format output, compute exit code.",
|
|
514
|
+
"Update cli-contract.yaml: add command definitions with standard LLM options (--adapter, --model, --dry-run, --fail-on, --output, --report-format), exit codes (0, 1, 3, 10, 11, 12), x-agent metadata, and register AgentAuditResult/AgentFinding/AgentRecommendedAction in components/schemas.",
|
|
515
|
+
'Add npm scripts: "dsl:generate" running agent-runtime generate --config dsl/agent-runtime.config.yaml. Add agent-contracts and agent-contracts-runtime as devDependencies. Add SDK packages as optional peerDependencies.'
|
|
516
|
+
],
|
|
517
|
+
constraints: [
|
|
518
|
+
"NEVER create custom adapter classes. Import from agent-contracts-runtime: ClaudeAgentSdkAdapter from agent-contracts-runtime/adapters/claude-agent-sdk, CursorSdkAdapter from agent-contracts-runtime/adapters/cursor-sdk, OpenAIAgentsSdkAdapter from agent-contracts-runtime/adapters/openai-agents-sdk, GeminiSdkAdapter from agent-contracts-runtime/adapters/gemini-sdk, MockAdapter from agent-contracts-runtime/adapters/mock.",
|
|
519
|
+
"NEVER call adapter.send() or adapter.sendExecution() directly. All LLM invocations must go through runTask() or runWorkflow() imported from agent-contracts-runtime. These functions handle prompt building, handoff validation, retry/followUp, and plugin hooks.",
|
|
520
|
+
'Dynamic-import both agent-contracts-runtime and adapter packages. The tool must work without them installed (graceful degradation). Pattern: const RUNTIME = "agent-contracts-runtime"; try { const { runTask } = await import(RUNTIME); } catch { exit(11); }',
|
|
521
|
+
"LLM commands use --report-format (json|text|yaml) for output format. --format is reserved for deterministic commands. Never mix them.",
|
|
522
|
+
"Exit code convention: 0=success (no findings above threshold), 1=general error, 3=input validation/parse failed, 10=findings detected above --fail-on threshold, 11=agent-contracts-runtime not installed, 12=adapter initialization error (missing API key, etc.).",
|
|
523
|
+
"Standard LLM command options (all must be present): --adapter <name> (mock|cursor|claude|openai|gemini, default varies), --model <name> (optional override), --dry-run (output prompt without LLM call), --fail-on <level> (warning|error|critical, default error), --output/-o <file> (write to file instead of stdout), --report-format <fmt> (json|text|yaml, default json).",
|
|
524
|
+
"Result handoff schemas must extend the AgentAuditResult base shape: summary (string, required), riskLevel (enum: low|medium|high|critical, required), findings (AgentFinding[], required), recommendedActions (AgentRecommendedAction[], optional), metadata (object with tool, command, version, generatedAt, adapter, model fields, optional).",
|
|
525
|
+
"AgentFinding shape: id?, severity (info|warning|error|critical), category (domain vocabulary), target?, location?, message (required), recommendation?, confidence? (0-1), evidence? (array of {type,content,source}), details? (object).",
|
|
526
|
+
"AgentRecommendedAction shape: kind (run_command|edit_file|review|confirm| block|ignore), title (required), command?, target?, rationale?.",
|
|
527
|
+
"Main DSL entry must have version:1 and a system block with id and name. Without these, the generator produces numbered files instead of named ones.",
|
|
528
|
+
"Every task must have a workflow field matching a defined workflow ID. Every workflow step's from_agent must match a defined agent ID. can_read_artifacts and can_write_artifacts must be empty arrays ([]) when no artifact registry is defined.",
|
|
529
|
+
"agent-runtime.config.yaml format: dsl: ./{project}-dsl.yaml generated_dir: ../src/generated/dsl Optional: plugins (array of paths), recovery ({max_follow_ups, max_retries}).",
|
|
530
|
+
"runTask signature: runTask(adapter: SdkAdapter, taskId: string, context: TaskContext, options?: TaskRunOptions & { agentRegistry?, taskRegistry?, handoffSchemas?, retry? }): Promise<TaskRunResult>. TaskContext: { user_request, prior_context?, relevant_paths?, acceptance_criteria?, handoff_input?, variables? }. TaskRunResult: { outcome: TaskOutcome, follow_ups_used, retries_used }. TaskOutcome: success {data,raw} | validation_error {errors,raw} | escalation {reason,raw} | error {message}.",
|
|
531
|
+
"runWorkflow overloads: (1) runWorkflow(adapter, workflowId, options, registries?) \u2014 legacy. (2) runWorkflow(adapter, invocation, registries?) \u2014 structured. WorkflowInvocation: { workflow, handoff?, user_request?, runtime? {maxFollowUps,maxRetries,timeoutMs,readonly,dryRun}, hooks? {onStepComplete,onGate,onOptionalStep}, context? {cwd,environment,artifacts,variables} }. WorkflowResult: { workflow_id, status (completed|escalated|gate_rejected|error), steps[], total_elapsed_ms, escalation_reason?, error_message? }.",
|
|
532
|
+
"Adapter constructors: MockAdapter({responses?, defaultLatencyMs?}), CursorSdkAdapter.create({apiKey, model?, cwd?, guardrailHooks?}) \u2014 async static, ClaudeAgentSdkAdapter({cwd?, model?, tools?, permissionMode?, maxTurns?, guardrailHooks?}), OpenAIAgentsSdkAdapter({model?, maxTurns?, guardrailHooks?, tools?, agentName?, signal?}), GeminiSdkAdapter({apiKey?, model?, systemInstruction?, temperature?, maxOutputTokens?, guardrailHooks?}).",
|
|
533
|
+
'Generated contract imports: import { agentRegistry, taskRegistry, handoffSchemas, workflowRegistry } from "../generated/dsl/index.js". Pass these as options to runTask/runWorkflow: { agentRegistry, taskRegistry, handoffSchemas } for runTask; { workflowRegistry, taskRegistry, agentRegistry, handoffSchemas } for runWorkflow.',
|
|
534
|
+
"Plugin interface (AgentPlugin): id (string), beforeTask?(taskId, context), afterTask?(taskId, outcome), contextEnhancer?(taskId, context), promptEnhancer?(taskId, prompt, context), promptBuilder?(args), customGuardrails?, beforeWorkflow?(workflowId, userRequest), afterWorkflow?(workflowId, result).",
|
|
535
|
+
"x-agent fields for LLM commands in cli-contract.yaml: riskLevel (low for read-only analysis), requiresConfirmation (false for read-only), idempotent (true for analysis), sideEffects ([network]), sideEffectNote (describe network call and optional file write), safeDryRunOption (dry-run), expectedDurationMs (120000 typical), retryableExitCodes ([1, 12])."
|
|
536
|
+
],
|
|
537
|
+
rules: [
|
|
538
|
+
{
|
|
539
|
+
"id": "R-IMPL-001",
|
|
540
|
+
"description": "Import SDK adapters exclusively from agent-contracts-runtime/adapters/*. Never create adapter classes, wrapper functions, or API client code.",
|
|
541
|
+
"severity": "mandatory"
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
"id": "R-IMPL-002",
|
|
545
|
+
"description": "All LLM invocations must use runTask() or runWorkflow() from agent-contracts-runtime. Never call adapter.send(), adapter.followUp(), or adapter.sendExecution() directly. The runtime handles prompt building, schema validation, retry, followUp, and plugin hooks.",
|
|
546
|
+
"severity": "mandatory"
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
"id": "R-IMPL-003",
|
|
550
|
+
"description": "Every LLM command in cli-contract.yaml must have x-agent metadata with at minimum: riskLevel, safeDryRunOption, expectedDurationMs.",
|
|
551
|
+
"severity": "mandatory"
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
"id": "R-IMPL-004",
|
|
555
|
+
"description": "Handoff type schemas must use $ref to cli-contract.yaml components/schemas as SSoT. If $ref resolution fails at generate time, inline the schema and add a YAML comment noting the SSoT path.",
|
|
556
|
+
"severity": "mandatory"
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
"id": "R-IMPL-005",
|
|
560
|
+
"description": "Context builder must cap prompt input at 16KB. Filter large contexts (schema dumps, lint output, etc.) to relevant portions before inclusion.",
|
|
561
|
+
"severity": "recommended"
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
"id": "R-IMPL-006",
|
|
565
|
+
"description": 'The orchestrator must dynamic-import agent-contracts-runtime as a single string variable (const PKG = "agent-contracts-runtime") to enable graceful degradation. Exit with code 11 when the import fails, code 12 when the adapter fails to initialize.',
|
|
566
|
+
"severity": "mandatory"
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
"id": "R-IMPL-007",
|
|
570
|
+
"description": "Generated DSL contracts must be imported from src/generated/dsl/index.js and passed as registries to runTask/runWorkflow. Never hard-code agent definitions, task definitions, or handoff schemas in application code.",
|
|
571
|
+
"severity": "mandatory"
|
|
572
|
+
}
|
|
573
|
+
],
|
|
574
|
+
escalation_criteria: [
|
|
575
|
+
{
|
|
576
|
+
"condition": "Target project has no cli-contract.yaml and user did not request creating one",
|
|
577
|
+
"action": "stop_and_report"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
"condition": "Target project is not a TypeScript / Node.js stack",
|
|
581
|
+
"action": "stop_and_report"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
"condition": "Target project already has src/agents/ with a different integration pattern",
|
|
585
|
+
"action": "stop_and_report"
|
|
586
|
+
}
|
|
587
|
+
]
|
|
588
|
+
};
|
|
589
|
+
var agentRegistry = {
|
|
590
|
+
"implementation-auditor": implementationAuditor,
|
|
591
|
+
"llm-feature-implementer": llmFeatureImplementer
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// src/builtin-agents/generated/tasks.ts
|
|
595
|
+
var implementLlmFeature = {
|
|
596
|
+
id: "implement-llm-feature",
|
|
597
|
+
description: 'Implement LLM-powered commands in a target CLI tool using the\nagent-contracts + agent-contracts-runtime + cli-contracts stack.\n\n## Implementation Procedure\n\n### Step 1: Project Analysis\n\nRead these files from the target project:\n- cli-contract.yaml \u2014 existing commands, components/schemas, x-agent usage\n- package.json \u2014 dependencies, scripts, bin entries, type:"module" check\n- tsconfig.json \u2014 module resolution, paths, outDir\n- src/ directory structure \u2014 understand existing command handler pattern\n\nDetermine:\n- Which LLM commands to add (audit / propose / explain)\n- What domain-specific context each command needs\n- What structured output schema each command returns\n- Whether the project already has agent-contracts integration\n\n### Step 2: Install Dependencies\n\nAdd to package.json devDependencies:\n- agent-contracts: ^0.32.0\n- agent-contracts-runtime: ^0.31.0\n- zod: ^4.0.0\n\nAdd optional peerDependencies for SDK packages:\n- @anthropic-ai/claude-agent-sdk: >=0.2.0\n- @openai/agents: >=0.10.0\n- @google/genai: >=2.0.0\n- @cursor/sdk (no version constraint)\n\n### Step 3: Create DSL Definitions\n\nCreate directory structure:\n\n dsl/\n \u251C\u2500\u2500 {project}-dsl.yaml\n \u251C\u2500\u2500 agent-runtime.config.yaml\n \u251C\u2500\u2500 agents/\n \u2502 \u2514\u2500\u2500 {agent-name}.yaml\n \u251C\u2500\u2500 tasks.yaml\n \u2514\u2500\u2500 handoff-types.yaml\n\n**Main DSL entry** (`dsl/{project}-dsl.yaml`):\n\n version: 1\n system:\n id: {project}\n name: "{Project} Agent System"\n default_workflow_order:\n - {workflow-ids}\n agents: { $ref: "./agents/" }\n tasks: { $ref: "./tasks.yaml" }\n handoff_types: { $ref: "./handoff-types.yaml" }\n guardrails:\n output-schema-conformance:\n description: ...\n scope: { agents: [...], tasks: [...] }\n rationale: ...\n guardrail_policies:\n {domain}-safety-policy:\n rules:\n - guardrail: output-schema-conformance\n severity: critical\n action: block\n workflow:\n {workflow-id}:\n description: ...\n trigger: cli-command\n entry_conditions: [...]\n steps:\n - type: delegate\n task: {task-id}\n from_agent: {agent-id}\n\n**Agent definition** (`dsl/agents/{agent-name}.yaml`):\n\n {agent-name}:\n role_name: "{Role Name}"\n purpose: >-\n Domain-specific purpose describing what the agent knows\n and what it can do that static rules cannot.\n mode: read-only\n can_read_artifacts: []\n can_write_artifacts: []\n can_invoke_agents: []\n can_execute_tools: []\n can_return_handoffs: [{result-handoff-ids}]\n responsibilities: [...]\n constraints: [...]\n rules:\n - id: "R-{PREFIX}-001"\n description: ...\n severity: mandatory\n escalation_criteria:\n - condition: ...\n action: stop_and_report\n\n**Tasks** (`dsl/tasks.yaml`):\n\n {task-id}:\n description: ...\n target_agent: {agent-name}\n allowed_from_agents: [{agent-name}]\n workflow: {workflow-id}\n input_artifacts: []\n invocation_handoff: {request-handoff}\n result_handoff: {result-handoff}\n responsibilities: [...]\n completion_criteria: [...]\n\n**Handoff types** (`dsl/handoff-types.yaml`):\nUse AgentAuditResult shape as the base for result types:\n\n {result-handoff}:\n version: 1\n description: ...\n schema:\n type: object\n required: [summary, riskLevel, findings]\n properties:\n summary: { type: string }\n riskLevel:\n type: string\n enum: [low, medium, high, critical]\n findings:\n type: array\n items:\n type: object\n required: [severity, category, message]\n properties:\n id: { type: string }\n severity:\n type: string\n enum: [info, warning, error, critical]\n category: { type: string }\n target: { type: string }\n location: { type: string }\n message: { type: string }\n recommendation: { type: string }\n confidence: { type: number, minimum: 0, maximum: 1 }\n recommendedActions:\n type: array\n items:\n type: object\n required: [kind, title]\n properties:\n kind:\n type: string\n enum: [run_command, edit_file, review, confirm, block, ignore]\n title: { type: string }\n command: { type: string }\n target: { type: string }\n rationale: { type: string }\n metadata:\n type: object\n properties:\n tool: { type: string }\n command: { type: string }\n version: { type: string }\n generatedAt: { type: string }\n adapter: { type: string }\n model: { type: string }\n\nDomain-specific result types add properties alongside the base fields.\n\n**Runtime config** (`dsl/agent-runtime.config.yaml`):\n\n dsl: ./{project}-dsl.yaml\n generated_dir: ../src/generated/dsl\n\n### Step 4: Generate TypeScript Contracts\n\nAdd to package.json scripts:\n\n "dsl:generate": "agent-runtime generate --config dsl/agent-runtime.config.yaml"\n\nRun: npm run dsl:generate\n\nThis produces src/generated/dsl/ containing:\n- agents.ts (AgentContract interface + agentRegistry)\n- tasks.ts (TaskContract interface + taskRegistry)\n- workflows.ts (WorkflowContract + workflowRegistry)\n- handoffs.ts (Zod schemas + handoffSchemas + factory functions)\n- index.ts (barrel re-exports)\n\n### Step 5: Implement src/agents/ Module\n\n**src/agents/types.ts**:\n\n import type { {ResultType} } from "../generated/dsl/handoffs.js";\n\n export type TaskId = "{task-1}" | "{task-2}" | ...;\n\n export interface AgentConfig {\n adapter?: string;\n model?: string;\n temperature?: number;\n }\n\n export interface AgentOptions {\n dryRun?: boolean;\n failOn?: "warning" | "error" | "critical";\n }\n\n export interface AgentRunResult {\n taskId: TaskId;\n data: {ResultType} | null;\n raw: string;\n prompt: string;\n dryRun: boolean;\n status: "success" | "error" | "escalation" | "validation_error";\n errorMessage?: string;\n followUpsUsed: number;\n retriesUsed: number;\n }\n\n**src/agents/orchestrator.ts**:\n\n export const EXIT_RUNTIME_MISSING = 11;\n export const EXIT_ADAPTER_ERROR = 12;\n\n async function createAdapter(pkg: string, name: string, config: AgentConfig) {\n switch (name) {\n case "mock": {\n const m = await import(`${pkg}/adapters/mock`);\n return new m.MockAdapter();\n }\n case "cursor": {\n const m = await import(`${pkg}/adapters/cursor-sdk`);\n return m.CursorSdkAdapter.create({ apiKey: process.env.CURSOR_API_KEY, model: config.model });\n }\n case "claude": {\n const m = await import(`${pkg}/adapters/claude-agent-sdk`);\n return new m.ClaudeAgentSdkAdapter({ model: config.model });\n }\n case "openai": {\n const m = await import(`${pkg}/adapters/openai-agents-sdk`);\n return new m.OpenAIAgentsSdkAdapter({ model: config.model });\n }\n case "gemini": {\n const m = await import(`${pkg}/adapters/gemini-sdk`);\n return new m.GeminiSdkAdapter({ apiKey: process.env.GEMINI_API_KEY, model: config.model });\n }\n }\n }\n\n export async function runAgentTask(\n userRequest: string, taskId: TaskId, config: AgentConfig, options: AgentOptions,\n ): Promise<AgentRunResult> {\n if (options.dryRun) return { taskId, data:null, raw:"", prompt:userRequest, dryRun:true, status:"success", followUpsUsed:0, retriesUsed:0 };\n\n const PKG = "agent-contracts-runtime";\n let runTask;\n try { ({ runTask } = await import(PKG)); }\n catch { throw Object.assign(new Error("agent-contracts-runtime not installed"), { exitCode: EXIT_RUNTIME_MISSING }); }\n\n let registries;\n try {\n const dsl = await import("../generated/dsl/index.js");\n registries = { agentRegistry: dsl.agentRegistry, taskRegistry: dsl.taskRegistry, handoffSchemas: dsl.handoffSchemas };\n } catch { registries = { agentRegistry:{}, taskRegistry:{}, handoffSchemas:{} }; }\n\n const adapter = await createAdapter(PKG, config.adapter ?? "mock", config);\n const result = await runTask(adapter, taskId, { user_request: userRequest }, { maxFollowUps:3, maxRetries:1, ...registries });\n // map result.outcome to AgentRunResult\n }\n\n**src/agents/context-builder.ts**:\n\n export function build{Command}Context(target, config): string {\n const sections = [];\n sections.push("# {Command} Request");\n sections.push(`## Target\\n\\n${target}`);\n sections.push("## Instructions\\n\\n{domain-specific instructions}");\n // Cap total context at 16KB\n return sections.join("\\n\\n");\n }\n\n**src/agents/formatter.ts**:\n\n export function computeExitCode(result, options): number {\n if (result.dryRun) return 0;\n if (result.status !== "success") return 1;\n const order = ["info","warning","error","critical"];\n const threshold = order.indexOf(options.failOn ?? "error");\n return result.data.findings.some(f => order.indexOf(f.severity) >= threshold) ? 10 : 0;\n }\n\n export function formatResultText(result): string { /* severity icons, structured output */ }\n export function formatResultJson(result): string { return JSON.stringify(result.data, null, 2); }\n\n### Step 6: Create CLI Command Handlers\n\nFor each LLM command, create src/commands/{command}.ts:\n\n export async function command{Name}(config, target, opts) {\n const context = build{Name}Context(target, config);\n const result = await runAgentTask(context, "{task-id}", agentConfig, agentOpts);\n if (opts.reportFormat === "json") console.log(formatResultJson(result));\n else console.log(formatResultText(result));\n process.exit(computeExitCode(result, opts));\n }\n\nRegister in the CLI using Commander or the project\'s existing pattern.\n\n### Step 7: Update cli-contract.yaml\n\nAdd each LLM command with standard options and x-agent metadata:\n\n {command-name}:\n summary: "{Command summary}"\n arguments: [...]\n options:\n - name: adapter\n schema: { type: string, enum: [mock, cursor, claude, openai, gemini] }\n - name: model\n schema: { type: string }\n - name: dry-run\n schema: { type: boolean, default: false }\n - name: fail-on\n schema: { type: string, enum: [warning, error, critical], default: error }\n - name: output\n aliases: [o]\n schema: { type: string }\n file: { mode: write }\n - name: report-format\n schema: { type: string, enum: [json, text, yaml], default: json }\n x-agent:\n riskLevel: low\n requiresConfirmation: false\n idempotent: true\n sideEffects: [network]\n sideEffectNote: >-\n Network calls to LLM provider when adapter is not mock.\n Filesystem write only when --output is specified.\n safeDryRunOption: dry-run\n expectedDurationMs: 120000\n retryableExitCodes: [1, 12]\n exits:\n \'0\': { description: "No blocking findings.", stdout: { format: json, schema: { $ref: \'...\' } } }\n \'1\': { description: "General error.", stderr: { format: text } }\n \'3\': { description: "Input validation failed.", stderr: { format: json } }\n \'10\': { description: "Blocking findings detected.", stdout: { format: json, schema: { $ref: \'...\' } } }\n \'11\': { description: "Runtime not installed.", stderr: { format: json } }\n \'12\': { description: "Adapter error.", stderr: { format: json } }\n\nAdd AgentAuditResult, AgentFinding, AgentRecommendedAction, AgentEvidence\nto components/schemas if not already present.\n\n### Step 8: Update README\n\nAdd "Agent-Native Toolchain" section after mechanical features:\n- Intro: tool encapsulates domain-specific semantic reasoning\n- Deterministic checks first, then semantic audit\n- Structured findings (AgentAuditResult/AgentFinding)\n- LLM Adapter Configuration table\n- Add agent-contracts-runtime, agent-contracts, cli-contracts to Technology Stack\n',
|
|
598
|
+
target_agent: "llm-feature-implementer",
|
|
599
|
+
allowed_from_agents: [
|
|
600
|
+
"llm-feature-implementer"
|
|
601
|
+
],
|
|
602
|
+
workflow: "implement-llm-feature",
|
|
603
|
+
invocation_handoff: "implement-request",
|
|
604
|
+
result_handoff: "implementation-result",
|
|
605
|
+
input_artifacts: [],
|
|
606
|
+
responsibilities: [
|
|
607
|
+
"Analyze the target project and determine the right LLM commands to add",
|
|
608
|
+
"Create all DSL definition files with correct cross-references",
|
|
609
|
+
"Generate TypeScript contracts via agent-runtime generate",
|
|
610
|
+
"Implement the complete src/agents/ module following the exact patterns",
|
|
611
|
+
"Create CLI command handlers integrating with the project's existing CLI structure",
|
|
612
|
+
"Update cli-contract.yaml with proper x-agent metadata and component schemas",
|
|
613
|
+
"Ensure the implementation compiles and --dry-run mode works"
|
|
614
|
+
],
|
|
615
|
+
completion_criteria: [
|
|
616
|
+
"dsl/ directory contains valid DSL definitions that pass agent-runtime generate",
|
|
617
|
+
"agent-runtime.config.yaml points to the DSL with correct generated_dir",
|
|
618
|
+
"src/generated/dsl/ contains generated contracts (agentRegistry, taskRegistry, handoffSchemas, workflowRegistry)",
|
|
619
|
+
"src/agents/orchestrator.ts uses runTask from agent-contracts-runtime (no direct adapter.send calls)",
|
|
620
|
+
"src/agents/orchestrator.ts dynamic-imports the runtime and adapters with correct exit codes (11, 12)",
|
|
621
|
+
"src/agents/context-builder.ts caps input at 16KB",
|
|
622
|
+
"src/agents/formatter.ts implements computeExitCode with the standard exit code mapping",
|
|
623
|
+
"src/commands/ has a handler for each new LLM command",
|
|
624
|
+
"cli-contract.yaml has all new commands with --adapter, --model, --dry-run, --fail-on, --output, --report-format options",
|
|
625
|
+
"cli-contract.yaml has x-agent metadata on each new command (riskLevel, safeDryRunOption, expectedDurationMs)",
|
|
626
|
+
"components/schemas includes AgentAuditResult and related schemas",
|
|
627
|
+
"All generated TypeScript compiles without type errors",
|
|
628
|
+
"--dry-run returns the constructed prompt without calling the LLM"
|
|
629
|
+
],
|
|
630
|
+
optional: false
|
|
631
|
+
};
|
|
632
|
+
var auditDsl = {
|
|
633
|
+
id: "audit-dsl",
|
|
634
|
+
description: "Audit the DSL layer of an LLM command integration.\n\nVerify these files exist and are well-formed:\n- dsl/{project}-dsl.yaml \u2014 must have version:1, system:{id,name},\n agents/tasks/handoff_types via $ref\n- dsl/agents/*.yaml \u2014 each agent has role_name, purpose, mode,\n can_read_artifacts:[], can_write_artifacts:[], responsibilities,\n constraints, rules with R-PREFIX-NNN\n- dsl/tasks.yaml \u2014 target_agent, workflow, result_handoff all\n cross-reference valid IDs\n- dsl/handoff-types.yaml \u2014 version:1, schema with JSON Schema,\n result types follow AgentAuditResult shape\n- dsl/agent-runtime.config.yaml \u2014 dsl and generated_dir fields\n\nSeverity classification:\n- critical: missing version:1 or system block (generator will fail)\n- critical: task references non-existent agent or workflow\n- error: agent missing constraints or rules\n- error: handoff schema not following AgentAuditResult shape\n- warning: missing guardrails or guardrail_policies\n- warning: agent has no escalation_criteria\n\nCategory vocabulary: dsl-structure, dsl-agent, dsl-task,\ndsl-handoff, dsl-workflow, dsl-guardrail.\n\nOutput a partial audit-result with findings only from the DSL layer.\n",
|
|
635
|
+
target_agent: "implementation-auditor",
|
|
636
|
+
allowed_from_agents: [
|
|
637
|
+
"implementation-auditor"
|
|
638
|
+
],
|
|
639
|
+
workflow: "audit-implementation",
|
|
640
|
+
invocation_handoff: "audit-request",
|
|
641
|
+
result_handoff: "audit-result",
|
|
642
|
+
input_artifacts: [],
|
|
643
|
+
responsibilities: [
|
|
644
|
+
"Check all DSL files for structural correctness",
|
|
645
|
+
"Validate cross-references (agent\u2194task\u2194workflow\u2194handoff)",
|
|
646
|
+
"Verify guardrails and guardrail_policies"
|
|
647
|
+
],
|
|
648
|
+
completion_criteria: [
|
|
649
|
+
"Every dsl/* file checked for required fields",
|
|
650
|
+
"Cross-references validated",
|
|
651
|
+
"Findings use dsl-* category vocabulary"
|
|
652
|
+
],
|
|
653
|
+
optional: false
|
|
654
|
+
};
|
|
655
|
+
var auditRuntime = {
|
|
656
|
+
id: "audit-runtime",
|
|
657
|
+
description: "Audit the runtime integration layer of an LLM command integration.\n\nScan src/agents/orchestrator.ts (or equivalent runtime module):\n\nCRITICAL violations (category: runtime-orchestrator):\n- adapter.send() or adapter.sendExecution() called directly\n- adapter.followUp() called directly\n- Custom adapter class defined (not imported from runtime)\n- runTask/runWorkflow not imported from agent-contracts-runtime\n\nERROR violations (category: runtime-registry):\n- Generated registries not imported from src/generated/dsl/\n- Registries not passed to runTask/runWorkflow options\n- Hard-coded agent/task definitions instead of registry lookup\n\nERROR violations (category: runtime-adapter):\n- Adapter packages imported statically (not dynamic import)\n- Missing exit code 11 when runtime import fails\n- Missing exit code 12 when adapter creation fails\n- CursorSdkAdapter created with constructor (must use static .create())\n\nWARNING violations (category: runtime-plugin):\n- Plugin hooks explicitly bypassed or ignored\n\nCategory vocabulary: runtime-orchestrator, runtime-registry,\nruntime-adapter, runtime-plugin.\n\nOutput a partial audit-result with findings only from the runtime layer.\n",
|
|
658
|
+
target_agent: "implementation-auditor",
|
|
659
|
+
allowed_from_agents: [
|
|
660
|
+
"implementation-auditor"
|
|
661
|
+
],
|
|
662
|
+
workflow: "audit-implementation",
|
|
663
|
+
invocation_handoff: "audit-request",
|
|
664
|
+
result_handoff: "audit-result",
|
|
665
|
+
input_artifacts: [],
|
|
666
|
+
responsibilities: [
|
|
667
|
+
"Scan orchestrator code for direct adapter usage",
|
|
668
|
+
"Verify registry imports and passing",
|
|
669
|
+
"Check adapter creation patterns and exit codes"
|
|
670
|
+
],
|
|
671
|
+
completion_criteria: [
|
|
672
|
+
"All orchestrator files scanned for adapter.send / adapter.followUp",
|
|
673
|
+
"Registry usage verified",
|
|
674
|
+
"Exit code 11/12 patterns checked"
|
|
675
|
+
],
|
|
676
|
+
optional: false
|
|
677
|
+
};
|
|
678
|
+
var auditCliContract = {
|
|
679
|
+
id: "audit-cli-contract",
|
|
680
|
+
description: "Audit the CLI contract layer of an LLM command integration.\n\nParse cli-contract.yaml and check each LLM command:\n\nERROR: missing standard options (category: cli-contract-options):\n- --adapter, --model, --dry-run, --fail-on, --output, --report-format\n- Using --format instead of --report-format for LLM commands\n\nERROR: missing x-agent metadata (category: cli-contract-xagent):\n- No x-agent block on LLM command\n- Missing riskLevel, safeDryRunOption, or expectedDurationMs\n- Using snake_case instead of camelCase for x-agent fields\n\nERROR: wrong exit codes (category: cli-contract-exits):\n- Missing exit 0/1/3/10/11/12 definitions\n- Exit 10 not defined for finding-based commands\n\nWARNING: missing schemas (category: cli-contract-schema):\n- AgentAuditResult not in components/schemas\n- AgentFinding, AgentRecommendedAction, AgentEvidence not defined\n\nCategory vocabulary: cli-contract-options, cli-contract-xagent,\ncli-contract-exits, cli-contract-schema.\n\nOutput a partial audit-result with findings only from the CLI contract layer.\n",
|
|
681
|
+
target_agent: "implementation-auditor",
|
|
682
|
+
allowed_from_agents: [
|
|
683
|
+
"implementation-auditor"
|
|
684
|
+
],
|
|
685
|
+
workflow: "audit-implementation",
|
|
686
|
+
invocation_handoff: "audit-request",
|
|
687
|
+
result_handoff: "audit-result",
|
|
688
|
+
input_artifacts: [],
|
|
689
|
+
responsibilities: [
|
|
690
|
+
"Check each LLM command for standard options",
|
|
691
|
+
"Verify x-agent metadata fields and casing",
|
|
692
|
+
"Validate exit code definitions",
|
|
693
|
+
"Check components/schemas for canonical types"
|
|
694
|
+
],
|
|
695
|
+
completion_criteria: [
|
|
696
|
+
"Every LLM command checked for all 6 standard options",
|
|
697
|
+
"x-agent metadata validated on every LLM command",
|
|
698
|
+
"Exit codes verified against convention",
|
|
699
|
+
"Schema completeness checked"
|
|
700
|
+
],
|
|
701
|
+
optional: false
|
|
702
|
+
};
|
|
703
|
+
var auditArchitecture = {
|
|
704
|
+
id: "audit-architecture",
|
|
705
|
+
description: "Audit the architecture and module structure of an LLM command integration.\n\nVerify module structure (category: architecture-modules):\n- src/agents/types.ts exists with TaskId, AgentConfig, AgentOptions, AgentRunResult\n- src/agents/orchestrator.ts exists\n- src/agents/context-builder.ts exists\n- src/agents/formatter.ts exists with computeExitCode\n\nVerify behavior (category: architecture-dry-run):\n- --dry-run path returns the constructed prompt without calling the adapter\n- buildTaskPrompt is used (not a placeholder string)\n\nVerify patterns (category: architecture-context-builder):\n- Context builder has size cap (16KB or similar)\n\nScan for direct SDK imports (category: architecture-modules):\n- @anthropic-ai/sdk or @anthropic-ai/claude-agent-sdk imported\n outside src/agents/orchestrator.ts or adapter files\n- openai or @openai/agents imported outside adapters\n- @google/genai imported outside adapters\n- @cursor/sdk imported outside adapters\n\nCategory vocabulary: architecture-modules, architecture-dry-run,\narchitecture-context-builder, architecture-formatter.\n\nOutput a partial audit-result with findings only from the architecture layer.\n",
|
|
706
|
+
target_agent: "implementation-auditor",
|
|
707
|
+
allowed_from_agents: [
|
|
708
|
+
"implementation-auditor"
|
|
709
|
+
],
|
|
710
|
+
workflow: "audit-implementation",
|
|
711
|
+
invocation_handoff: "audit-request",
|
|
712
|
+
result_handoff: "audit-result",
|
|
713
|
+
input_artifacts: [],
|
|
714
|
+
responsibilities: [
|
|
715
|
+
"Verify module structure",
|
|
716
|
+
"Check dry-run behavior",
|
|
717
|
+
"Validate context size cap",
|
|
718
|
+
"Scan for direct SDK imports"
|
|
719
|
+
],
|
|
720
|
+
completion_criteria: [
|
|
721
|
+
"Module structure verified",
|
|
722
|
+
"Dry-run behavior confirmed",
|
|
723
|
+
"No direct SDK imports outside adapter files"
|
|
724
|
+
],
|
|
725
|
+
optional: false
|
|
726
|
+
};
|
|
727
|
+
var auditMerge = {
|
|
728
|
+
id: "audit-merge",
|
|
729
|
+
description: 'Merge the partial audit results from the four parallel layer audits\n(DSL, runtime, CLI contract, architecture) into a single unified\naudit-result.\n\nThe prior_context contains the JSON output from each completed\naudit step. Parse each one, combine all findings into a single\narray, deduplicate by (target + message), assign sequential IDs\n(F-001, F-002, ...), derive the overall riskLevel from the worst\nfinding severity, and produce prioritized recommendedActions.\n\nMerging rules:\n- Collect all findings from all layer results\n- Sort: critical first, then error, warning, info\n- Assign sequential IDs: F-001, F-002, ...\n- Deduplicate: if two findings have the same target and message, keep one\n- Derive riskLevel: any critical \u2192 critical, any error \u2192 high,\n any warning \u2192 medium, info only \u2192 low\n- Merge recommendedActions from all layers, deduplicate by title\n- Set metadata: { tool: "agent-runtime", command: "audit-implementation" }\n',
|
|
730
|
+
target_agent: "implementation-auditor",
|
|
731
|
+
allowed_from_agents: [
|
|
732
|
+
"implementation-auditor"
|
|
733
|
+
],
|
|
734
|
+
workflow: "audit-implementation",
|
|
735
|
+
invocation_handoff: "audit-request",
|
|
736
|
+
result_handoff: "audit-result",
|
|
737
|
+
input_artifacts: [],
|
|
738
|
+
responsibilities: [
|
|
739
|
+
"Parse prior_context JSON from each layer audit step",
|
|
740
|
+
"Merge and deduplicate findings",
|
|
741
|
+
"Derive overall riskLevel",
|
|
742
|
+
"Produce a single coherent summary paragraph"
|
|
743
|
+
],
|
|
744
|
+
completion_criteria: [
|
|
745
|
+
"All findings from all layers included",
|
|
746
|
+
"No duplicate findings",
|
|
747
|
+
"riskLevel correctly derived from worst finding",
|
|
748
|
+
"Summary paragraph covers all audited layers"
|
|
749
|
+
],
|
|
750
|
+
optional: false
|
|
751
|
+
};
|
|
752
|
+
var taskRegistry = {
|
|
753
|
+
"implement-llm-feature": implementLlmFeature,
|
|
754
|
+
"audit-dsl": auditDsl,
|
|
755
|
+
"audit-runtime": auditRuntime,
|
|
756
|
+
"audit-cli-contract": auditCliContract,
|
|
757
|
+
"audit-architecture": auditArchitecture,
|
|
758
|
+
"audit-merge": auditMerge
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
// src/builtin-agents/generated/handoffs.ts
|
|
762
|
+
import { z } from "zod";
|
|
763
|
+
var ImplementRequestSchema = z.object({
|
|
764
|
+
description: z.string(),
|
|
765
|
+
project_dir: z.string(),
|
|
766
|
+
reference_doc: z.string().optional()
|
|
767
|
+
});
|
|
768
|
+
var AuditRequestSchema = z.object({
|
|
769
|
+
project_dir: z.string(),
|
|
770
|
+
focus: z.enum(["all", "dsl", "runtime", "cli-contract", "architecture"]).optional()
|
|
771
|
+
});
|
|
772
|
+
var AuditResultSchema = z.object({
|
|
773
|
+
summary: z.string(),
|
|
774
|
+
riskLevel: z.enum(["low", "medium", "high", "critical"]),
|
|
775
|
+
findings: z.array(z.object({
|
|
776
|
+
id: z.string().optional(),
|
|
777
|
+
severity: z.enum(["info", "warning", "error", "critical"]),
|
|
778
|
+
category: z.string(),
|
|
779
|
+
target: z.string().optional(),
|
|
780
|
+
location: z.string().optional(),
|
|
781
|
+
message: z.string(),
|
|
782
|
+
recommendation: z.string().optional(),
|
|
783
|
+
confidence: z.number().optional()
|
|
784
|
+
})),
|
|
785
|
+
recommendedActions: z.array(z.object({
|
|
786
|
+
kind: z.enum(["run_command", "edit_file", "review", "confirm", "block", "ignore"]),
|
|
787
|
+
title: z.string(),
|
|
788
|
+
command: z.string().optional(),
|
|
789
|
+
target: z.string().optional(),
|
|
790
|
+
rationale: z.string().optional()
|
|
791
|
+
})).optional(),
|
|
792
|
+
metadata: z.object({
|
|
793
|
+
tool: z.string().optional(),
|
|
794
|
+
command: z.string().optional(),
|
|
795
|
+
version: z.string().optional(),
|
|
796
|
+
generatedAt: z.string().optional(),
|
|
797
|
+
adapter: z.string().optional(),
|
|
798
|
+
model: z.string().optional()
|
|
799
|
+
}).optional()
|
|
800
|
+
});
|
|
801
|
+
var ImplementationResultSchema = z.object({
|
|
802
|
+
files_created: z.array(z.string()),
|
|
803
|
+
files_modified: z.array(z.string()),
|
|
804
|
+
summary: z.string(),
|
|
805
|
+
commands_added: z.array(z.object({
|
|
806
|
+
name: z.string(),
|
|
807
|
+
type: z.enum(["audit", "propose", "explain"]),
|
|
808
|
+
description: z.string().optional()
|
|
809
|
+
})).optional(),
|
|
810
|
+
next_steps: z.array(z.string()).optional()
|
|
811
|
+
});
|
|
812
|
+
var handoffSchemas = {
|
|
813
|
+
"implement-request": ImplementRequestSchema,
|
|
814
|
+
"audit-request": AuditRequestSchema,
|
|
815
|
+
"audit-result": AuditResultSchema,
|
|
816
|
+
"implementation-result": ImplementationResultSchema
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
// src/builtin-agents/generated/workflows.ts
|
|
820
|
+
var implementLlmFeature2 = {
|
|
821
|
+
id: "implement-llm-feature",
|
|
822
|
+
description: "Implement LLM-powered commands in a CLI tool",
|
|
823
|
+
trigger: "cli-command",
|
|
824
|
+
entry_conditions: [
|
|
825
|
+
"Target project is a TypeScript / Node.js project",
|
|
826
|
+
"cli-contract.yaml exists or is being created"
|
|
827
|
+
],
|
|
828
|
+
steps: [
|
|
829
|
+
{
|
|
830
|
+
type: "delegate",
|
|
831
|
+
task: "implement-llm-feature",
|
|
832
|
+
from_agent: "llm-feature-implementer",
|
|
833
|
+
description: "",
|
|
834
|
+
optional: false,
|
|
835
|
+
max_retries: 0
|
|
836
|
+
}
|
|
837
|
+
]
|
|
838
|
+
};
|
|
839
|
+
var auditImplementation = {
|
|
840
|
+
id: "audit-implementation",
|
|
841
|
+
description: "Audit an LLM command integration for pattern conformance",
|
|
842
|
+
trigger: "cli-command",
|
|
843
|
+
entry_conditions: [
|
|
844
|
+
"Target project has LLM command integration to audit"
|
|
845
|
+
],
|
|
846
|
+
steps: [
|
|
847
|
+
{
|
|
848
|
+
type: "delegate",
|
|
849
|
+
task: "audit-dsl",
|
|
850
|
+
from_agent: "implementation-auditor",
|
|
851
|
+
description: "",
|
|
852
|
+
optional: false,
|
|
853
|
+
max_retries: 0,
|
|
854
|
+
depends_on: []
|
|
855
|
+
},
|
|
856
|
+
{
|
|
857
|
+
type: "delegate",
|
|
858
|
+
task: "audit-runtime",
|
|
859
|
+
from_agent: "implementation-auditor",
|
|
860
|
+
description: "",
|
|
861
|
+
optional: false,
|
|
862
|
+
max_retries: 0,
|
|
863
|
+
depends_on: []
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
type: "delegate",
|
|
867
|
+
task: "audit-cli-contract",
|
|
868
|
+
from_agent: "implementation-auditor",
|
|
869
|
+
description: "",
|
|
870
|
+
optional: false,
|
|
871
|
+
max_retries: 0,
|
|
872
|
+
depends_on: []
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
type: "delegate",
|
|
876
|
+
task: "audit-architecture",
|
|
877
|
+
from_agent: "implementation-auditor",
|
|
878
|
+
description: "",
|
|
879
|
+
optional: false,
|
|
880
|
+
max_retries: 0,
|
|
881
|
+
depends_on: []
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
type: "delegate",
|
|
885
|
+
task: "audit-merge",
|
|
886
|
+
from_agent: "implementation-auditor",
|
|
887
|
+
description: "",
|
|
888
|
+
optional: false,
|
|
889
|
+
max_retries: 0,
|
|
890
|
+
depends_on: [
|
|
891
|
+
"audit-dsl",
|
|
892
|
+
"audit-runtime",
|
|
893
|
+
"audit-cli-contract",
|
|
894
|
+
"audit-architecture"
|
|
895
|
+
]
|
|
896
|
+
}
|
|
897
|
+
]
|
|
898
|
+
};
|
|
899
|
+
var workflowRegistry = {
|
|
900
|
+
"implement-llm-feature": implementLlmFeature2,
|
|
901
|
+
"audit-implementation": auditImplementation
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
// src/lib/implement.ts
|
|
905
|
+
function getLocale() {
|
|
906
|
+
return process.env.LANG?.split(".")[0] ?? process.env.LC_ALL?.split(".")[0] ?? process.env.LANGUAGE?.split(":")[0] ?? "en_US";
|
|
907
|
+
}
|
|
908
|
+
function isJapanese() {
|
|
909
|
+
return getLocale().startsWith("ja");
|
|
910
|
+
}
|
|
911
|
+
var en = {
|
|
912
|
+
noProjectDir: (dir) => `Project directory not found: ${dir}`,
|
|
913
|
+
adapterError: (msg3) => `Adapter initialization failed: ${msg3}`,
|
|
914
|
+
dryRunHeader: "=== Dry Run ===",
|
|
915
|
+
dryRunProjectDir: (dir) => `Project: ${dir}`,
|
|
916
|
+
dryRunDescription: (desc) => `Description: ${desc}`,
|
|
917
|
+
dryRunRefIncluded: "Reference: integrate-llm-commands (included)",
|
|
918
|
+
dryRunRefNotFound: "Reference: integrate-llm-commands (not found, will proceed without)",
|
|
919
|
+
implementStarting: (adapter) => `Starting implementation with ${adapter} adapter...`,
|
|
920
|
+
implementSuccess: "Implementation completed successfully.",
|
|
921
|
+
implementFailed: (reason) => `Implementation failed: ${reason}`,
|
|
922
|
+
filesCreated: "Files created:",
|
|
923
|
+
filesModified: "Files modified:",
|
|
924
|
+
commandsAdded: "Commands added:",
|
|
925
|
+
nextSteps: "Next steps:"
|
|
926
|
+
};
|
|
927
|
+
var ja = {
|
|
928
|
+
noProjectDir: (dir) => `\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${dir}`,
|
|
929
|
+
adapterError: (msg3) => `\u30A2\u30C0\u30D7\u30BF\u30FC\u521D\u671F\u5316\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${msg3}`,
|
|
930
|
+
dryRunHeader: "=== \u30C9\u30E9\u30A4\u30E9\u30F3 ===",
|
|
931
|
+
dryRunProjectDir: (dir) => `\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8: ${dir}`,
|
|
932
|
+
dryRunDescription: (desc) => `\u8AAC\u660E: ${desc}`,
|
|
933
|
+
dryRunRefIncluded: "\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9: integrate-llm-commands\uFF08\u542B\u307E\u308C\u3066\u3044\u307E\u3059\uFF09",
|
|
934
|
+
dryRunRefNotFound: "\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9: integrate-llm-commands\uFF08\u672A\u691C\u51FA\u3001\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9\u306A\u3057\u3067\u7D9A\u884C\uFF09",
|
|
935
|
+
implementStarting: (adapter) => `${adapter} \u30A2\u30C0\u30D7\u30BF\u30FC\u3067\u5B9F\u88C5\u3092\u958B\u59CB\u3057\u307E\u3059...`,
|
|
936
|
+
implementSuccess: "\u5B9F\u88C5\u304C\u6B63\u5E38\u306B\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002",
|
|
937
|
+
implementFailed: (reason) => `\u5B9F\u88C5\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${reason}`,
|
|
938
|
+
filesCreated: "\u4F5C\u6210\u3055\u308C\u305F\u30D5\u30A1\u30A4\u30EB:",
|
|
939
|
+
filesModified: "\u5909\u66F4\u3055\u308C\u305F\u30D5\u30A1\u30A4\u30EB:",
|
|
940
|
+
commandsAdded: "\u8FFD\u52A0\u3055\u308C\u305F\u30B3\u30DE\u30F3\u30C9:",
|
|
941
|
+
nextSteps: "\u6B21\u306E\u30B9\u30C6\u30C3\u30D7:"
|
|
942
|
+
};
|
|
943
|
+
function msg() {
|
|
944
|
+
return isJapanese() ? ja : en;
|
|
945
|
+
}
|
|
946
|
+
function loadReferenceDoc() {
|
|
947
|
+
const candidates = [
|
|
948
|
+
// Shipped with the package (templates/ sibling of dist/)
|
|
949
|
+
join3(fileURLToPath(import.meta.url), "..", "..", "..", "templates", "implement-reference.md"),
|
|
950
|
+
// Dev-time: from the skill directory
|
|
951
|
+
join3(process.env.HOME ?? "", ".cursor", "skills", "integrate-llm-commands", "SKILL.md")
|
|
952
|
+
];
|
|
953
|
+
for (const candidate of candidates) {
|
|
954
|
+
try {
|
|
955
|
+
if (existsSync3(candidate)) {
|
|
956
|
+
return readFileSync(candidate, "utf8");
|
|
957
|
+
}
|
|
958
|
+
} catch {
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return void 0;
|
|
962
|
+
}
|
|
963
|
+
async function createImplementAdapter(adapterName, projectDir, model) {
|
|
964
|
+
switch (adapterName) {
|
|
965
|
+
case "claude": {
|
|
966
|
+
const { ClaudeAgentSdkAdapter } = await import("../adapters/claude-agent-sdk.js");
|
|
967
|
+
return new ClaudeAgentSdkAdapter({
|
|
968
|
+
cwd: projectDir,
|
|
969
|
+
permissionMode: "bypassPermissions",
|
|
970
|
+
model
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
case "cursor": {
|
|
974
|
+
const { CursorSdkAdapter } = await import("../adapters/cursor-sdk.js");
|
|
975
|
+
const apiKey = process.env.CURSOR_API_KEY;
|
|
976
|
+
if (!apiKey) {
|
|
977
|
+
throw new Error("CURSOR_API_KEY environment variable is required for the cursor adapter");
|
|
978
|
+
}
|
|
979
|
+
return CursorSdkAdapter.create({ apiKey, cwd: projectDir, model });
|
|
980
|
+
}
|
|
981
|
+
case "mock": {
|
|
982
|
+
const { MockAdapter } = await import("../adapters/mock.js");
|
|
983
|
+
return new MockAdapter();
|
|
984
|
+
}
|
|
985
|
+
default:
|
|
986
|
+
throw new Error(
|
|
987
|
+
`Unsupported adapter for implement: "${adapterName}". Available: claude, cursor, mock`
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
async function runImplement(description, options) {
|
|
992
|
+
const m = msg();
|
|
993
|
+
const projectDir = resolve2(options.projectDir);
|
|
994
|
+
if (!existsSync3(projectDir)) {
|
|
995
|
+
return { status: "failed", exitCode: 3, error: m.noProjectDir(projectDir) };
|
|
996
|
+
}
|
|
997
|
+
const referenceDoc = loadReferenceDoc();
|
|
998
|
+
const userRequest = [
|
|
999
|
+
description,
|
|
1000
|
+
"",
|
|
1001
|
+
`Project directory: ${projectDir}`
|
|
1002
|
+
].join("\n");
|
|
1003
|
+
const context = {
|
|
1004
|
+
user_request: userRequest,
|
|
1005
|
+
relevant_paths: [projectDir]
|
|
1006
|
+
};
|
|
1007
|
+
if (referenceDoc) {
|
|
1008
|
+
context.prior_context = "# Reference: integrate-llm-commands pattern\n\nFollow this reference exactly when implementing LLM commands.\n\n" + referenceDoc;
|
|
1009
|
+
}
|
|
1010
|
+
if (options.dryRun) {
|
|
1011
|
+
const agent = agentRegistry["llm-feature-implementer"];
|
|
1012
|
+
const task = taskRegistry["implement-llm-feature"];
|
|
1013
|
+
const prompt = buildTaskPrompt(agent, task, context, { handoffSchemas });
|
|
1014
|
+
return {
|
|
1015
|
+
status: "dry_run",
|
|
1016
|
+
exitCode: 0,
|
|
1017
|
+
data: {
|
|
1018
|
+
files_created: [],
|
|
1019
|
+
files_modified: [],
|
|
1020
|
+
summary: prompt
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
let adapter;
|
|
1025
|
+
try {
|
|
1026
|
+
adapter = await createImplementAdapter(options.adapter, projectDir, options.model);
|
|
1027
|
+
} catch (err) {
|
|
1028
|
+
return { status: "failed", exitCode: 12, error: m.adapterError(err.message) };
|
|
1029
|
+
}
|
|
1030
|
+
if (!options.verbose) {
|
|
1031
|
+
console.error(m.implementStarting(options.adapter));
|
|
1032
|
+
}
|
|
1033
|
+
const registries = {
|
|
1034
|
+
workflowRegistry,
|
|
1035
|
+
taskRegistry,
|
|
1036
|
+
agentRegistry,
|
|
1037
|
+
handoffSchemas
|
|
1038
|
+
};
|
|
1039
|
+
const invocation = {
|
|
1040
|
+
workflow: "implement-llm-feature",
|
|
1041
|
+
user_request: userRequest,
|
|
1042
|
+
runtime: {
|
|
1043
|
+
maxFollowUps: 3,
|
|
1044
|
+
maxRetries: 1
|
|
1045
|
+
},
|
|
1046
|
+
hooks: {
|
|
1047
|
+
onGate: async () => true
|
|
1048
|
+
},
|
|
1049
|
+
context: {
|
|
1050
|
+
cwd: projectDir
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
const result = await runWorkflow(adapter, invocation, registries);
|
|
1054
|
+
if (result.status !== "completed") {
|
|
1055
|
+
const reason = result.escalation_reason ?? result.error_message ?? result.status;
|
|
1056
|
+
return { status: "failed", exitCode: 1, error: m.implementFailed(reason) };
|
|
1057
|
+
}
|
|
1058
|
+
const lastStep = result.steps[result.steps.length - 1];
|
|
1059
|
+
const outcomeData = lastStep?.outcome?.data;
|
|
1060
|
+
return {
|
|
1061
|
+
status: "success",
|
|
1062
|
+
exitCode: 0,
|
|
1063
|
+
data: outcomeData ?? {
|
|
1064
|
+
files_created: [],
|
|
1065
|
+
files_modified: [],
|
|
1066
|
+
summary: m.implementSuccess
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
function formatImplementResult(result) {
|
|
1071
|
+
const m = msg();
|
|
1072
|
+
if (result.status === "dry_run") {
|
|
1073
|
+
return result.data?.summary ?? m.dryRunHeader;
|
|
1074
|
+
}
|
|
1075
|
+
if (result.status === "failed") {
|
|
1076
|
+
return result.error ?? m.implementFailed("unknown");
|
|
1077
|
+
}
|
|
1078
|
+
const data = result.data;
|
|
1079
|
+
if (!data) return m.implementSuccess;
|
|
1080
|
+
const lines = [data.summary, ""];
|
|
1081
|
+
if (data.files_created.length > 0) {
|
|
1082
|
+
lines.push(m.filesCreated);
|
|
1083
|
+
for (const f of data.files_created) lines.push(` + ${f}`);
|
|
1084
|
+
lines.push("");
|
|
1085
|
+
}
|
|
1086
|
+
if (data.files_modified.length > 0) {
|
|
1087
|
+
lines.push(m.filesModified);
|
|
1088
|
+
for (const f of data.files_modified) lines.push(` ~ ${f}`);
|
|
1089
|
+
lines.push("");
|
|
1090
|
+
}
|
|
1091
|
+
if (data.commands_added && data.commands_added.length > 0) {
|
|
1092
|
+
lines.push(m.commandsAdded);
|
|
1093
|
+
for (const c of data.commands_added) {
|
|
1094
|
+
lines.push(` - ${c.name} [${c.type}]${c.description ? ` \u2014 ${c.description}` : ""}`);
|
|
1095
|
+
}
|
|
1096
|
+
lines.push("");
|
|
1097
|
+
}
|
|
1098
|
+
if (data.next_steps && data.next_steps.length > 0) {
|
|
1099
|
+
lines.push(m.nextSteps);
|
|
1100
|
+
for (const s of data.next_steps) lines.push(` ${s}`);
|
|
1101
|
+
}
|
|
1102
|
+
return lines.join("\n");
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// src/lib/audit-implementation.ts
|
|
1106
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1107
|
+
import { resolve as resolve3 } from "path";
|
|
1108
|
+
function getLocale2() {
|
|
1109
|
+
return process.env.LANG?.split(".")[0] ?? process.env.LC_ALL?.split(".")[0] ?? process.env.LANGUAGE?.split(":")[0] ?? "en_US";
|
|
1110
|
+
}
|
|
1111
|
+
function isJapanese2() {
|
|
1112
|
+
return getLocale2().startsWith("ja");
|
|
1113
|
+
}
|
|
1114
|
+
var en2 = {
|
|
1115
|
+
noProjectDir: (dir) => `Project directory not found: ${dir}`,
|
|
1116
|
+
adapterError: (msg3) => `Adapter initialization failed: ${msg3}`,
|
|
1117
|
+
dryRunHeader: "=== Dry Run (audit-implementation) ===",
|
|
1118
|
+
dryRunProjectDir: (dir) => `Project: ${dir}`,
|
|
1119
|
+
dryRunFocus: (focus) => `Focus: ${focus}`,
|
|
1120
|
+
auditStarting: (adapter) => `Starting audit with ${adapter} adapter...`,
|
|
1121
|
+
auditSuccess: "Audit completed.",
|
|
1122
|
+
auditFailed: (reason) => `Audit failed: ${reason}`,
|
|
1123
|
+
riskLevel: (level) => `Risk level: ${level}`,
|
|
1124
|
+
findingsHeader: (count) => `Findings (${count}):`,
|
|
1125
|
+
noFindings: "No findings.",
|
|
1126
|
+
recommendedActionsHeader: "Recommended actions:"
|
|
1127
|
+
};
|
|
1128
|
+
var ja2 = {
|
|
1129
|
+
noProjectDir: (dir) => `\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${dir}`,
|
|
1130
|
+
adapterError: (msg3) => `\u30A2\u30C0\u30D7\u30BF\u30FC\u521D\u671F\u5316\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${msg3}`,
|
|
1131
|
+
dryRunHeader: "=== \u30C9\u30E9\u30A4\u30E9\u30F3 (audit-implementation) ===",
|
|
1132
|
+
dryRunProjectDir: (dir) => `\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8: ${dir}`,
|
|
1133
|
+
dryRunFocus: (focus) => `\u30D5\u30A9\u30FC\u30AB\u30B9: ${focus}`,
|
|
1134
|
+
auditStarting: (adapter) => `${adapter} \u30A2\u30C0\u30D7\u30BF\u30FC\u3067\u76E3\u67FB\u3092\u958B\u59CB\u3057\u307E\u3059...`,
|
|
1135
|
+
auditSuccess: "\u76E3\u67FB\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002",
|
|
1136
|
+
auditFailed: (reason) => `\u76E3\u67FB\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${reason}`,
|
|
1137
|
+
riskLevel: (level) => `\u30EA\u30B9\u30AF\u30EC\u30D9\u30EB: ${level}`,
|
|
1138
|
+
findingsHeader: (count) => `\u691C\u51FA\u4E8B\u9805 (${count}\u4EF6):`,
|
|
1139
|
+
noFindings: "\u691C\u51FA\u4E8B\u9805\u306F\u3042\u308A\u307E\u305B\u3093\u3002",
|
|
1140
|
+
recommendedActionsHeader: "\u63A8\u5968\u30A2\u30AF\u30B7\u30E7\u30F3:"
|
|
1141
|
+
};
|
|
1142
|
+
function msg2() {
|
|
1143
|
+
return isJapanese2() ? ja2 : en2;
|
|
1144
|
+
}
|
|
1145
|
+
async function createAuditAdapter(adapterName, projectDir, model) {
|
|
1146
|
+
switch (adapterName) {
|
|
1147
|
+
case "claude": {
|
|
1148
|
+
const { ClaudeAgentSdkAdapter } = await import("../adapters/claude-agent-sdk.js");
|
|
1149
|
+
return new ClaudeAgentSdkAdapter({
|
|
1150
|
+
cwd: projectDir,
|
|
1151
|
+
model
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
case "cursor": {
|
|
1155
|
+
const { CursorSdkAdapter } = await import("../adapters/cursor-sdk.js");
|
|
1156
|
+
const apiKey = process.env.CURSOR_API_KEY;
|
|
1157
|
+
if (!apiKey) {
|
|
1158
|
+
throw new Error("CURSOR_API_KEY environment variable is required for the cursor adapter");
|
|
1159
|
+
}
|
|
1160
|
+
return CursorSdkAdapter.create({ apiKey, cwd: projectDir, model });
|
|
1161
|
+
}
|
|
1162
|
+
case "mock": {
|
|
1163
|
+
const { MockAdapter } = await import("../adapters/mock.js");
|
|
1164
|
+
return new MockAdapter();
|
|
1165
|
+
}
|
|
1166
|
+
default:
|
|
1167
|
+
throw new Error(
|
|
1168
|
+
`Unsupported adapter for audit-implementation: "${adapterName}". Available: claude, cursor, mock`
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
var SEVERITY_ORDER = {
|
|
1173
|
+
info: 0,
|
|
1174
|
+
warning: 1,
|
|
1175
|
+
error: 2,
|
|
1176
|
+
critical: 3
|
|
1177
|
+
};
|
|
1178
|
+
function hasFindings(result, failOn) {
|
|
1179
|
+
const threshold = SEVERITY_ORDER[failOn] ?? 2;
|
|
1180
|
+
return result.findings.some(
|
|
1181
|
+
(f) => (SEVERITY_ORDER[f.severity] ?? 0) >= threshold
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
async function runAuditImplementation(options) {
|
|
1185
|
+
const m = msg2();
|
|
1186
|
+
const projectDir = resolve3(options.projectDir);
|
|
1187
|
+
if (!existsSync4(projectDir)) {
|
|
1188
|
+
return { status: "failed", exitCode: 3, error: m.noProjectDir(projectDir) };
|
|
1189
|
+
}
|
|
1190
|
+
const focusInstruction = options.focus !== "all" ? `
|
|
1191
|
+
|
|
1192
|
+
Focus the audit on the "${options.focus}" layer only.` : "";
|
|
1193
|
+
const userRequest = [
|
|
1194
|
+
`Audit the LLM command integration in the following project.`,
|
|
1195
|
+
`Project directory: ${projectDir}`,
|
|
1196
|
+
focusInstruction
|
|
1197
|
+
].join("\n");
|
|
1198
|
+
const context = {
|
|
1199
|
+
user_request: userRequest,
|
|
1200
|
+
relevant_paths: [projectDir]
|
|
1201
|
+
};
|
|
1202
|
+
if (options.dryRun) {
|
|
1203
|
+
const agent = agentRegistry["implementation-auditor"];
|
|
1204
|
+
const auditTasks = ["audit-dsl", "audit-runtime", "audit-cli-contract", "audit-architecture"];
|
|
1205
|
+
const prompts = auditTasks.map((taskId) => {
|
|
1206
|
+
const task = taskRegistry[taskId];
|
|
1207
|
+
if (!task) return `# [Task not found: ${taskId}]`;
|
|
1208
|
+
return buildTaskPrompt(agent, task, context, { handoffSchemas });
|
|
1209
|
+
});
|
|
1210
|
+
const separator = "\n\n" + "=".repeat(72) + "\n\n";
|
|
1211
|
+
const fullPrompt = prompts.join(separator);
|
|
1212
|
+
return {
|
|
1213
|
+
status: "dry_run",
|
|
1214
|
+
exitCode: 0,
|
|
1215
|
+
data: {
|
|
1216
|
+
summary: fullPrompt,
|
|
1217
|
+
riskLevel: "low",
|
|
1218
|
+
findings: []
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
let adapter;
|
|
1223
|
+
try {
|
|
1224
|
+
adapter = await createAuditAdapter(options.adapter, projectDir, options.model);
|
|
1225
|
+
} catch (err) {
|
|
1226
|
+
return { status: "failed", exitCode: 12, error: m.adapterError(err.message) };
|
|
1227
|
+
}
|
|
1228
|
+
console.error(m.auditStarting(options.adapter));
|
|
1229
|
+
const registries = {
|
|
1230
|
+
workflowRegistry,
|
|
1231
|
+
taskRegistry,
|
|
1232
|
+
agentRegistry,
|
|
1233
|
+
handoffSchemas
|
|
1234
|
+
};
|
|
1235
|
+
const invocation = {
|
|
1236
|
+
workflow: "audit-implementation",
|
|
1237
|
+
user_request: userRequest,
|
|
1238
|
+
runtime: {
|
|
1239
|
+
maxFollowUps: 2,
|
|
1240
|
+
maxRetries: 1
|
|
1241
|
+
},
|
|
1242
|
+
hooks: {
|
|
1243
|
+
onGate: async () => true
|
|
1244
|
+
},
|
|
1245
|
+
context: {
|
|
1246
|
+
cwd: projectDir
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
const result = await runWorkflow(adapter, invocation, registries);
|
|
1250
|
+
if (result.status !== "completed") {
|
|
1251
|
+
const reason = result.escalation_reason ?? result.error_message ?? result.status;
|
|
1252
|
+
return { status: "failed", exitCode: 1, error: m.auditFailed(reason) };
|
|
1253
|
+
}
|
|
1254
|
+
const lastStep = result.steps[result.steps.length - 1];
|
|
1255
|
+
const outcomeData = lastStep?.outcome?.data;
|
|
1256
|
+
const auditData = outcomeData ?? {
|
|
1257
|
+
summary: m.auditSuccess,
|
|
1258
|
+
riskLevel: "low",
|
|
1259
|
+
findings: []
|
|
1260
|
+
};
|
|
1261
|
+
const exitCode = hasFindings(auditData, options.failOn) ? 10 : 0;
|
|
1262
|
+
return {
|
|
1263
|
+
status: "success",
|
|
1264
|
+
exitCode,
|
|
1265
|
+
data: auditData
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
var SEVERITY_ICON = {
|
|
1269
|
+
critical: "\u2717",
|
|
1270
|
+
error: "\u2717",
|
|
1271
|
+
warning: "!",
|
|
1272
|
+
info: "\xB7"
|
|
1273
|
+
};
|
|
1274
|
+
function formatAuditResult(result) {
|
|
1275
|
+
const m = msg2();
|
|
1276
|
+
if (result.status === "dry_run") {
|
|
1277
|
+
return result.data?.summary ?? m.dryRunHeader;
|
|
1278
|
+
}
|
|
1279
|
+
if (result.status === "failed") {
|
|
1280
|
+
return result.error ?? m.auditFailed("unknown");
|
|
1281
|
+
}
|
|
1282
|
+
const data = result.data;
|
|
1283
|
+
if (!data) return m.auditSuccess;
|
|
1284
|
+
const lines = [data.summary, ""];
|
|
1285
|
+
lines.push(m.riskLevel(data.riskLevel));
|
|
1286
|
+
lines.push("");
|
|
1287
|
+
if (data.findings.length === 0) {
|
|
1288
|
+
lines.push(m.noFindings);
|
|
1289
|
+
} else {
|
|
1290
|
+
lines.push(m.findingsHeader(data.findings.length));
|
|
1291
|
+
for (const f of data.findings) {
|
|
1292
|
+
const icon = SEVERITY_ICON[f.severity] ?? "\xB7";
|
|
1293
|
+
const id = f.id ? `[${f.id}] ` : "";
|
|
1294
|
+
const target = f.target ? ` (${f.target})` : "";
|
|
1295
|
+
lines.push(` ${icon} ${id}${f.severity.toUpperCase()}: ${f.message}${target}`);
|
|
1296
|
+
if (f.recommendation) {
|
|
1297
|
+
lines.push(` \u2192 ${f.recommendation}`);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
lines.push("");
|
|
1301
|
+
}
|
|
1302
|
+
if (data.recommendedActions && data.recommendedActions.length > 0) {
|
|
1303
|
+
lines.push(m.recommendedActionsHeader);
|
|
1304
|
+
for (const a of data.recommendedActions) {
|
|
1305
|
+
const cmd = a.command ? ` \u2014 ${a.command}` : "";
|
|
1306
|
+
lines.push(` [${a.kind}] ${a.title}${cmd}`);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return lines.join("\n");
|
|
1310
|
+
}
|
|
1311
|
+
|
|
391
1312
|
// src/cli/index.ts
|
|
392
1313
|
import YAML3 from "yaml";
|
|
393
1314
|
register();
|
|
394
|
-
var VERSION = "0.
|
|
1315
|
+
var VERSION = "0.32.1";
|
|
395
1316
|
async function loadGeneratedContracts(configPath) {
|
|
396
1317
|
const config = await loadConfig(configPath);
|
|
397
1318
|
const basePath = `${config.generatedDir}/index`;
|
|
398
1319
|
let indexPath;
|
|
399
|
-
if (
|
|
1320
|
+
if (existsSync5(`${basePath}.js`)) {
|
|
400
1321
|
indexPath = `${basePath}.js`;
|
|
401
|
-
} else if (
|
|
1322
|
+
} else if (existsSync5(`${basePath}.ts`)) {
|
|
402
1323
|
indexPath = `${basePath}.ts`;
|
|
403
1324
|
} else {
|
|
404
1325
|
throw new Error(
|
|
@@ -408,7 +1329,7 @@ async function loadGeneratedContracts(configPath) {
|
|
|
408
1329
|
const mod = await import(new URL(`file://${indexPath}`).href);
|
|
409
1330
|
let guardrailHooks;
|
|
410
1331
|
const hooksBasePath = `${config.generatedDir}/hooks/index`;
|
|
411
|
-
const hooksPath =
|
|
1332
|
+
const hooksPath = existsSync5(`${hooksBasePath}.js`) ? `${hooksBasePath}.js` : existsSync5(`${hooksBasePath}.ts`) ? `${hooksBasePath}.ts` : null;
|
|
412
1333
|
if (hooksPath) {
|
|
413
1334
|
try {
|
|
414
1335
|
const hooksMod = await import(new URL(`file://${hooksPath}`).href);
|
|
@@ -467,7 +1388,7 @@ function formatTable(headers, rows) {
|
|
|
467
1388
|
var handlers = {
|
|
468
1389
|
async init(options, _globalOpts) {
|
|
469
1390
|
try {
|
|
470
|
-
const outputDir =
|
|
1391
|
+
const outputDir = resolve4(options.output ?? ".");
|
|
471
1392
|
const result = await runInit({
|
|
472
1393
|
adapter: options.adapter ?? "mock",
|
|
473
1394
|
outputDir,
|
|
@@ -508,7 +1429,7 @@ var handlers = {
|
|
|
508
1429
|
let fileInvocation;
|
|
509
1430
|
if (options.file) {
|
|
510
1431
|
try {
|
|
511
|
-
const raw =
|
|
1432
|
+
const raw = readFileSync2(options.file, "utf8");
|
|
512
1433
|
const parsed = YAML3.parse(raw);
|
|
513
1434
|
resolvedWorkflowId = parsed.workflow;
|
|
514
1435
|
if (!resolvedWorkflowId) {
|
|
@@ -572,7 +1493,7 @@ var handlers = {
|
|
|
572
1493
|
adapter = await createAdapter(adapterName, contracts.guardrailHooks);
|
|
573
1494
|
} catch (err) {
|
|
574
1495
|
console.error(err.message);
|
|
575
|
-
process.exit(
|
|
1496
|
+
process.exit(12);
|
|
576
1497
|
return;
|
|
577
1498
|
}
|
|
578
1499
|
const recovery = config.recovery;
|
|
@@ -737,14 +1658,92 @@ var handlers = {
|
|
|
737
1658
|
console.log(prompt);
|
|
738
1659
|
}
|
|
739
1660
|
},
|
|
1661
|
+
async implement(description, options, _globalOpts) {
|
|
1662
|
+
if (!description) {
|
|
1663
|
+
console.error("Error: description is required");
|
|
1664
|
+
process.exit(3);
|
|
1665
|
+
}
|
|
1666
|
+
const result = await runImplement(description, {
|
|
1667
|
+
adapter: options.adapter ?? "claude",
|
|
1668
|
+
projectDir: options.projectDir ?? ".",
|
|
1669
|
+
dryRun: options.dryRun ?? false,
|
|
1670
|
+
model: options.model,
|
|
1671
|
+
failOn: options.failOn ?? "error",
|
|
1672
|
+
reportFormat: options.reportFormat ?? "text"
|
|
1673
|
+
});
|
|
1674
|
+
if (result.status === "failed") {
|
|
1675
|
+
if (options.reportFormat === "json") {
|
|
1676
|
+
console.log(JSON.stringify({ error: result.error, status: "failed" }, null, 2));
|
|
1677
|
+
} else if (options.reportFormat === "yaml") {
|
|
1678
|
+
console.log(YAML3.stringify({ error: result.error, status: "failed" }));
|
|
1679
|
+
} else {
|
|
1680
|
+
console.error(formatImplementResult(result));
|
|
1681
|
+
}
|
|
1682
|
+
process.exit(result.exitCode ?? 1);
|
|
1683
|
+
}
|
|
1684
|
+
const outputData = result.data ?? { status: result.status };
|
|
1685
|
+
let output;
|
|
1686
|
+
if (options.reportFormat === "json") {
|
|
1687
|
+
output = JSON.stringify(outputData, null, 2);
|
|
1688
|
+
} else if (options.reportFormat === "yaml") {
|
|
1689
|
+
output = YAML3.stringify(outputData);
|
|
1690
|
+
} else {
|
|
1691
|
+
output = formatImplementResult(result);
|
|
1692
|
+
}
|
|
1693
|
+
const outputPath = options.output;
|
|
1694
|
+
if (outputPath) {
|
|
1695
|
+
writeFileSync(outputPath, output + "\n");
|
|
1696
|
+
} else {
|
|
1697
|
+
console.log(output);
|
|
1698
|
+
}
|
|
1699
|
+
},
|
|
1700
|
+
async auditImplementation(projectDir, options, _globalOpts) {
|
|
1701
|
+
const result = await runAuditImplementation({
|
|
1702
|
+
adapter: options.adapter ?? "claude",
|
|
1703
|
+
projectDir: projectDir ?? ".",
|
|
1704
|
+
focus: options.focus ?? "all",
|
|
1705
|
+
dryRun: options.dryRun ?? false,
|
|
1706
|
+
failOn: options.failOn ?? "error",
|
|
1707
|
+
model: options.model,
|
|
1708
|
+
reportFormat: options.reportFormat ?? "text"
|
|
1709
|
+
});
|
|
1710
|
+
if (result.status === "failed") {
|
|
1711
|
+
if (options.reportFormat === "json") {
|
|
1712
|
+
console.log(JSON.stringify({ error: result.error, status: "failed" }, null, 2));
|
|
1713
|
+
} else if (options.reportFormat === "yaml") {
|
|
1714
|
+
console.log(YAML3.stringify({ error: result.error, status: "failed" }));
|
|
1715
|
+
} else {
|
|
1716
|
+
console.error(formatAuditResult(result));
|
|
1717
|
+
}
|
|
1718
|
+
process.exit(result.exitCode);
|
|
1719
|
+
}
|
|
1720
|
+
const outputData = result.data ?? { status: result.status };
|
|
1721
|
+
let output;
|
|
1722
|
+
if (options.reportFormat === "json") {
|
|
1723
|
+
output = JSON.stringify(outputData, null, 2);
|
|
1724
|
+
} else if (options.reportFormat === "yaml") {
|
|
1725
|
+
output = YAML3.stringify(outputData);
|
|
1726
|
+
} else {
|
|
1727
|
+
output = formatAuditResult(result);
|
|
1728
|
+
}
|
|
1729
|
+
const outputPath = options.output;
|
|
1730
|
+
if (outputPath) {
|
|
1731
|
+
writeFileSync(outputPath, output + "\n");
|
|
1732
|
+
} else {
|
|
1733
|
+
console.log(output);
|
|
1734
|
+
}
|
|
1735
|
+
if (result.exitCode !== 0) {
|
|
1736
|
+
process.exit(result.exitCode);
|
|
1737
|
+
}
|
|
1738
|
+
},
|
|
740
1739
|
async doctor(globalOpts) {
|
|
741
1740
|
const configPath = globalOpts.config ?? "./agent-runtime.config.yaml";
|
|
742
1741
|
const result = await runDoctor(configPath);
|
|
743
1742
|
const statusIcon = (s) => s === "pass" ? "\u2713" : s === "warn" ? "!" : "\u2717";
|
|
744
1743
|
for (const check of result.checks) {
|
|
745
1744
|
const icon = statusIcon(check.status);
|
|
746
|
-
const
|
|
747
|
-
console.log(` ${icon} ${check.name.padEnd(20)} ${check.status.toUpperCase()}${
|
|
1745
|
+
const msg3 = check.message ? ` ${check.message}` : "";
|
|
1746
|
+
console.log(` ${icon} ${check.name.padEnd(20)} ${check.status.toUpperCase()}${msg3}`);
|
|
748
1747
|
}
|
|
749
1748
|
console.log("");
|
|
750
1749
|
if (result.all_passed) {
|