Commit Graph

869 Commits

Author SHA1 Message Date
ismeth b4dd379b38 fix(council-archive): handle literal tag mentions inside response content
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:48:19 +09:00
ismeth 7d2749cfe1 fix(athena): address 11 audit findings (H2,H3,H5,M1-M4,M8-M11)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:48:13 +09:00
ismeth a13cc7b877 fix(council-finalize): patch path traversal vulnerabilities in name, task_ids, and prompt_file 2026-04-15 16:48:07 +09:00
ismeth a33a3d1095 refactor(athena): remove redundant council_read tool, use Read instead
council_read was a sandboxed readFile wrapper for .sisyphus/ archives.
Now that council_finalize extracts member responses into plain files,
the standard Read tool serves the same purpose. Removes the tool, its
tests, and updates Athena's prompt to reference Read directly.
2026-04-15 16:48:07 +09:00
ismeth 225a612b3a fix(test): update council-finalize assertions to match current runtime guidance wording 2026-04-15 16:48:01 +09:00
ismeth 34faa7c67c refactor(switch-agent): replace deferred hook system with direct session.create + promptAsync
Adopt the opencode-handoff pattern: switch_agent now creates a new session
and sends the context via promptAsync immediately in the tool's execute
function, then navigates the TUI to the new session.

Removes ~1700 LOC of complexity: persistent state management, event-based
hook monitoring, retry logic, session idle waiting, apply verification,
and terminal detection — all replaced by 3 SDK calls.

Deleted: src/features/agent-switch/ (14 files), src/hooks/agent-switch/ (4 files)
Updated: Athena prompt to announce handoff before calling switch_agent
2026-04-15 16:48:01 +09:00
ismeth 227a59a796 fix(athena): implement 10 prompt audit fixes from council review
- Fix 1: Clarify 'restart at Step 3' → 'restart the council workflow from Step 3 (intent classification)'
- Fix 2: Replace {council-session-name} with static references to council_finalize archive_dir
- Fix 3: Add documenting comment for call_omo_agent in solo mode allowlist
- Fix 4: Add delegation agent rationale comment to RUNTIME_GUIDANCE_BY_INTENT
- Fix 5: Type-safe COUNCIL_INTENT_ADDENDUMS with Record<CouncilIntent, string>
- Fix 6: Clarify FREEFORM wording re COUNCIL_MEMBER_RESPONSE tag requirement
- Fix 7: Remove dead Step 15 fallback from agent.ts
- Fix 8: Add compound question intent precedence guidance
- Fix 9: Fix AUDIT double-period typo
- Fix 10: Add edge case test for extractCouncilResponse with literal tag text
2026-04-15 16:47:57 +09:00
ismeth c265200f5f feat(athena): inject intent runtime guidance and action flows 2026-04-15 16:47:52 +09:00
ismeth e52ccd1b04 fix(agent-switch): create fresh session for handoff apply 2026-04-15 16:47:37 +09:00
ismeth 2c27298dc1 fix(council-archive): simplify finalize output and archive reads 2026-04-15 16:47:33 +09:00
ismeth c27b309320 feat(athena): expand council intent system from 4 to 8 intents
Add DIAGNOSE, CREATE, PERSPECTIVES, FREEFORM intents to Athena's council
classification system. Refine existing AUDIT (add DIAGNOSE boundary),
EVALUATE (improve criteria guidance), and EXPLAIN (remove catch-all status).

Fix bug where prepare_council_prompt defaulted to AUDIT when no intent was
specified — this caused analytical frameworks to be injected into creative
requests (e.g. poetry). Now defaults to no addendum.

Derive validIntents from Object.keys(COUNCIL_INTENT_ADDENDUMS) to prevent
drift between the addendums record and the validation array.
2026-04-15 16:47:33 +09:00
ismeth f5829bf2fb fix(athena): resolve task output files to project directory instead of process.cwd()
task-output-writer wrote to process.cwd()/.sisyphus/task-outputs/ while
council_finalize read from ctx.directory/.sisyphus/task-outputs/. When
these differ, all output files appear missing.

Fix by passing directory to writeTaskOutput from BackgroundManager, and
adding basePath to council_read. Also removes process.chdir() from tests
that was masking the bug.
2026-04-15 16:47:20 +09:00
ismeth aa91c1fb19 fix(glob): extract directory prefix from pattern for ripgrep compatibility
Ripgrep's --glob flag silently returns no results when the pattern
contains a directory prefix (e.g. 'apps/backend/**/*.ts'). Models
naturally write patterns this way when exploring unfamiliar codebases.

Extract the static directory segments from the pattern, append them to
the search path, and pass only the glob portion to ripgrep.
2026-04-15 16:46:52 +09:00
ismeth 2b70130c08 feat(athena): council member continuation enforcer, tool allowlist, and prompt fixes
- Add council-continuation-enforcer to nudge council members until they
  output COUNCIL_MEMBER_RESPONSE, replacing the hacky post-compaction hack
- Add background_wait + background_cancel to council member tool allowlist
  so members can properly manage their explore agents before responding
- Update COUNCIL_DELEGATION_ADDENDUM prompt to instruct members to cancel
  pending tasks and wait for explore results before final response
- Fix council_finalize path resolution to use project directory
- Remove post-compaction-continuation.ts and recentlyCompactedSessions hack
- Add council-response-checker for detecting response tag in session messages
2026-04-15 16:46:05 +09:00
ismeth 684b746ee7 fix(tools): resolve relative paths in glob/grep against project directory
When models pass relative paths (e.g. 'apps/ios/CleanSlate') to glob/grep
tools, they were passed directly to ripgrep which resolved them against
process.cwd(). In OpenCode Desktop, process.cwd() is '/' causing all
relative path lookups to fail with 'No such file or directory'.

Fix: use path.resolve(ctx.directory, args.path) to resolve relative paths
against the project directory instead of relying on process.cwd().
2026-04-15 16:43:54 +09:00
ismeth 8676b1cdb9 fix(tools): resolve relative paths in glob/grep against project directory
When models pass relative paths (e.g. 'apps/ios/CleanSlate') to glob/grep
tools, they were passed directly to ripgrep which resolved them against
process.cwd(). In OpenCode Desktop, process.cwd() is '/' causing all
relative path lookups to fail with 'No such file or directory'.

Fix: use path.resolve(ctx.directory, args.path) to resolve relative paths
against the project directory instead of relying on process.cwd().
2026-04-15 16:43:54 +09:00
ismeth da446979f6 test(athena): add tests for intent addendums, hook enforcement, restriction parity, and council prompt regression 2026-04-15 16:43:48 +09:00
ismeth 6b450b42db feat(athena): add intent parameter to prepare_council_prompt + wire hook into plugin system + update exports 2026-04-15 16:43:17 +09:00
ismeth e198707e84 test(council-archive): add integration tests for full council flow 2026-04-15 16:43:17 +09:00
ismeth c644643aef feat(background-agent): integrate file writing in completion path and remove dead council code
- Add _isCompleting guard and writeTaskOutput call before status flip
- Propagate writeOutputToFile from LaunchInput to BackgroundTask
- Delete council-result-format.ts and tests (no longer needed)
- 38/38 tests passing
2026-04-15 16:43:17 +09:00
ismeth b6b956c4c3 feat(council-archive): register council tools and add write_output_to_file to task tool
- Register council_finalize and council_read in tool registry
- Add write_output_to_file param to delegate-task, propagate to LaunchInput
- Create council-archive barrel exports
2026-04-15 16:43:17 +09:00
ismeth 2a426860f6 feat(council-archive): add council_finalize and council_read tools, refactor background_wait to metadata-only
- council_finalize: batch extract, archive, and return council results
- council_read: secure file reader for archived council responses
- background_wait: stripped to metadata-only, returns completed_tasks array
- Removed all council-specific logic from background_wait
- 28/28 tests passing across all changed files
2026-04-15 16:42:49 +09:00
ismeth b7552f13ac feat(council-archive): add shared extraction utility and background task type extensions
- Create council-response-extractor.ts with ported extractCouncilResponse()
- Add writeOutputToFile, outputFilePath, _isCompleting to BackgroundTask
- Add writeOutputToFile to LaunchInput
- 8/8 extraction tests passing
2026-04-15 16:42:49 +09:00
ismeth 5a819d0914 fix(athena): address 5 audit findings — remove harmful thinking config, add error handling, improve tests
- Remove applyModelThinkingConfig and all callers (OpenCode handles thinking natively)

- Add try/catch error handling to prepare_council_prompt filesystem operations

- Add mode input validation to prepare_council_prompt tool

- Add 2 missing placeholder test cases (RETRY_FAILED_IF_OTHERS_FINISHED, CANCEL_RETRYING_ON_QUORUM)

- Remove redundant 'Do NOT use TodoWrite' prompt section from council member agent
2026-04-15 16:42:33 +09:00
ismeth 4cd27f620e test(background-task): add tests for background_wait JSON output contract 2026-04-15 16:42:28 +09:00
ismeth 3dd378fce6 test(background-task): add tests for council result formatter and tag extraction 2026-04-15 16:42:28 +09:00
ismeth d055e19753 feat(background-task): convert background_wait output to structured JSON 2026-04-15 16:42:28 +09:00
ismeth ecf334dcd6 feat(background-task): add council-specific result formatter with COUNCIL_MEMBER_RESPONSE tag extraction 2026-04-15 16:42:28 +09:00
ismeth b8f3e5434f fix(athena): remove duplicate council prompt, add temp file cleanup, fix code quality
- Remove COUNCIL_MEMBER_PROMPT from temp file content since it's already
  provided as the council member's system prompt via agent config, saving
  ~350+ tokens per council member per invocation
- Add startup cleanup for stale athena-council-*.md files older than 30
  minutes in .sisyphus/tmp/ to handle cases where process exits before
  setTimeout cleanup fires
- Remove redundant intermediate permission object spread in createAthenaAgent
- Fix test style: it() -> test(), add #given/#then prefixes per conventions
2026-04-15 16:42:22 +09:00
ismeth 5cbf08eabc fix(athena): add solo/delegation addendums, recommend delegation mode
Both modes now inject explicit instructions: solo warns against subagent usage, delegation provides concrete call_omo_agent examples. Delegation is now the recommended default to reduce context window pressure on council members.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:42:13 +09:00
ismeth 656907ada0 fix(athena): council review fixes — delegation bug, dead code, test coverage
- Add background_output to council-member allowlist (fixes delegation deadlock)
- Replace empty catch with error logging in prepare-council-prompt
- Remove unnecessary type assertion in agent.ts
- Remove dead hasAgentToolRestrictions function
- Fix incorrect test assertions (undefined vs false semantics)
- Add barrel export for athena module
- Add guard function test coverage (5 tests)
- Add parity test for triple-sync restrictions (9 tests)
2026-04-15 16:41:53 +09:00
ismeth fb543f88d5 fix(athena): harden council members — compaction recovery, block TodoWrite, analysis mode
- Add session.compacted handler in BackgroundManager to prevent premature
  task completion after compaction (defer first post-compaction idle)
- Explicitly block TodoWrite/TodoRead for council members in all sync
  points (AgentConfig permission + session tools + prompt instructions)
- Add council member prefix check to todo-continuation-enforcer skip list
  to prevent infinite continuation loops on completed council members
- Add optional analysis mode (solo/delegation) question to Athena setup:
  solo = thorough but heavier, delegation = fast via explore/librarian
- Allow call_omo_agent in council member allow-list for delegation mode
- Update COUNCIL_MEMBER_PROMPT with TodoWrite prohibition and delegation
  addendum for when delegation mode is selected
- Update prepare_council_prompt tool with mode parameter
2026-04-15 16:41:02 +09:00
ismeth c75ae6bffd fix(athena): write council prompt to .sisyphus/tmp/, switch to allow-list permissions
Council members now use an allow-list (read, grep, glob, lsp_*, ast_grep_search)
instead of a deny-list. Prompt file moved from /tmp/ to .sisyphus/tmp/ so no
external_directory permission is needed. COUNCIL_MEMBER_PROMPT is included in
the temp file for self-contained council member instructions.
2026-04-15 16:39:28 +09:00
ismeth b606c27c61 fix(athena): use explicit node:crypto import for randomUUID 2026-04-15 16:39:28 +09:00
ismeth da0fba3166 feat(athena): add prepare_council_prompt tool for faster council launches
Athena saves the analysis prompt to a temp file once, then launches each
council member with a short "Read <path> for your instructions" prompt.
This eliminates repeated prompt text across N task calls while preserving
individual clickable task panes in the TUI.
2026-04-15 16:39:28 +09:00
ismeth d0639baeca fix: enforce directory param in skill resolution, replace legacy k2p5 model ID
- Make directory required in SkillLoadOptions, getAllSkills, and async
  skill template resolvers to prevent unsafe process.cwd() fallback
- Remove dead skill export and process.cwd() fallback in skill tool
- Replace kimi-for-coding/k2p5 with kimi-for-coding/kimi-k2.5 in
  council-members-generator
2026-04-15 16:36:38 +09:00
ismeth 9330ec806b refactor(event): remove runHookSafely wrapper, align with upstream dispatch pattern 2026-04-15 16:35:25 +09:00
ismeth 99e577d1e1 fix: abort signal in polling loops, remove legacy k2p5, pass ctx.directory to skill tool
- Check context.abort in background-wait and background-output polling loops
- Remove legacy kimi-for-coding/k2p5 from athena fallback chain
- Pass ctx.directory from tool-registry to createSkillTool instead of process.cwd()
2026-04-15 16:34:59 +09:00
ismeth ad481472eb refactor(athena): consolidate parseModelString to single source of truth 2026-04-15 16:34:01 +09:00
ismeth ac42ff6788 refactor(athena): remove athena_council from plugin wiring
Drop the barrel export, tool-registry registration, and agent-tool-restriction entry for the deleted athena_council tool.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:24:16 +09:00
ismeth 0b56880f4d refactor(athena): delete athena_council tool directory
Remove the entire custom tool implementation (constants, launcher, session-waiter, tool-helpers, tools, types, and all tests). Council members are now launched via the standard task tool.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:23:31 +09:00
ismeth c40185628b fix(athena): use background_wait for council progress instead of polling
Athena now uses background_wait (race-style) to collect council results with incremental progress instead of sequential background_output calls or rapid polling. Updated both the system prompt and tool description to guide Athena to the correct waiting pattern.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:23:31 +09:00
ismeth 30d33ccced feat(athena): add background_wait tool for race-style task collection
New tool that takes multiple task IDs and blocks until ANY one completes (Promise.race pattern). Returns the completed task's result plus a progress summary with remaining IDs. Enables Athena to show incremental council progress without polling.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:23:31 +09:00
ismeth bbb8fdcca7 refactor(athena): extract tool helpers and improve type safety
- Extract helper functions from tools.ts into dedicated tool-helpers.ts
- Replace getToolContextProperty workaround with typed AthenaCouncilToolContext
- Remove dead code path in formatCouncilLaunchFailure
- Add logging for council member launch and session resolution
- Update tool description to reflect notification-based workflow

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:22:28 +09:00
ismeth 5d32d5891b fix(athena): harden council tool error handling and type safety
Improve not-configured error message with config file path. Wrap metadataFn in try/catch for best-effort metadata. Replace unsafe as-casts with getToolContextProperty helper. Show Name (model) format in errors. Return error directly for empty member selection.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:22:28 +09:00
ismeth f0922ecb4d fix(athena): add partial result tracking to session-waiter
Return CouncilSessionWaitResult with timedOut/aborted flags instead of raw array, so callers know when results are partial. Add 5 tests covering normal flow, abort, partial results, and edge cases.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:22:28 +09:00
ismeth 94bd5ac47f refactor(athena): remove dead session-guard code and unused types
Remove session-guard.ts (runtime gating uses hasPendingCouncilMembers instead), its test file, and dead snake_case type interfaces from types.ts that don't match the camelCase code.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 16:22:28 +09:00
ismeth 8de10c1f2b fix(agent-switch): make handoff durable and sync CLI TUI selection 2026-04-15 16:18:19 +09:00
ismeth 4764d65db1 fix(athena): parallelize council launches and gate handoff actions 2026-04-15 16:17:43 +09:00
ismeth ca199ee85b fix(athena): make council tool blocking — collect results directly instead of polling
The athena_council tool now waits for all council members to complete and
returns their collected results as markdown, eliminating the need for
Athena to repeatedly call background_output per member (which created
excessive UI noise).

- Add result-collector.ts that polls task status and fetches session content
- Update tool to accept BackgroundOutputClient and return formatted markdown
- Update Athena prompt to remove background_output polling steps
- Rewrite tests for new blocking behavior and markdown output format
2026-04-15 15:56:56 +09:00