@kilnai/core 0.23.2 → 1.0.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/dist/agents/execution-identity.d.ts +15 -0
- package/dist/agents/execution-identity.d.ts.map +1 -0
- package/dist/agents/execution-identity.js +42 -0
- package/dist/agents/execution-identity.js.map +1 -0
- package/dist/agents/index.d.ts +6 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +4 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/infrastructure/__tests__/codex-oauth-auth.test.d.ts +2 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth-auth.test.d.ts.map +1 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth-auth.test.js +313 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth-auth.test.js.map +1 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth.test.d.ts +2 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth.test.d.ts.map +1 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth.test.js +720 -0
- package/dist/agents/infrastructure/__tests__/codex-oauth.test.js.map +1 -0
- package/dist/agents/infrastructure/codex-oauth-auth.d.ts +41 -0
- package/dist/agents/infrastructure/codex-oauth-auth.d.ts.map +1 -0
- package/dist/agents/infrastructure/codex-oauth-auth.js +204 -0
- package/dist/agents/infrastructure/codex-oauth-auth.js.map +1 -0
- package/dist/agents/infrastructure/codex-oauth.d.ts +32 -0
- package/dist/agents/infrastructure/codex-oauth.d.ts.map +1 -0
- package/dist/agents/infrastructure/codex-oauth.js +371 -0
- package/dist/agents/infrastructure/codex-oauth.js.map +1 -0
- package/dist/agents/model-capability-registry.d.ts +2 -0
- package/dist/agents/model-capability-registry.d.ts.map +1 -1
- package/dist/agents/model-capability-registry.js +11 -2
- package/dist/agents/model-capability-registry.js.map +1 -1
- package/dist/agents/model-pricing.d.ts +2 -0
- package/dist/agents/model-pricing.d.ts.map +1 -1
- package/dist/agents/model-pricing.js +10 -0
- package/dist/agents/model-pricing.js.map +1 -1
- package/dist/cost/cost-tracker.d.ts +1 -0
- package/dist/cost/cost-tracker.d.ts.map +1 -1
- package/dist/cost/cost-tracker.js +6 -3
- package/dist/cost/cost-tracker.js.map +1 -1
- package/dist/cost/index.d.ts +2 -0
- package/dist/cost/index.d.ts.map +1 -1
- package/dist/cost/index.js +1 -0
- package/dist/cost/index.js.map +1 -1
- package/dist/cost/models-dev-client.d.ts +20 -0
- package/dist/cost/models-dev-client.d.ts.map +1 -0
- package/dist/cost/models-dev-client.js +91 -0
- package/dist/cost/models-dev-client.js.map +1 -0
- package/dist/domain/index.d.ts +1 -0
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js.map +1 -1
- package/dist/engine/composites/team.d.ts +1 -1
- package/dist/engine/composites/team.d.ts.map +1 -1
- package/dist/engine/composites/team.js +1 -17
- package/dist/engine/composites/team.js.map +1 -1
- package/dist/engine/domain/cron.d.ts +3 -1
- package/dist/engine/domain/cron.d.ts.map +1 -1
- package/dist/engine/domain/cron.js +41 -10
- package/dist/engine/domain/cron.js.map +1 -1
- package/dist/engine/domain/tool-execution.d.ts +21 -0
- package/dist/engine/domain/tool-execution.d.ts.map +1 -1
- package/dist/engine/error-catalog.d.ts.map +1 -1
- package/dist/engine/error-catalog.js +8 -0
- package/dist/engine/error-catalog.js.map +1 -1
- package/dist/engine/errors.d.ts +2 -1
- package/dist/engine/errors.d.ts.map +1 -1
- package/dist/engine/errors.js +10 -0
- package/dist/engine/errors.js.map +1 -1
- package/dist/engine/index.d.ts +1 -1
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +1 -1
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/loader/app-loader.js +1 -1
- package/dist/engine/loader/app-loader.js.map +1 -1
- package/dist/events/index.d.ts +18 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -1
- package/dist/field/domain/field-config.d.ts +8 -0
- package/dist/field/domain/field-config.d.ts.map +1 -0
- package/dist/field/domain/field-config.js +7 -0
- package/dist/field/domain/field-config.js.map +1 -0
- package/dist/field/domain/field-store.d.ts +8 -0
- package/dist/field/domain/field-store.d.ts.map +1 -0
- package/dist/field/domain/field-store.js +2 -0
- package/dist/field/domain/field-store.js.map +1 -0
- package/dist/field/domain/field.d.ts +22 -0
- package/dist/field/domain/field.d.ts.map +1 -0
- package/dist/field/domain/field.js +2 -0
- package/dist/field/domain/field.js.map +1 -0
- package/dist/field/field-inhibitor.d.ts +17 -0
- package/dist/field/field-inhibitor.d.ts.map +1 -0
- package/dist/field/field-inhibitor.js +50 -0
- package/dist/field/field-inhibitor.js.map +1 -0
- package/dist/field/field-propagator.d.ts +19 -0
- package/dist/field/field-propagator.d.ts.map +1 -0
- package/dist/field/field-propagator.js +69 -0
- package/dist/field/field-propagator.js.map +1 -0
- package/dist/field/field-service.d.ts +18 -0
- package/dist/field/field-service.d.ts.map +1 -0
- package/dist/field/field-service.js +57 -0
- package/dist/field/field-service.js.map +1 -0
- package/dist/field/field-updater.d.ts +19 -0
- package/dist/field/field-updater.d.ts.map +1 -0
- package/dist/field/field-updater.js +64 -0
- package/dist/field/field-updater.js.map +1 -0
- package/dist/field/index.d.ts +15 -0
- package/dist/field/index.d.ts.map +1 -0
- package/dist/field/index.js +9 -0
- package/dist/field/index.js.map +1 -0
- package/dist/field/infrastructure/in-memory-field-store.d.ts +16 -0
- package/dist/field/infrastructure/in-memory-field-store.d.ts.map +1 -0
- package/dist/field/infrastructure/in-memory-field-store.js +72 -0
- package/dist/field/infrastructure/in-memory-field-store.js.map +1 -0
- package/dist/field/infrastructure/sqlite-field-store.d.ts +20 -0
- package/dist/field/infrastructure/sqlite-field-store.d.ts.map +1 -0
- package/dist/field/infrastructure/sqlite-field-store.js +107 -0
- package/dist/field/infrastructure/sqlite-field-store.js.map +1 -0
- package/dist/field/stability-monitor.d.ts +24 -0
- package/dist/field/stability-monitor.d.ts.map +1 -0
- package/dist/field/stability-monitor.js +72 -0
- package/dist/field/stability-monitor.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/context-budget.d.ts +17 -0
- package/dist/memory/context-budget.d.ts.map +1 -0
- package/dist/memory/context-budget.js +29 -0
- package/dist/memory/context-budget.js.map +1 -0
- package/dist/memory/context-cache.d.ts +23 -0
- package/dist/memory/context-cache.d.ts.map +1 -0
- package/dist/memory/context-cache.js +34 -0
- package/dist/memory/context-cache.js.map +1 -0
- package/dist/memory/index.d.ts +15 -3
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/memory-manager.d.ts +1 -1
- package/dist/memory/memory-manager.d.ts.map +1 -1
- package/dist/memory/memory-manager.js +2 -2
- package/dist/memory/memory-manager.js.map +1 -1
- package/dist/memory/project-store.js +1 -1
- package/dist/memory/project-store.js.map +1 -1
- package/dist/memory/resume-policy.d.ts +21 -0
- package/dist/memory/resume-policy.d.ts.map +1 -0
- package/dist/memory/resume-policy.js +70 -0
- package/dist/memory/resume-policy.js.map +1 -0
- package/dist/memory/resume-signals.d.ts +8 -0
- package/dist/memory/resume-signals.d.ts.map +1 -0
- package/dist/memory/resume-signals.js +8 -0
- package/dist/memory/resume-signals.js.map +1 -0
- package/dist/memory/sqlite-store.d.ts +6 -1
- package/dist/memory/sqlite-store.d.ts.map +1 -1
- package/dist/memory/sqlite-store.js +88 -11
- package/dist/memory/sqlite-store.js.map +1 -1
- package/dist/memory/task-shape.d.ts +2 -0
- package/dist/memory/task-shape.d.ts.map +1 -0
- package/dist/memory/task-shape.js +9 -0
- package/dist/memory/task-shape.js.map +1 -0
- package/dist/observability/span-mapper.d.ts.map +1 -1
- package/dist/observability/span-mapper.js +18 -0
- package/dist/observability/span-mapper.js.map +1 -1
- package/dist/orchestrator/chain-governor.d.ts +62 -0
- package/dist/orchestrator/chain-governor.d.ts.map +1 -0
- package/dist/orchestrator/chain-governor.js +80 -0
- package/dist/orchestrator/chain-governor.js.map +1 -0
- package/dist/orchestrator/demand-allocator.d.ts +64 -0
- package/dist/orchestrator/demand-allocator.d.ts.map +1 -0
- package/dist/orchestrator/demand-allocator.js +139 -0
- package/dist/orchestrator/demand-allocator.js.map +1 -0
- package/dist/orchestrator/demand-signal.d.ts +9 -0
- package/dist/orchestrator/demand-signal.d.ts.map +1 -0
- package/dist/orchestrator/demand-signal.js +23 -0
- package/dist/orchestrator/demand-signal.js.map +1 -0
- package/dist/orchestrator/index.d.ts +8 -2
- package/dist/orchestrator/index.d.ts.map +1 -1
- package/dist/orchestrator/index.js +8 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/orchestrator-checkpoint-support.d.ts +43 -0
- package/dist/orchestrator/orchestrator-checkpoint-support.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-checkpoint-support.js +147 -0
- package/dist/orchestrator/orchestrator-checkpoint-support.js.map +1 -0
- package/dist/orchestrator/orchestrator-dev-tool-support.d.ts +30 -0
- package/dist/orchestrator/orchestrator-dev-tool-support.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-dev-tool-support.js +125 -0
- package/dist/orchestrator/orchestrator-dev-tool-support.js.map +1 -0
- package/dist/orchestrator/orchestrator-interrupt-support.d.ts +22 -0
- package/dist/orchestrator/orchestrator-interrupt-support.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-interrupt-support.js +64 -0
- package/dist/orchestrator/orchestrator-interrupt-support.js.map +1 -0
- package/dist/orchestrator/orchestrator-memory-sync-support.d.ts +16 -0
- package/dist/orchestrator/orchestrator-memory-sync-support.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-memory-sync-support.js +25 -0
- package/dist/orchestrator/orchestrator-memory-sync-support.js.map +1 -0
- package/dist/orchestrator/orchestrator-verification-support.d.ts +17 -0
- package/dist/orchestrator/orchestrator-verification-support.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-verification-support.js +29 -0
- package/dist/orchestrator/orchestrator-verification-support.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +24 -16
- package/dist/orchestrator/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/orchestrator.js +106 -235
- package/dist/orchestrator/orchestrator.js.map +1 -1
- package/dist/orchestrator/strategies/index.d.ts +0 -1
- package/dist/orchestrator/strategies/index.d.ts.map +1 -1
- package/dist/orchestrator/strategies/index.js +1 -5
- package/dist/orchestrator/strategies/index.js.map +1 -1
- package/dist/orchestrator/task-registry.d.ts +94 -0
- package/dist/orchestrator/task-registry.d.ts.map +1 -0
- package/dist/orchestrator/task-registry.js +167 -0
- package/dist/orchestrator/task-registry.js.map +1 -0
- package/dist/safety/pii-scanner.d.ts.map +1 -1
- package/dist/safety/pii-scanner.js +7 -8
- package/dist/safety/pii-scanner.js.map +1 -1
- package/dist/safety/rails.d.ts.map +1 -1
- package/dist/safety/rails.js +9 -5
- package/dist/safety/rails.js.map +1 -1
- package/dist/security/dangerous-command-detector.d.ts +5 -0
- package/dist/security/dangerous-command-detector.d.ts.map +1 -0
- package/dist/security/dangerous-command-detector.js +92 -0
- package/dist/security/dangerous-command-detector.js.map +1 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/dist/security/prompt-scanner.d.ts.map +1 -1
- package/dist/security/prompt-scanner.js +117 -4
- package/dist/security/prompt-scanner.js.map +1 -1
- package/dist/skill/index.d.ts +4 -0
- package/dist/skill/index.d.ts.map +1 -1
- package/dist/skill/index.js +2 -0
- package/dist/skill/index.js.map +1 -1
- package/dist/skill/skill-capture.d.ts +46 -0
- package/dist/skill/skill-capture.d.ts.map +1 -0
- package/dist/skill/skill-capture.js +150 -0
- package/dist/skill/skill-capture.js.map +1 -0
- package/dist/skill/skill-generator.d.ts +20 -0
- package/dist/skill/skill-generator.d.ts.map +1 -0
- package/dist/skill/skill-generator.js +106 -0
- package/dist/skill/skill-generator.js.map +1 -0
- package/dist/tools/domain/tool-environment.d.ts +16 -0
- package/dist/tools/domain/tool-environment.d.ts.map +1 -0
- package/dist/tools/domain/tool-environment.js +94 -0
- package/dist/tools/domain/tool-environment.js.map +1 -0
- package/dist/tools/domain/tool-registry.d.ts +10 -0
- package/dist/tools/domain/tool-registry.d.ts.map +1 -0
- package/dist/tools/domain/tool-registry.js +23 -0
- package/dist/tools/domain/tool-registry.js.map +1 -0
- package/dist/tools/domain/tool.d.ts +29 -0
- package/dist/tools/domain/tool.d.ts.map +1 -0
- package/dist/tools/domain/tool.js +123 -0
- package/dist/tools/domain/tool.js.map +1 -0
- package/dist/tools/index.d.ts +18 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +13 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/infrastructure/bash-tool.d.ts +20 -0
- package/dist/tools/infrastructure/bash-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/bash-tool.js +84 -0
- package/dist/tools/infrastructure/bash-tool.js.map +1 -0
- package/dist/tools/infrastructure/edit-tool.d.ts +9 -0
- package/dist/tools/infrastructure/edit-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/edit-tool.js +80 -0
- package/dist/tools/infrastructure/edit-tool.js.map +1 -0
- package/dist/tools/infrastructure/git-tool.d.ts +20 -0
- package/dist/tools/infrastructure/git-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/git-tool.js +85 -0
- package/dist/tools/infrastructure/git-tool.js.map +1 -0
- package/dist/tools/infrastructure/glob-tool.d.ts +23 -0
- package/dist/tools/infrastructure/glob-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/glob-tool.js +88 -0
- package/dist/tools/infrastructure/glob-tool.js.map +1 -0
- package/dist/tools/infrastructure/grep-tool.d.ts +23 -0
- package/dist/tools/infrastructure/grep-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/grep-tool.js +146 -0
- package/dist/tools/infrastructure/grep-tool.js.map +1 -0
- package/dist/tools/infrastructure/read-tool.d.ts +9 -0
- package/dist/tools/infrastructure/read-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/read-tool.js +45 -0
- package/dist/tools/infrastructure/read-tool.js.map +1 -0
- package/dist/tools/infrastructure/tool-helpers.d.ts +37 -0
- package/dist/tools/infrastructure/tool-helpers.d.ts.map +1 -0
- package/dist/tools/infrastructure/tool-helpers.js +145 -0
- package/dist/tools/infrastructure/tool-helpers.js.map +1 -0
- package/dist/tools/infrastructure/write-tool.d.ts +9 -0
- package/dist/tools/infrastructure/write-tool.d.ts.map +1 -0
- package/dist/tools/infrastructure/write-tool.js +38 -0
- package/dist/tools/infrastructure/write-tool.js.map +1 -0
- package/dist/tools/mcp/dev-tools-server.d.ts +37 -0
- package/dist/tools/mcp/dev-tools-server.d.ts.map +1 -0
- package/dist/tools/mcp/dev-tools-server.js +94 -0
- package/dist/tools/mcp/dev-tools-server.js.map +1 -0
- package/dist/tools/tool-executor.d.ts +34 -0
- package/dist/tools/tool-executor.d.ts.map +1 -0
- package/dist/tools/tool-executor.js +123 -0
- package/dist/tools/tool-executor.js.map +1 -0
- package/package.json +6 -5
- package/dist/orchestrator/strategies/swarm-strategy.d.ts +0 -36
- package/dist/orchestrator/strategies/swarm-strategy.d.ts.map +0 -1
- package/dist/orchestrator/strategies/swarm-strategy.js +0 -126
- package/dist/orchestrator/strategies/swarm-strategy.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ToolEnvironment } from "../domain/tool-environment.js";
|
|
2
|
+
import { type DevTool, type ToolInput, type ToolResult } from "../domain/tool.js";
|
|
3
|
+
import { type CommandResult } from "./tool-helpers.js";
|
|
4
|
+
type GrepCommandRunner = (binary: string, args: readonly string[], cwd: string, timeoutMs: number) => Promise<CommandResult>;
|
|
5
|
+
type EnvironmentProvider = () => Promise<ToolEnvironment>;
|
|
6
|
+
export interface GrepToolOptions {
|
|
7
|
+
readonly commandRunner?: GrepCommandRunner;
|
|
8
|
+
readonly environmentProvider?: EnvironmentProvider;
|
|
9
|
+
}
|
|
10
|
+
export declare class GrepTool implements DevTool {
|
|
11
|
+
readonly name = "grep";
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly inputSchema: Record<string, unknown>;
|
|
14
|
+
readonly annotations: import("../domain/tool.js").DevToolAnnotations;
|
|
15
|
+
private readonly commandRunner;
|
|
16
|
+
private readonly environmentProvider;
|
|
17
|
+
constructor(options?: GrepToolOptions);
|
|
18
|
+
execute(input: ToolInput, sandbox?: unknown): Promise<ToolResult>;
|
|
19
|
+
private executeFastPath;
|
|
20
|
+
private executeFallback;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=grep-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/infrastructure/grep-tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,aAAa,EAYnB,MAAM,mBAAmB,CAAC;AAM3B,KAAK,iBAAiB,GAAG,CACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,KACd,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B,KAAK,mBAAmB,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAC3C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CACpD;AAED,qBAAa,QAAS,YAAW,OAAO;IACtC,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,WAAW,SAAiC;IACrD,QAAQ,CAAC,WAAW,0BAAiC;IACrD,QAAQ,CAAC,WAAW,iDAAiC;IAErD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAoB;IAClD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAsB;gBAE9C,OAAO,GAAE,eAAoB;IAKnC,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;YAiDzD,eAAe;YAkDf,eAAe;CAkE9B"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { basename, relative } from "node:path";
|
|
3
|
+
import { detectToolEnvironment, } from "../domain/tool-environment.js";
|
|
4
|
+
import { TOOL_SCHEMAS, } from "../domain/tool.js";
|
|
5
|
+
import { getSandboxContext, matchesGlob, normalizePath, optionalString, requireString, resolvePath, runCommand as defaultRunCommand, toErrorResult, toSuccessResult, validateReadPath, walkFiles, } from "./tool-helpers.js";
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
|
+
export class GrepTool {
|
|
8
|
+
name = "grep";
|
|
9
|
+
description = TOOL_SCHEMAS.grep.description;
|
|
10
|
+
inputSchema = TOOL_SCHEMAS.grep.inputSchema;
|
|
11
|
+
annotations = TOOL_SCHEMAS.grep.annotations;
|
|
12
|
+
commandRunner;
|
|
13
|
+
environmentProvider;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.commandRunner = options.commandRunner ?? defaultRunCommand;
|
|
16
|
+
this.environmentProvider = options.environmentProvider ?? detectToolEnvironment;
|
|
17
|
+
}
|
|
18
|
+
async execute(input, sandbox) {
|
|
19
|
+
const patternInput = requireString(input, "pattern");
|
|
20
|
+
if (!patternInput.ok) {
|
|
21
|
+
return patternInput.result;
|
|
22
|
+
}
|
|
23
|
+
const sandboxContext = getSandboxContext(sandbox);
|
|
24
|
+
const searchRoot = resolvePath(optionalString(input, "path") ?? sandboxContext?.cwd ?? process.cwd(), sandbox);
|
|
25
|
+
const rootReadError = validateReadPath(searchRoot, sandbox);
|
|
26
|
+
if (rootReadError) {
|
|
27
|
+
return toErrorResult(rootReadError, { path: searchRoot });
|
|
28
|
+
}
|
|
29
|
+
const globFilter = optionalString(input, "glob");
|
|
30
|
+
const modeValue = optionalString(input, "outputMode");
|
|
31
|
+
const outputMode = isGrepOutputMode(modeValue) ? modeValue : "content";
|
|
32
|
+
try {
|
|
33
|
+
const environment = await this.environmentProvider();
|
|
34
|
+
const rgPath = environment.rg?.path;
|
|
35
|
+
if (rgPath) {
|
|
36
|
+
return await this.executeFastPath(rgPath, searchRoot, patternInput.value, globFilter, outputMode);
|
|
37
|
+
}
|
|
38
|
+
return await this.executeFallback(searchRoot, patternInput.value, globFilter, outputMode, sandbox);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const err = error;
|
|
42
|
+
return toErrorResult(err.message, {
|
|
43
|
+
path: searchRoot,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async executeFastPath(rgPath, searchRoot, pattern, globFilter, outputMode) {
|
|
48
|
+
const args = buildFastPathArgs(pattern, globFilter, outputMode);
|
|
49
|
+
try {
|
|
50
|
+
const result = await this.commandRunner(rgPath, args, searchRoot, DEFAULT_TIMEOUT_MS);
|
|
51
|
+
return toSuccessResult(result.stdout.trim(), {
|
|
52
|
+
path: searchRoot,
|
|
53
|
+
strategy: "rg",
|
|
54
|
+
outputMode,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const err = error;
|
|
59
|
+
if (String(err.code) === "1") {
|
|
60
|
+
return toSuccessResult("", {
|
|
61
|
+
path: searchRoot,
|
|
62
|
+
strategy: "rg",
|
|
63
|
+
outputMode,
|
|
64
|
+
noMatches: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const message = [err.stderr, err.stdout].filter(Boolean).join("").trim() ||
|
|
68
|
+
err.message ||
|
|
69
|
+
"rg execution failed";
|
|
70
|
+
return toErrorResult(message, {
|
|
71
|
+
path: searchRoot,
|
|
72
|
+
strategy: "rg",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async executeFallback(searchRoot, pattern, globFilter, outputMode, sandbox) {
|
|
77
|
+
let expression;
|
|
78
|
+
try {
|
|
79
|
+
expression = new RegExp(pattern);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return toErrorResult("Invalid input: \"pattern\" must be a valid regular expression");
|
|
83
|
+
}
|
|
84
|
+
const files = await walkFiles(searchRoot);
|
|
85
|
+
const resultsContent = [];
|
|
86
|
+
const resultsFiles = [];
|
|
87
|
+
const resultsCount = [];
|
|
88
|
+
for (const filePath of files) {
|
|
89
|
+
const readError = validateReadPath(filePath, sandbox);
|
|
90
|
+
if (readError) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const relativePath = normalizePath(relative(searchRoot, filePath) || basename(filePath));
|
|
94
|
+
if (globFilter && !matchesGlob(relativePath, globFilter)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const content = await readFile(filePath, "utf8");
|
|
98
|
+
const lines = content.split(/\r?\n/);
|
|
99
|
+
let matchedLines = 0;
|
|
100
|
+
for (let index = 0; index < lines.length; index++) {
|
|
101
|
+
if (expression.test(lines[index] ?? "")) {
|
|
102
|
+
matchedLines += 1;
|
|
103
|
+
if (outputMode === "content") {
|
|
104
|
+
resultsContent.push(`${relativePath}:${index + 1}:${lines[index] ?? ""}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (matchedLines > 0) {
|
|
109
|
+
if (outputMode === "files_with_matches") {
|
|
110
|
+
resultsFiles.push(relativePath);
|
|
111
|
+
}
|
|
112
|
+
else if (outputMode === "count") {
|
|
113
|
+
resultsCount.push(`${relativePath}:${matchedLines}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const output = outputMode === "content"
|
|
118
|
+
? resultsContent.join("\n")
|
|
119
|
+
: outputMode === "files_with_matches"
|
|
120
|
+
? resultsFiles.join("\n")
|
|
121
|
+
: resultsCount.join("\n");
|
|
122
|
+
return toSuccessResult(output, {
|
|
123
|
+
path: searchRoot,
|
|
124
|
+
strategy: "fallback",
|
|
125
|
+
outputMode,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function isGrepOutputMode(value) {
|
|
130
|
+
return value === "content" || value === "files_with_matches" || value === "count";
|
|
131
|
+
}
|
|
132
|
+
function buildFastPathArgs(pattern, globFilter, outputMode) {
|
|
133
|
+
const args = ["--no-heading", "--line-number"];
|
|
134
|
+
if (globFilter) {
|
|
135
|
+
args.push("--glob", globFilter);
|
|
136
|
+
}
|
|
137
|
+
if (outputMode === "files_with_matches") {
|
|
138
|
+
args.push("--files-with-matches");
|
|
139
|
+
}
|
|
140
|
+
else if (outputMode === "count") {
|
|
141
|
+
args.push("--count");
|
|
142
|
+
}
|
|
143
|
+
args.push(pattern, ".");
|
|
144
|
+
return args;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=grep-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep-tool.js","sourceRoot":"","sources":["../../../src/tools/infrastructure/grep-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,qBAAqB,GAEtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,YAAY,GAIb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,cAAc,EACd,aAAa,EACb,WAAW,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IAAI,CAAC,IAAI,CAAC;YAC3B,CAAC,CAAC,UAAU,KAAK,oBAAoB;gBACnC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;gBACzB,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhC,OAAO,eAAe,CAAC,MAAM,EAAE;YAC7B,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,UAAU;YACpB,UAAU;SACX,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,KAAyB;IACjD,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,oBAAoB,IAAI,KAAK,KAAK,OAAO,CAAC;AACpF,CAAC;AAED,SAAS,iBAAiB,CACxB,OAAe,EACf,UAA8B,EAC9B,UAA0B;IAE1B,MAAM,IAAI,GAAa,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IACzD,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,UAAU,KAAK,oBAAoB,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACpC,CAAC;SAAM,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DevTool, type ToolInput, type ToolResult } from "../domain/tool.js";
|
|
2
|
+
export declare class ReadTool implements DevTool {
|
|
3
|
+
readonly name = "read";
|
|
4
|
+
readonly description: string;
|
|
5
|
+
readonly inputSchema: Record<string, unknown>;
|
|
6
|
+
readonly annotations: import("../domain/tool.js").DevToolAnnotations;
|
|
7
|
+
execute(input: ToolInput, sandbox?: unknown): Promise<ToolResult>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=read-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/infrastructure/read-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAUhG,qBAAa,QAAS,YAAW,OAAO;IACtC,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,WAAW,SAAiC;IACrD,QAAQ,CAAC,WAAW,0BAAiC;IACrD,QAAQ,CAAC,WAAW,iDAAiC;IAE/C,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;CAqCxE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { TOOL_SCHEMAS } from "../domain/tool.js";
|
|
3
|
+
import { optionalNumber, requireString, resolvePath, toErrorResult, toSuccessResult, validateReadPath, } from "./tool-helpers.js";
|
|
4
|
+
export class ReadTool {
|
|
5
|
+
name = "read";
|
|
6
|
+
description = TOOL_SCHEMAS.read.description;
|
|
7
|
+
inputSchema = TOOL_SCHEMAS.read.inputSchema;
|
|
8
|
+
annotations = TOOL_SCHEMAS.read.annotations;
|
|
9
|
+
async execute(input, sandbox) {
|
|
10
|
+
const filePathInput = requireString(input, "filePath");
|
|
11
|
+
if (!filePathInput.ok) {
|
|
12
|
+
return filePathInput.result;
|
|
13
|
+
}
|
|
14
|
+
const absolutePath = resolvePath(filePathInput.value, sandbox);
|
|
15
|
+
const readError = validateReadPath(absolutePath, sandbox);
|
|
16
|
+
if (readError) {
|
|
17
|
+
return toErrorResult(readError, { filePath: absolutePath });
|
|
18
|
+
}
|
|
19
|
+
const offset = optionalNumber(input, "offset") ?? 0;
|
|
20
|
+
const limit = optionalNumber(input, "limit");
|
|
21
|
+
if (offset < 0) {
|
|
22
|
+
return toErrorResult('Invalid input: "offset" must be >= 0');
|
|
23
|
+
}
|
|
24
|
+
if (limit !== undefined && limit < 0) {
|
|
25
|
+
return toErrorResult('Invalid input: "limit" must be >= 0');
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const content = await readFile(absolutePath, "utf8");
|
|
29
|
+
const lines = content.split(/\r?\n/);
|
|
30
|
+
const sliced = limit !== undefined ? lines.slice(offset, offset + limit) : lines.slice(offset);
|
|
31
|
+
const windowed = sliced.join("\n");
|
|
32
|
+
return toSuccessResult(windowed, {
|
|
33
|
+
filePath: absolutePath,
|
|
34
|
+
offset,
|
|
35
|
+
limit,
|
|
36
|
+
totalLines: lines.length,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const err = error;
|
|
41
|
+
return toErrorResult(err.message, { filePath: absolutePath, code: err.code });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=read-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-tool.js","sourceRoot":"","sources":["../../../src/tools/infrastructure/read-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAiD,MAAM,mBAAmB,CAAC;AAChG,OAAO,EACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,aAAa,EACb,eAAe,EACf,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,OAAO,QAAQ;IACV,IAAI,GAAG,MAAM,CAAC;IACd,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC;IAC5C,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC;IAC5C,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,W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AAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnC,OAAO,eAAe,CAAC,QAAQ,EAAE;gBAC/B,QAAQ,EAAE,YAAY;gBACtB,MAAM;gBACN,KAAK;gBACL,UAAU,EAAE,KAAK,CAAC,MAAM;aACzB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,KAA8B,CAAC;YAC3C,OAAO,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PathValidator } from "../../sandbox/path-validator.js";
|
|
2
|
+
import { SandboxPolicy } from "../../sandbox/policies.js";
|
|
3
|
+
import type { ToolInput, ToolResult } from "../domain/tool.js";
|
|
4
|
+
export interface ToolSandboxContext {
|
|
5
|
+
readonly cwd?: string;
|
|
6
|
+
readonly policy?: SandboxPolicy;
|
|
7
|
+
readonly pathValidator?: PathValidator;
|
|
8
|
+
}
|
|
9
|
+
export declare function toErrorResult(message: string, metadata?: Record<string, unknown>): ToolResult;
|
|
10
|
+
export declare function toSuccessResult(output: string, metadata?: Record<string, unknown>): ToolResult;
|
|
11
|
+
export declare function getSandboxContext(sandbox?: unknown): ToolSandboxContext | undefined;
|
|
12
|
+
export declare function resolvePath(filePath: string, sandbox?: unknown): string;
|
|
13
|
+
export declare function validateReadPath(filePath: string, sandbox?: unknown): string | undefined;
|
|
14
|
+
export declare function validateWritePath(filePath: string, sandbox?: unknown): string | undefined;
|
|
15
|
+
export declare function requireString(input: ToolInput, key: string, options?: {
|
|
16
|
+
allowEmpty?: boolean;
|
|
17
|
+
}): {
|
|
18
|
+
ok: true;
|
|
19
|
+
value: string;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
result: ToolResult;
|
|
23
|
+
};
|
|
24
|
+
export declare function optionalNumber(input: ToolInput, key: string): number | undefined;
|
|
25
|
+
export declare function optionalString(input: ToolInput, key: string): string | undefined;
|
|
26
|
+
export declare function optionalBoolean(input: ToolInput, key: string): boolean | undefined;
|
|
27
|
+
export declare function validateCommand(command: string, cwd: string, sandbox?: unknown): string | undefined;
|
|
28
|
+
export type CommandResult = {
|
|
29
|
+
readonly stdout: string;
|
|
30
|
+
readonly stderr: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function runCommand(binary: string, args: readonly string[], cwd: string, timeoutMs: number): Promise<CommandResult>;
|
|
33
|
+
export declare function walkFiles(rootPath: string): Promise<string[]>;
|
|
34
|
+
export declare function matchesGlob(candidatePath: string, globPattern: string): boolean;
|
|
35
|
+
export declare function globToRegExp(pattern: string): RegExp;
|
|
36
|
+
export declare function normalizePath(value: string): string;
|
|
37
|
+
//# sourceMappingURL=tool-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../../src/tools/infrastructure/tool-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;CACxC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAM7F;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAA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,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC,CAQxB;AAED,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAInE;AAeD,wBAAgB,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAM/E;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { readdir } from "node:fs/promises";
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
const execFile = promisify(execFileCallback);
|
|
6
|
+
import { PathValidator } from "../../sandbox/path-validator.js";
|
|
7
|
+
import { SandboxPolicy } from "../../sandbox/policies.js";
|
|
8
|
+
export function toErrorResult(message, metadata) {
|
|
9
|
+
return {
|
|
10
|
+
output: message,
|
|
11
|
+
isError: true,
|
|
12
|
+
metadata,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function toSuccessResult(output, metadata) {
|
|
16
|
+
return {
|
|
17
|
+
output,
|
|
18
|
+
isError: false,
|
|
19
|
+
metadata,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function getSandboxContext(sandbox) {
|
|
23
|
+
if (!sandbox || typeof sandbox !== "object") {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const context = sandbox;
|
|
27
|
+
const policy = context.policy instanceof SandboxPolicy ? context.policy : undefined;
|
|
28
|
+
const pathValidator = context.pathValidator instanceof PathValidator
|
|
29
|
+
? context.pathValidator
|
|
30
|
+
: policy
|
|
31
|
+
? new PathValidator({ policy })
|
|
32
|
+
: undefined;
|
|
33
|
+
return {
|
|
34
|
+
cwd: typeof context.cwd === "string" ? context.cwd : undefined,
|
|
35
|
+
policy,
|
|
36
|
+
pathValidator,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function resolvePath(filePath, sandbox) {
|
|
40
|
+
const context = getSandboxContext(sandbox);
|
|
41
|
+
if (context?.cwd) {
|
|
42
|
+
return resolve(context.cwd, filePath);
|
|
43
|
+
}
|
|
44
|
+
return resolve(filePath);
|
|
45
|
+
}
|
|
46
|
+
export function validateReadPath(filePath, sandbox) {
|
|
47
|
+
const context = getSandboxContext(sandbox);
|
|
48
|
+
if (!context?.pathValidator) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const result = context.pathValidator.validateRead(filePath);
|
|
52
|
+
return result.allowed ? undefined : result.reason ?? "Read access denied";
|
|
53
|
+
}
|
|
54
|
+
export function validateWritePath(filePath, sandbox) {
|
|
55
|
+
const context = getSandboxContext(sandbox);
|
|
56
|
+
if (!context?.pathValidator) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const result = context.pathValidator.validateWrite(filePath);
|
|
60
|
+
return result.allowed ? undefined : result.reason ?? "Write access denied";
|
|
61
|
+
}
|
|
62
|
+
export function requireString(input, key, options) {
|
|
63
|
+
const value = input.input[key];
|
|
64
|
+
const allowEmpty = options?.allowEmpty ?? false;
|
|
65
|
+
if (typeof value !== "string" || (!allowEmpty && value.length === 0)) {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
result: toErrorResult(allowEmpty
|
|
69
|
+
? `Invalid input: "${key}" must be a string`
|
|
70
|
+
: `Invalid input: "${key}" must be a non-empty string`),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return { ok: true, value };
|
|
74
|
+
}
|
|
75
|
+
export function optionalNumber(input, key) {
|
|
76
|
+
const value = input.input[key];
|
|
77
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
export function optionalString(input, key) {
|
|
83
|
+
const value = input.input[key];
|
|
84
|
+
return typeof value === "string" ? value : undefined;
|
|
85
|
+
}
|
|
86
|
+
export function optionalBoolean(input, key) {
|
|
87
|
+
const value = input.input[key];
|
|
88
|
+
return typeof value === "boolean" ? value : undefined;
|
|
89
|
+
}
|
|
90
|
+
export function validateCommand(command, cwd, sandbox) {
|
|
91
|
+
const context = getSandboxContext(sandbox);
|
|
92
|
+
if (!context?.pathValidator) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const result = context.pathValidator.validateExecute(command, cwd);
|
|
96
|
+
return result.allowed ? undefined : result.reason ?? "Command execution denied";
|
|
97
|
+
}
|
|
98
|
+
export async function runCommand(binary, args, cwd, timeoutMs) {
|
|
99
|
+
const { stdout, stderr } = await execFile(binary, args, {
|
|
100
|
+
cwd,
|
|
101
|
+
timeout: timeoutMs,
|
|
102
|
+
windowsHide: true,
|
|
103
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
104
|
+
});
|
|
105
|
+
return { stdout, stderr };
|
|
106
|
+
}
|
|
107
|
+
export async function walkFiles(rootPath) {
|
|
108
|
+
const out = [];
|
|
109
|
+
await walk(rootPath, out);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
async function walk(currentPath, out) {
|
|
113
|
+
const entries = await readdir(currentPath, { withFileTypes: true });
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
if (entry.isSymbolicLink())
|
|
116
|
+
continue;
|
|
117
|
+
const fullPath = `${currentPath}/${entry.name}`;
|
|
118
|
+
if (entry.isDirectory()) {
|
|
119
|
+
await walk(fullPath, out);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (entry.isFile())
|
|
123
|
+
out.push(fullPath);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function matchesGlob(candidatePath, globPattern) {
|
|
127
|
+
const normalizedPath = normalizePath(candidatePath);
|
|
128
|
+
const normalizedPattern = normalizePath(globPattern);
|
|
129
|
+
const matcher = globToRegExp(normalizedPattern);
|
|
130
|
+
if (normalizedPattern.includes("/"))
|
|
131
|
+
return matcher.test(normalizedPath);
|
|
132
|
+
return matcher.test(basename(normalizedPath));
|
|
133
|
+
}
|
|
134
|
+
export function globToRegExp(pattern) {
|
|
135
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
136
|
+
const withDoubleStar = escaped.replace(/\*\*/g, "::DOUBLE_STAR::");
|
|
137
|
+
const withSingleStar = withDoubleStar.replace(/\*/g, "[^/]*");
|
|
138
|
+
const withQuestion = withSingleStar.replace(/\?/g, ".");
|
|
139
|
+
const source = withQuestion.replace(/::DOUBLE_STAR::/g, ".*");
|
|
140
|
+
return new RegExp(`^${source}$`);
|
|
141
|
+
}
|
|
142
|
+
export function normalizePath(value) {
|
|
143
|
+
return value.replace(/\\/g, "/");
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=tool-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../../../src/tools/infrastructure/tool-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,iCAA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MAAM,cAAc,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;IACpD,MAAM,iBAAiB,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;IAChD,IAAI,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACzE,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAC7D,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACnE,MAAM,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC9D,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DevTool, type ToolInput, type ToolResult } from "../domain/tool.js";
|
|
2
|
+
export declare class WriteTool implements DevTool {
|
|
3
|
+
readonly name = "write";
|
|
4
|
+
readonly description: string;
|
|
5
|
+
readonly inputSchema: Record<string, unknown>;
|
|
6
|
+
readonly annotations: import("../domain/tool.js").DevToolAnnotations;
|
|
7
|
+
execute(input: ToolInput, sandbox?: unknown): Promise<ToolResult>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=write-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/infrastructure/write-tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAShG,qBAAa,SAAU,YAAW,OAAO;IACvC,QAAQ,CAAC,IAAI,WAAW;IACxB,QAAQ,CAAC,WAAW,SAAkC;IACtD,QAAQ,CAAC,WAAW,0BAAkC;IACtD,QAAQ,CAAC,WAAW,iDAAkC;IAEhD,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;CAiCxE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { TOOL_SCHEMAS } from "../domain/tool.js";
|
|
4
|
+
import { requireString, resolvePath, toErrorResult, toSuccessResult, validateWritePath, } from "./tool-helpers.js";
|
|
5
|
+
export class WriteTool {
|
|
6
|
+
name = "write";
|
|
7
|
+
description = TOOL_SCHEMAS.write.description;
|
|
8
|
+
inputSchema = TOOL_SCHEMAS.write.inputSchema;
|
|
9
|
+
annotations = TOOL_SCHEMAS.write.annotations;
|
|
10
|
+
async execute(input, sandbox) {
|
|
11
|
+
const filePathInput = requireString(input, "filePath");
|
|
12
|
+
if (!filePathInput.ok) {
|
|
13
|
+
return filePathInput.result;
|
|
14
|
+
}
|
|
15
|
+
const contentInput = requireString(input, "content", { allowEmpty: true });
|
|
16
|
+
if (!contentInput.ok) {
|
|
17
|
+
return contentInput.result;
|
|
18
|
+
}
|
|
19
|
+
const absolutePath = resolvePath(filePathInput.value, sandbox);
|
|
20
|
+
const writeError = validateWritePath(absolutePath, sandbox);
|
|
21
|
+
if (writeError) {
|
|
22
|
+
return toErrorResult(writeError, { filePath: absolutePath });
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
await mkdir(dirname(absolutePath), { recursive: true });
|
|
26
|
+
await writeFile(absolutePath, contentInput.value, "utf8");
|
|
27
|
+
return toSuccessResult(`Wrote ${contentInput.value.length} characters to ${absolutePath}`, {
|
|
28
|
+
filePath: absolutePath,
|
|
29
|
+
bytesWritten: Buffer.byteLength(contentInput.value, "utf8"),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const err = error;
|
|
34
|
+
return toErrorResult(err.message, { filePath: absolutePath, code: err.code });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=write-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-tool.js","sourceRoot":"","sources":["../../../src/tools/infrastructure/write-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAiD,MAAM,mBAAmB,CAAC;AAChG,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,eAAe,EACf,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,OAAO,SAAS;IACX,IAAI,GAAG,OAAO,CAAC;IACf,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;IAC7C,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;IAC7C,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,KAAgB,EAAE,OAAiB;QAC/C,MAAM,aAAa,GAAG,aAAa,CAAC,KAAK,EAAE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-0,0 +1,37 @@
|
|
|
1
|
+
import { DevToolExecutionBridge } from "../tool-executor.js";
|
|
2
|
+
interface McpServerInstance {
|
|
3
|
+
setRequestHandler(schema: unknown, handler: (request: {
|
|
4
|
+
params: Record<string, unknown>;
|
|
5
|
+
}) => unknown): void;
|
|
6
|
+
}
|
|
7
|
+
export interface DevToolsMcpServerOptions {
|
|
8
|
+
readonly bridge: DevToolExecutionBridge;
|
|
9
|
+
}
|
|
10
|
+
export interface DevToolsMcpToolSchema {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly inputSchema: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface DevToolsMcpCallResult {
|
|
16
|
+
readonly content: readonly {
|
|
17
|
+
type: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
readonly isError?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class DevToolsMcpServer {
|
|
23
|
+
private readonly bridge;
|
|
24
|
+
private sdk;
|
|
25
|
+
private sdkPromise;
|
|
26
|
+
constructor(options: DevToolsMcpServerOptions);
|
|
27
|
+
initialize(): Promise<void>;
|
|
28
|
+
close(): void;
|
|
29
|
+
listTools(): readonly DevToolsMcpToolSchema[];
|
|
30
|
+
callTool(name: string, args?: Record<string, unknown>): Promise<DevToolsMcpCallResult>;
|
|
31
|
+
createServer(): McpServerInstance;
|
|
32
|
+
private jsonResult;
|
|
33
|
+
private errorResult;
|
|
34
|
+
private formatErrorMessage;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=dev-tools-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-tools-server.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp/dev-tools-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAK7D,UAAU,iBAAiB;IACzB,iBAAiB,CACf,MAAM,EA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
|
3
|
+
const SERVER_NAME = "kilnai-dev-tools";
|
|
4
|
+
const SERVER_VERSION = "0.1.0";
|
|
5
|
+
function loadSdkModules() {
|
|
6
|
+
return Promise.all([
|
|
7
|
+
import("@modelcontextprotocol/sdk/server/index.js"),
|
|
8
|
+
import("@modelcontextprotocol/sdk/types.js"),
|
|
9
|
+
]).then(([serverModule, typesModule]) => ({
|
|
10
|
+
Server: serverModule.Server,
|
|
11
|
+
ListToolsRequestSchema: typesModule.ListToolsRequestSchema,
|
|
12
|
+
CallToolRequestSchema: typesModule.CallToolRequestSchema,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
export class DevToolsMcpServer {
|
|
16
|
+
bridge;
|
|
17
|
+
sdk;
|
|
18
|
+
sdkPromise;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.bridge = options.bridge;
|
|
21
|
+
}
|
|
22
|
+
async initialize() {
|
|
23
|
+
this.sdkPromise ??= loadSdkModules();
|
|
24
|
+
try {
|
|
25
|
+
this.sdk = await this.sdkPromise;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
this.sdkPromise = undefined;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
close() {
|
|
33
|
+
this.sdk = undefined;
|
|
34
|
+
}
|
|
35
|
+
listTools() {
|
|
36
|
+
return Object.values(TOOL_SCHEMAS).map((tool) => ({
|
|
37
|
+
name: tool.name,
|
|
38
|
+
description: tool.description,
|
|
39
|
+
inputSchema: tool.inputSchema,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
async callTool(name, args = {}) {
|
|
43
|
+
try {
|
|
44
|
+
const execution = await this.bridge.execute({
|
|
45
|
+
name,
|
|
46
|
+
input: args,
|
|
47
|
+
});
|
|
48
|
+
if (execution.result.isError) {
|
|
49
|
+
return this.errorResult(execution.result.output);
|
|
50
|
+
}
|
|
51
|
+
return this.jsonResult({
|
|
52
|
+
result: execution.result,
|
|
53
|
+
attempts: execution.attempts,
|
|
54
|
+
fallbackUsed: execution.fallbackUsed,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return this.errorResult(this.formatErrorMessage(error));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
createServer() {
|
|
62
|
+
if (!this.sdk) {
|
|
63
|
+
throw new Error("Dev tools MCP server not initialized");
|
|
64
|
+
}
|
|
65
|
+
const { Server, ListToolsRequestSchema, CallToolRequestSchema } = this.sdk;
|
|
66
|
+
const server = new Server({ name: SERVER_NAME, version: SERVER_VERSION }, { capabilities: { tools: {} } });
|
|
67
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
68
|
+
tools: this.listTools(),
|
|
69
|
+
}));
|
|
70
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
71
|
+
const params = request.params;
|
|
72
|
+
return this.callTool(params.name, params.arguments ?? {});
|
|
73
|
+
});
|
|
74
|
+
return server;
|
|
75
|
+
}
|
|
76
|
+
jsonResult(data) {
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
errorResult(message) {
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: "text", text: message }],
|
|
84
|
+
isError: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
formatErrorMessage(error) {
|
|
88
|
+
if (error instanceof KilnError) {
|
|
89
|
+
return `${error.code}: ${error.message}`;
|
|
90
|
+
}
|
|
91
|
+
return error instanceof Error ? error.message : String(error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=dev-tools-server.js.map
|