goatchain 0.0.13 → 0.0.14

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.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Tool Access Controller
3
+ *
4
+ * Provides methods to query tool access modes based on a policy.
5
+ */
6
+ import type { ToolAccessPolicy, ToolAccessMode } from './types';
7
+ /**
8
+ * Tool Access Controller
9
+ *
10
+ * Responsible for determining tool access modes based on a policy.
11
+ */
12
+ export declare class ToolAccessController {
13
+ private policy;
14
+ constructor(policy: ToolAccessPolicy);
15
+ /**
16
+ * Get the access mode for a specific tool
17
+ *
18
+ * @param toolName - Name of the tool
19
+ * @returns The access mode for the tool
20
+ */
21
+ getAccessMode(toolName: string): ToolAccessMode;
22
+ /**
23
+ * Get all blocked tool names
24
+ *
25
+ * @returns Array of tool names that are blocked
26
+ */
27
+ getBlockedTools(): string[];
28
+ /**
29
+ * Get all restricted tool names
30
+ *
31
+ * Restricted tools require special handling (e.g., BashTool read-only mode).
32
+ *
33
+ * @returns Array of tool names that are restricted
34
+ */
35
+ getRestrictedTools(): string[];
36
+ /**
37
+ * Check if a tool is blocked
38
+ *
39
+ * @param toolName - Name of the tool
40
+ * @returns true if the tool is blocked
41
+ */
42
+ isBlocked(toolName: string): boolean;
43
+ /**
44
+ * Check if a tool is restricted
45
+ *
46
+ * @param toolName - Name of the tool
47
+ * @returns true if the tool is restricted
48
+ */
49
+ isRestricted(toolName: string): boolean;
50
+ /**
51
+ * Check if a tool has full access
52
+ *
53
+ * @param toolName - Name of the tool
54
+ * @returns true if the tool has full access
55
+ */
56
+ hasFullAccess(toolName: string): boolean;
57
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Tool Access Control Module
3
+ *
4
+ * Provides a unified system for controlling tool access in different
5
+ * execution contexts (Plan Mode, Explore subagent, etc.).
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import {
10
+ * ToolAccessController,
11
+ * PLAN_MODE_POLICY,
12
+ * isReadOnlyBashCommand
13
+ * } from '../lib/access-control'
14
+ *
15
+ * const controller = new ToolAccessController(PLAN_MODE_POLICY)
16
+ * const blockedTools = controller.getBlockedTools()
17
+ * // ['Write', 'Edit', 'ast_grep_replace', 'TodoWrite']
18
+ *
19
+ * const bashMode = controller.getAccessMode('Bash')
20
+ * // 'restricted'
21
+ *
22
+ * const validation = isReadOnlyBashCommand('ls -la')
23
+ * // { isAllowed: true }
24
+ * ```
25
+ */
26
+ export type { ToolAccessMode, ToolAccessPolicy, ToolValidationResult } from './types';
27
+ export { ToolAccessController } from './controller';
28
+ export { PLAN_MODE_POLICY, EXPLORE_POLICY, GENERAL_PURPOSE_POLICY, } from './policies';
29
+ export { READ_ONLY_COMMANDS, FORBIDDEN_PATTERNS, isReadOnlyBashCommand, assertReadOnlyBashCommand, } from './validators';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Predefined Tool Access Policies
3
+ *
4
+ * Provides standard access policies for different execution contexts.
5
+ */
6
+ import type { ToolAccessPolicy } from './types';
7
+ /**
8
+ * Plan Mode Read-Only Policy
9
+ *
10
+ * Allows:
11
+ * - All read tools (Read, Glob, Grep, WebSearch, WebFetch)
12
+ * - Read-only Bash commands (via BashTool internal validation)
13
+ * - User interaction tools (AskUserQuestion)
14
+ * - Task tool (limited to Explore subagent only)
15
+ *
16
+ * Blocks:
17
+ * - All write tools (Write, Edit)
18
+ * - Code modification tools (ast_grep_replace)
19
+ * - TodoWrite (use TodoPlan instead in Plan Mode)
20
+ * - Non-read-only Bash commands (validated by BashTool)
21
+ * - Task calls to non-Explore subagents (validated by TaskTool)
22
+ *
23
+ * Note: 'restricted' mode tools are not blocked by Session's blocked list.
24
+ * The actual restrictions are enforced internally by the tool based on ctx.metadata:
25
+ * - Bash: checks ctx.metadata.readOnlyBash, calls isReadOnlyBashCommand()
26
+ * - Task: checks ctx.metadata.planMode, only allows subagent_type === 'Explore'
27
+ */
28
+ export declare const PLAN_MODE_POLICY: ToolAccessPolicy;
29
+ /**
30
+ * Explore Subagent Read-Only Policy
31
+ *
32
+ * Allows only read operations for fast codebase exploration.
33
+ */
34
+ export declare const EXPLORE_POLICY: ToolAccessPolicy;
35
+ /**
36
+ * General Purpose Agent Policy
37
+ *
38
+ * Full access to all tools except Task (to prevent infinite recursion).
39
+ */
40
+ export declare const GENERAL_PURPOSE_POLICY: ToolAccessPolicy;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Tool Access Control Types
3
+ *
4
+ * Defines types for controlling tool access in different execution contexts
5
+ * (e.g., Plan Mode, Explore subagent).
6
+ */
7
+ /**
8
+ * Tool access mode
9
+ */
10
+ export type ToolAccessMode = 'full' | 'restricted' | 'blocked';
11
+ /**
12
+ * Tool access policy
13
+ *
14
+ * Defines which tools are allowed, restricted, or blocked in a given context.
15
+ */
16
+ export interface ToolAccessPolicy {
17
+ /** Default access mode for tools not explicitly listed in overrides */
18
+ defaultMode: ToolAccessMode;
19
+ /** Tool-specific access mode overrides */
20
+ overrides?: Record<string, ToolAccessMode>;
21
+ }
22
+ /**
23
+ * Tool validation result
24
+ *
25
+ * Used by tools in 'restricted' mode to indicate whether
26
+ * a specific operation is allowed.
27
+ */
28
+ export interface ToolValidationResult {
29
+ /** Whether the operation is allowed */
30
+ isAllowed: boolean;
31
+ /** Reason for rejection if not allowed */
32
+ reason?: string;
33
+ /** The matched pattern/rule that caused rejection */
34
+ matchedPattern?: string;
35
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Bash Command Validator
3
+ *
4
+ * Provides validation for Bash commands to ensure they are read-only operations.
5
+ * Used by Plan Mode and Explore subagent to prevent file modifications.
6
+ */
7
+ import type { ToolValidationResult } from '../types';
8
+ /**
9
+ * Whitelist of read-only commands that are allowed
10
+ *
11
+ * Note: This list is for documentation purposes. The actual validation
12
+ * uses FORBIDDEN_PATTERNS (blacklist approach).
13
+ */
14
+ export declare const READ_ONLY_COMMANDS: readonly ["ls", "find", "file", "stat", "tree", "du", "df", "wc", "cat", "head", "tail", "less", "more", "grep", "awk", "sed", "sort", "uniq", "cut", "tr", "xargs", "git status", "git log", "git diff", "git show", "git branch", "git remote", "git tag", "git blame", "git rev-parse", "git ls-files", "git ls-tree", "pwd", "which", "whereis", "type", "echo", "printf", "date", "env", "printenv"];
15
+ /**
16
+ * Patterns that indicate forbidden (write) operations
17
+ */
18
+ export declare const FORBIDDEN_PATTERNS: RegExp[];
19
+ /**
20
+ * Validates if a bash command is read-only and safe
21
+ *
22
+ * @param command - The bash command to validate
23
+ * @returns Validation result with isAllowed flag and optional reason
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * isReadOnlyBashCommand('ls -la')
28
+ * // { isAllowed: true }
29
+ *
30
+ * isReadOnlyBashCommand('rm file.txt')
31
+ * // { isAllowed: false, reason: 'File modification commands are not allowed...', matchedPattern: 'rm' }
32
+ *
33
+ * isReadOnlyBashCommand('echo "test" > file.txt')
34
+ * // { isAllowed: false, reason: 'Command contains redirect operator...', matchedPattern: '>' }
35
+ * ```
36
+ */
37
+ export declare function isReadOnlyBashCommand(command: string): ToolValidationResult;
38
+ /**
39
+ * Validates a bash command and throws an error if not allowed
40
+ *
41
+ * @param command - The bash command to validate
42
+ * @throws Error if the command is not read-only
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * assertReadOnlyBashCommand('ls -la') // passes
47
+ * assertReadOnlyBashCommand('rm file.txt') // throws Error
48
+ * ```
49
+ */
50
+ export declare function assertReadOnlyBashCommand(command: string): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Tool Validators
3
+ *
4
+ * Exports validators for different tools in restricted mode.
5
+ */
6
+ export { READ_ONLY_COMMANDS, FORBIDDEN_PATTERNS, isReadOnlyBashCommand, assertReadOnlyBashCommand, } from './bash';
@@ -55,7 +55,7 @@ export interface ParallelSubagentMiddlewareOptions {
55
55
  * const model = createDefaultModel()
56
56
  *
57
57
  * const middleware = createParallelSubagentMiddleware({
58
- * subagents: [fileSearchSpecialist],
58
+ * subagents: [exploreAgent],
59
59
  * globalToolRegistry,
60
60
  * model,
61
61
  * debug: true,
@@ -68,7 +68,7 @@ export interface ParallelSubagentMiddlewareOptions {
68
68
  * ```typescript
69
69
  * const middleware = createParallelSubagentMiddleware({
70
70
  * subagents: [
71
- * { name: 'Explore', description: 'Code explorer', tools: ['Read', 'Grep'] },
71
+ * { name: 'Explore', description: 'Code explorer', accessPolicy: EXPLORE_POLICY },
72
72
  * ],
73
73
  * executor: async (args) => {
74
74
  * const subAgent = createSubAgent(args.subagent_type)
@@ -1,5 +1,6 @@
1
1
  import type { Middleware } from '../agent/middleware';
2
2
  import type { AgentLoopState } from '../agent/types';
3
+ import type { ToolAccessPolicy } from '../lib/access-control';
3
4
  /**
4
5
  * Configuration options for plan mode middleware.
5
6
  */
@@ -34,6 +35,11 @@ export interface PlanModeMiddlewareOptions {
34
35
  * When true, adds stronger emphasis on Phase 3 synthesis step.
35
36
  */
36
37
  requireSynthesisPhase?: boolean;
38
+ /**
39
+ * Custom tool access policy (optional).
40
+ * If not provided, uses the default PLAN_MODE_POLICY.
41
+ */
42
+ accessPolicy?: ToolAccessPolicy;
37
43
  }
38
44
  /**
39
45
  * Creates a middleware that injects a plan mode system reminder into the conversation.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Bash Command Validator for Explore Subagent
3
+ *
4
+ * This module provides validation for Bash commands to ensure
5
+ * they are read-only operations. Used by the Explore subagent
6
+ * to prevent any file modifications.
7
+ *
8
+ * @deprecated Import from '../lib/access-control' instead.
9
+ * This module re-exports for backward compatibility.
10
+ */
11
+ import type { ToolExecutionContext } from '../tool/types';
12
+ import type { CallToolResult, ToolInputSchema } from '../types';
13
+ import { BaseTool } from '../tool/base';
14
+ export { assertReadOnlyBashCommand, FORBIDDEN_PATTERNS, isReadOnlyBashCommand, READ_ONLY_COMMANDS, } from '../lib/access-control';
15
+ export type { ToolValidationResult as BashValidationResult } from '../lib/access-control';
16
+ /**
17
+ * Read-only Bash tool wrapper for Explore subagent
18
+ *
19
+ * This tool wraps the standard BashTool and validates commands
20
+ * before execution to ensure they are read-only operations.
21
+ */
22
+ export declare class ReadOnlyBashTool extends BaseTool {
23
+ readonly name = "Bash";
24
+ readonly description: string;
25
+ readonly parameters: ToolInputSchema;
26
+ readonly riskLevel: "safe";
27
+ private innerBash;
28
+ constructor(options?: {
29
+ cwd?: string;
30
+ shell?: string;
31
+ });
32
+ execute(args: Record<string, unknown>, ctx: ToolExecutionContext): Promise<CallToolResult>;
33
+ setCwd(cwd: string): void;
34
+ getCwd(): string;
35
+ }
36
+ /**
37
+ * Creates a read-only Bash tool for use in Explore subagent
38
+ *
39
+ * @param options - Optional configuration for the Bash tool
40
+ * @param options.cwd - Working directory for bash commands
41
+ * @param options.shell - Shell to use for command execution
42
+ * @returns A ReadOnlyBashTool instance
43
+ */
44
+ export declare function createReadOnlyBashTool(options?: {
45
+ cwd?: string;
46
+ shell?: string;
47
+ }): ReadOnlyBashTool;
@@ -0,0 +1,38 @@
1
+ import type { SubagentDefinition } from '../tool/builtin/task';
2
+ /**
3
+ * Thoroughness level for Explore subagent
4
+ *
5
+ * - quick: Fast targeted search, 1-2 search iterations, exact matches
6
+ * - medium: Balanced exploration, follows related files, multiple naming conventions
7
+ * - very thorough: Comprehensive analysis, multiple locations, deep analysis
8
+ */
9
+ export type ThoroughnessLevel = 'quick' | 'medium' | 'very thorough';
10
+ /**
11
+ * System prompt for Explore subagent
12
+ *
13
+ * This prompt defines the Explore agent's role as a READ-ONLY codebase explorer.
14
+ * It emphasizes speed, efficiency, and strict prohibition of file modifications.
15
+ */
16
+ export declare function buildExplorePrompt(cwd: string, now?: Date): string;
17
+ export declare const explorePrompt: string;
18
+ /**
19
+ * Explore Subagent Definition
20
+ *
21
+ * A fast, read-only agent specialized for codebase exploration.
22
+ * Uses Haiku model for speed and cost efficiency.
23
+ *
24
+ * Features:
25
+ * - Supports thoroughness levels (quick/medium/very thorough)
26
+ * - Strict read-only mode with Bash command validation
27
+ * - Optimized for parallel tool calls
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * Task({
32
+ * subagent_type: 'Explore',
33
+ * description: 'Find auth files',
34
+ * prompt: 'Find all authentication-related files. Thoroughness: quick'
35
+ * })
36
+ * ```
37
+ */
38
+ export declare const exploreAgent: SubagentDefinition;
@@ -4,5 +4,6 @@
4
4
  * This module exports predefined subagent configurations
5
5
  * that can be used with the parallel subagent middleware.
6
6
  */
7
- export * from './file-search-specialist';
7
+ export * from './bash-validator';
8
+ export * from './explore';
8
9
  export * from './parallel-task-coordinator';
@@ -1,5 +1,6 @@
1
1
  import type { CallToolResult, ToolInputSchema } from '../../types';
2
2
  import type { ToolExecutionContext } from '../types';
3
+ import type { ToolAccessPolicy } from '../../lib/access-control';
3
4
  import { BaseTool } from '../base';
4
5
  /**
5
6
  * Definition of an available subagent type
@@ -9,10 +10,8 @@ export interface SubagentDefinition {
9
10
  name: string;
10
11
  /** Description of what the subagent does */
11
12
  description: string;
12
- /** Tools available to this subagent (optional) */
13
- tools?: string[];
14
- /** Tools to explicitly block for this subagent (optional) */
15
- blockedTools?: string[];
13
+ /** Tool access policy for this subagent */
14
+ accessPolicy: ToolAccessPolicy;
16
15
  /** System prompt for this subagent (optional) */
17
16
  systemPrompt?: string;
18
17
  /** Additional metadata (extensible for future use) */
@@ -96,6 +96,16 @@ export interface ToolExecutionContext {
96
96
  * ```
97
97
  */
98
98
  emitEvent?: (event: Omit<import('../types').AgentEvent, 'sessionId'>) => void;
99
+ /**
100
+ * Runtime metadata passed from AgentLoopState.metadata.
101
+ *
102
+ * Used to communicate context-specific information to tools, such as:
103
+ * - readOnlyBash: boolean - Whether Bash tool is in read-only mode (Plan Mode)
104
+ * - planMode: boolean - Whether the session is in Plan Mode
105
+ *
106
+ * This is set by middleware and synchronized before each tool execution.
107
+ */
108
+ metadata?: Record<string, unknown>;
99
109
  }
100
110
  /**
101
111
  * Safe input shape for callers to provide context/capabilities/metadata.
@@ -228,7 +228,7 @@ export interface SubagentEvent extends BaseEvent {
228
228
  type: 'subagent_event';
229
229
  /** Subagent identifier (agent ID or task call ID) */
230
230
  subagentId: string;
231
- /** Subagent type/name (e.g., 'FileSearchSpecialist') */
231
+ /** Subagent type/name (e.g., 'Explore') */
232
232
  subagentType: string;
233
233
  /** The original event emitted by the subagent */
234
234
  nestedEvent: AgentEvent;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goatchain",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "workspaces": [
6
6
  "packages/*"
7
7
  ],
@@ -49,8 +49,10 @@
49
49
  "build:binary:windows": "bun run --filter 'dimcode' build:binary:windows",
50
50
  "build:all": "bun run clear:all && bun run build:lib && bun run build:tui && bun run build:cli && bun run build:binary",
51
51
  "clear:all": "rm -rf dist packages/cli/dist packages/cli/bin-release packages/tui/dist",
52
- "cli": "cd packages/cli && esno ./src/cli.ts",
53
- "cli:debug": "cd packages/cli && esno ./src/cli.ts --debug",
52
+ "cli": "cd packages/cli && bun run cli",
53
+ "cli:run": "cd packages/cli && bun run cli:run",
54
+ "cli:debug": "cd packages/cli && bun run cli:debug",
55
+ "cli:debug:run": "cd packages/cli && bun run cli:debug:run",
54
56
  "cli:smoke": "cd packages/cli && bun run smoke",
55
57
  "providers:update": "node packages/cli/scripts/update-provider-models.mjs",
56
58
  "release": "bumpp --commit --no-tag --no-push && bun run build && bun publish",
@@ -96,4 +98,4 @@
96
98
  ],
97
99
  "prettier": "@sxzz/prettier-config",
98
100
  "packageManager": "pnpm@10.16.0+sha512.8066e7b034217b700a9a4dbb3a005061d641ba130a89915213a10b3ca4919c19c037bec8066afdc559b89635fdb806b16ea673f2468fbb28aabfa13c53e3f769"
99
- }
101
+ }
@@ -1,16 +0,0 @@
1
- import type { SubagentDefinition } from '../tool/builtin/task';
2
- /**
3
- * System prompt for File Search Specialist
4
- *
5
- * Based on the configuration from subagent_file.json, this prompt
6
- * defines the specialist's role, capabilities, and guidelines.
7
- */
8
- export declare function buildFileSearchSpecialistPrompt(cwd: string, now?: Date): string;
9
- export declare const fileSearchSpecialistPrompt: string;
10
- /**
11
- * File Search Specialist Subagent Definition
12
- *
13
- * This subagent specializes in navigating and exploring codebases,
14
- * finding files, searching content, and analyzing file structures.
15
- */
16
- export declare const fileSearchSpecialist: SubagentDefinition;