Skip to content

feat: enforce cwd and track PIDs in subAgent process delegation#456

Merged
avoidwork merged 72 commits into
mainfrom
feat/scan-agents-tool
Jun 27, 2026
Merged

feat: enforce cwd and track PIDs in subAgent process delegation#456
avoidwork merged 72 commits into
mainfrom
feat/scan-agents-tool

Conversation

@avoidwork

@avoidwork avoidwork commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Description

This branch introduces comprehensive subAgent process management: enforcing explicit cwd for delegation, tracking OS-level PIDs in process results, and adding the loadAgents workspace function for AGENTS.md discovery. It also creates and refines the SUB_AGENT.md prompt for one-shot skill execution, adds the --sub-agent CLI flag, and excludes subAgent tools from sub-agent processes to prevent recursion.

Type of Change

  • New feature (non-breaking change which adds functionality)

Testing

Unit tests for scanAgents tool, subAgent cwd handling, skills module cwd override, sandbox runner, discoverer, and tool registration. Full test suite runs with no failures.

Coverage

  • 100% line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with 100% line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

@avoidwork avoidwork self-assigned this Jun 26, 2026
- Add src/tools/scanAgents.js with implementation, tool definition, and factory
- Register tool in src/tools/index.js (TOOL_PERMISSIONS, TOOL_FACTORIES, switch case)
- Add unit tests in tests/unit/tools_scanAgents.test.js
- Update tool_index.test.js to account for new tool registration
- Archive OpenSpec change as 2026-06-26-scan-agents-tool
- Create spec in openspec/specs/scan-agents/spec.md
@avoidwork avoidwork changed the title feat: add OpenSpec proposal for scanAgents tool feat: add scanAgents tool for AGENTS.md discovery Jun 26, 2026
@avoidwork

Copy link
Copy Markdown
Owner Author

Audit Results — scanAgents Tool (Implementation)

Audit 1: Implementation Against Specs & Goals

Goal Fulfillment

  • Goal 1 (Add scanAgents tool): Fully implemented.
  • Key Req 1 (optional path parameter): Implemented — input.path || process.cwd() (line 18).
  • Key Req 2 (checks for AGENTS.md): Implemented — join(resolved.path, "AGENTS.md") (line 24).
  • Key Req 3 (returns file contents): Implemented — readFile(agentsPath, "utf-8") returns content (lines 39-40).
  • Key Req 4 (silent on not found): Implemented — returns "" on ENOENT (lines 28-30).
  • Key Req 5 (validatePath/checkFileLimit): Implemented — both used for safety (lines 19, 33).
  • Key Req 6 (minimal tool pattern): Implemented — follows date.js pattern exactly.
  • Key Req 7-9 (registration): Implemented — TOOL_PERMISSIONS, TOOL_FACTORIES, switch case all updated.

Spec Compliance

  • Requirement 1 (discovers AGENTS.md): ✓ Lines 18, 24
  • Requirement 2 (returns file contents): ✓ Lines 39-40
  • Requirement 3 (silent on not found): ✓ Lines 28-30
  • Requirement 4 (validates paths): ✓ Lines 19-22
  • Requirement 5 (enforces size limits): ✓ Lines 33-36

Task Completion

  • Task 1.1-1.4: Created src/tools/scanAgents.js with implementation, tool definition, factory, and common.js integration. ✓
  • Task 2.1-2.3: Registered in index.js (import, TOOL_PERMISSIONS, TOOL_FACTORIES, switch case). ✓
  • Task 3.1-3.6: Created tests/unit/tools_scanAgents.test.js with 6 test cases covering all scenarios. ✓
  • Task 4.1-4.3: Tests pass (1193/1193), lint passes, application starts. ✓

Quality Check

  • No obvious issues or inconsistencies.
  • All edge cases covered by tests.
  • Code follows existing patterns (date.js, filesystem.js).
  • JSDoc comments present on public APIs.

Result

No errors found. Implementation is complete and correct.

@avoidwork avoidwork force-pushed the feat/scan-agents-tool branch from 33da5c6 to 87ed201 Compare June 26, 2026 23:31
avoidwork added 21 commits June 26, 2026 19:49
- Create src/workspace/loadAgents.js to read AGENTS.md from any directory
- Update scanAgents tool to delegate to loadAgents with validated path
- Wire loadAgents into index.js session init to append AGENTS.md to system prompt
- Remove scanAgents reference from SYSTEM_PROMPT.md
- Add cwd: '' to config.yaml and schema
- Set config.cwd = process.cwd() in loader before any chdir
- Import config loader first in index.js, before all other ./src imports
- Replace all process.cwd() calls in ./src with config.cwd
- Document CLI arguments in README
avoidwork added 20 commits June 27, 2026 12:23
- Add subAgent option to buildToolConfig to exclude subAgent tools
- Skip subAgent, subAgentLog, and subAgentMessage when subAgent=true
- Fix pre-existing bug: subAgentMessage missing from TOOL_PERMISSIONS
- Pass config.subAgent from index.js to buildToolConfig
- Add tests for subAgent tool exclusion behavior
Sub-agents running in target project directories (e.g., ../tiny-lru)
were trying to navigate back to madz. Added explicit WORKING DIRECTORY
section to prevent this behavior.
Sub-agents running in target directories (e.g., ../tiny-lru) were
denied file access because the cwd wasn't in the sandbox scope.
Now config.cwd is pushed into sandbox.paths at load time.
Only push config.cwd into sandbox.paths when running as a sub-agent,
preventing unnecessary path pollution for normal app runs.
@avoidwork avoidwork changed the title feat: add scanAgents tool for AGENTS.md discovery with cwd enforcement feat: enforce cwd and track PIDs in subAgent process delegation Jun 27, 2026
…l change

- Add 'What Actually Happened' sections to design.md and proposal.md
- Document the expanded scope beyond original scanAgents tool proposal
- Add scope delta table comparing original vs actual implementation
- Update .openspec.yaml with name, archived, and archivedDate fields
- Fill in Purpose sections for scan-agents and subagent specs
- Capture lessons learned about scope creep and architectural evolution
@avoidwork avoidwork enabled auto-merge (squash) June 27, 2026 19:33
@avoidwork avoidwork merged commit c8d900e into main Jun 27, 2026
2 checks passed
@avoidwork avoidwork deleted the feat/scan-agents-tool branch June 27, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant