832 Commits

Author SHA1 Message Date
Dhanji R. Prasanna
085688479b Improve terminal width responsiveness for tool output
Clip summary text and other long fields to fit terminal width:

- Clip display_summary in print_tool_compact (e.g., "47 lines (2.0k chars)")
- Account for header_suffix length when compressing paths in print_tool_output_header
- Clip TODO item lines in print_todo_compact
- Clip plan item descriptions, evidence, touches, checks, and paths in print_plan_compact
- Replace hardcoded 70/40 char limits with dynamic terminal-width-based clipping

All clipping uses clip_line() which handles UTF-8 safely and adds ellipsis.
2026-02-05 20:44:12 +11:00
Dhanji R. Prasanna
19162b1fe6 Exit plan mode when plan is completed or blocked
When a plan reaches a terminal state (all items done or blocked) in
interactive mode, automatically exit plan mode and return to normal
prompt.

Changes:
- Add Agent::is_plan_terminal() method to check if plan is complete
- Add check_and_exit_plan_mode_if_terminal() helper in interactive.rs
- Call the helper after each execute_user_input() to detect completion

Fixes issue where plan mode prompt ' >> ' persisted after plan completion.
2026-02-05 20:31:24 +11:00
Dhanji R. Prasanna
30627bce97 feat(cli): make tool output responsive to terminal width
- Add terminal_width module with get_terminal_width(), clip_line(),
  compress_path(), and compress_command() utilities
- Update ConsoleUiWriter to use dynamic terminal width for all tool output
- Tool output lines are clipped to fit without wrapping
- Tool headers use semantic compression (paths preserve filename,
  commands clip from right)
- 4-character right margin for visual clarity
- Minimum 40 columns, default 80 when terminal size unavailable
- All truncation is UTF-8 safe (char counting, not byte slicing)
- Add 13 unit tests for terminal width utilities
2026-02-05 20:18:30 +11:00
Dhanji R. Prasanna
b2fbcf33d0 Fix plan approval gate and add "Create a plan:" prefix for first message
- Fix build warnings: add #[allow(dead_code)] to unused deserialization fields
- Fix plan approval gate bug: block file changes when no plan exists (not just
  when plan exists but is unapproved)
- Add "Create a plan: " prefix to first user message in plan mode
- Add prepare_plan_mode_input() helper function for testability
- Reset is_first_plan_message flag when entering plan mode via /plan command
- Add tests for approval gate (no plan + no changes, no plan + changes)
- Add tests for prepare_plan_mode_input (happy, negative, boundary cases)
2026-02-05 19:43:38 +11:00
Dhanji R. Prasanna
06d75f613c feat(plan): display rulespec.yaml and envelope.yaml in plan_read/plan_write output
- Add format_envelope_markdown() function in invariants.rs for rich markdown
  formatting of ActionEnvelope facts
- Add format_yaml_value_markdown() helper for recursive YAML value display
- Update execute_plan_read() to append rulespec and envelope sections
- Update execute_plan_write() to append envelope section alongside rulespec
- Add 3 tests for format_envelope_markdown (empty, with facts, null values)

When plan_read or plan_write is called, the output now includes:
- Plan YAML (as before)
- Rulespec section (if rulespec.yaml exists) with invariants grouped by source
- Envelope section (if envelope.yaml exists) with facts in readable format

Missing files show placeholder text rather than errors.
2026-02-05 19:08:55 +11:00
Dhanji R. Prasanna
bc5c1bdf61 Fix plan UI formatting to handle Vec<Check> and display elegantly
- Update ChecksCompact to use Vec<CheckCompact> for negative/boundary fields
- Add progress bar visualization showing done/doing/blocked/todo counts
- Show evidence for done items, checks for active items
- Display all negative and boundary checks (not just first)
- Add proper tree structure with └/├ prefixes
- Truncate long descriptions and evidence paths
- Add file path display with 📄 icon
2026-02-05 14:38:18 +11:00
Dhanji R. Prasanna
e34f37fd47 Merge sessions/sdlc/3b6c6c3e into main
Resolved conflicts:
- analysis/memory.md: kept condensed documentation from incoming branch
- crates/g3-core/src/skills/embedded.rs: removed unused HashMap import, kept better doc comment

Additional fix:
- crates/g3-core/src/prompts.rs: updated test to match current prompt file content
2026-02-05 14:38:08 +11:00
Dhanji R. Prasanna
307f04fa25 chore: Compress workspace memory after research externalization
- Remove deleted code: pending_research.rs, tools/research.rs (externalized to skill)
- Merge duplicate Agent Skills entries into unified section
- Update SDLC state path: analysis/sdlc/ → .g3/sdlc/
- Remove G3Status.resuming() (deleted in 6228001)
- Tighten verbose descriptions throughout

Metrics: 444 → 325 lines (-27%), 23.6k → 17.0k chars (-28%)
Concepts preserved: all semantic information retained

Agent: huffman
2026-02-05 14:29:48 +11:00
Dhanji R. Prasanna
74c2671e1b docs: Update documentation for Agent Skills system
Document the new Skills system introduced in recent commits:

- docs/architecture.md: Add Skills System section with discovery
  priority, embedded skills, script extraction, and key types
- docs/skills.md: New comprehensive guide covering SKILL.md format,
  discovery priority, embedded skills, research skill usage, and
  troubleshooting
- README.md: Update Agent Skills section with correct priority order,
  add embedded skills info, research skill usage, and link to Skills
  Guide in Documentation Map
- AGENTS.md: Add skill creation to Adding Features, skill extraction
  to Dangerous Code Paths, and new Skills System Entry Points section

All documentation links validated - no broken links or orphan files.

Agent: lamport
2026-02-05 14:26:26 +11:00
Dhanji R. Prasanna
cff32bf0ba Make research skill self-contained without external scripts
- Rewrite SKILL.md with inline instructions to spawn g3 --agent scout directly
- Extend read_file to handle embedded skill paths (<embedded:name>/SKILL.md)
- Remove scripts field from EmbeddedSkill struct (no longer needed)
- Delete extraction.rs module (was only for script extraction)
- Delete g3-research bash script
- Remove obsolete Async Research Tool section from workspace memory

Skills are now fully portable - they work when g3 is installed as a
binary without access to source files. Agents can read embedded skill
content via read_file with the special <embedded:...> path syntax.
2026-02-05 14:22:17 +11:00
Dhanji R. Prasanna
c3549ce043 refactor: Remove unused functions from skills module
- Remove is_embedded_skill() from discovery.rs (unused)
- Remove get_embedded_skills_map() from embedded.rs (unused)
- Remove associated tests for deleted functions
- Inline path check in test_repo_overrides_embedded test

This eliminates dead code warnings and reduces module surface area
without changing any behavior.

Agent: fowler
2026-02-05 14:17:56 +11:00
Dhanji R. Prasanna
38da6a56ef analysis: Update dependency graph for commits b6d2582..9443f933
Focused analysis on past 10 commits covering:
- New skills module in g3-core (parser, discovery, prompt, embedded, extraction)
- Research tool externalized to skills/research/ skill
- SkillsConfig added to g3-config
- SDLC pipeline state moved to .g3/sdlc/

Key findings:
- 4 crates changed, 29 files affected (8 added, 2 deleted, 19 modified)
- No dependency cycles detected
- Clean DAG structure in new skills module
- Cross-crate coupling via g3-core::skills and g3-config::SkillsConfig
- Compile-time coupling to skills/research/ via include_str!

Agent: euler
2026-02-05 14:02:44 +11:00
Dhanji R. Prasanna
788debb93a remove cruft from system prompt 2026-02-05 14:01:26 +11:00
Dhanji R. Prasanna
68fd7b96c1 Remove accidental Emacs lock file 2026-02-05 14:01:03 +11:00
Dhanji R. Prasanna
6cb70f26fa Fix empty Language-Specific Guidance header in system prompt
When a Rust-only workspace was detected, the Language-Specific Guidance
header was appearing with no content because Rust has an empty prompt
string (agent-specific prompts handle Rust instead).

The fix filters out empty prompt strings in get_language_prompts_for_workspace()
so the header only appears when there's actual guidance content.

Added test to verify Rust-only workspaces return None.
2026-02-05 14:00:52 +11:00
Dhanji R. Prasanna
9443f9333b refactor: Remove hardcoded Web Research section from system prompt
- Web Research instructions now come from skills/research/SKILL.md
- Skills are dynamically loaded and injected via generate_skills_prompt()
- Remove test_both_prompts_have_web_research test (no longer applicable)
- Remove unused G3Status::research_complete() function

This completes the externalization of research as a skill.
2026-02-05 13:41:53 +11:00
Dhanji R. Prasanna
0b308853a0 fix: Improve research skill with ANSI stripping and fallback extraction
- Add strip_ansi() function using perl for comprehensive escape sequence removal
- Add fallback extraction when scout doesn't output markers
- Strip g3 UI elements (session banner, tool output chrome, auto-memory messages)
- Reports are now clean plaintext without terminal formatting
2026-02-05 13:35:32 +11:00
Dhanji R. Prasanna
39e586982c feat: Externalize research tool as embedded skill
Replaces the built-in research/research_status tools with a portable
skill-based approach:

- Add embedded skills infrastructure (skills compiled into binary)
- Add repo-local skills/ directory support (highest priority)
- Create research skill with SKILL.md and g3-research shell script
- Script extraction to .g3/bin/ with version tracking
- Filesystem-based handoff via .g3/research/<id>/status.json
- Remove PendingResearchManager and all research tool code
- Update system prompt to reference skill instead of tool

Benefits:
- No special tool infrastructure needed (just shell + read_file)
- Context-efficient (reports stay on disk until needed)
- Crash-resilient (state persisted to filesystem)
- Portable (skill can be overridden per-workspace)

Breaking change: research tool calls now return a deprecation message
pointing to the research skill.
2026-02-05 13:23:26 +11:00
Dhanji R. Prasanna
bf9e3dc878 Merge sessions/interactive/213d9910 2026-02-05 13:05:57 +11:00
Dhanji R. Prasanna
89c071baf6 fix: honor --resume flag when used with --agent --chat
The --resume flag was being ignored when --agent and --chat flags were
used together. The if-else chain checked for chat mode first and
immediately returned None, skipping the --resume check entirely.

Reordered the logic to check flags.resume first, ensuring explicit
--resume is always honored regardless of other flags.

Fixes: --resume not working with --agent --chat
2026-02-05 13:05:48 +11:00
Dhanji R. Prasanna
bc2860dd3a studio sdlc: merge worktree on completion, move state to .g3/
- Add merge step before worktree cleanup when pipeline completes
- On success with commits: merge to main, then cleanup
- On failure: preserve worktree for debugging, print path
- On merge conflict: preserve worktree, print resolution instructions
- Move pipeline.json from analysis/sdlc/ to .g3/sdlc/ (gitignored)
2026-02-05 13:03:54 +11:00
Dhanji R. Prasanna
0e64f13a8a Merge feature/agent-skills-support: Agent Skills specification support 2026-02-05 12:46:53 +11:00
Dhanji R. Prasanna
6228001bfc Remove automatic session resume suggestion on startup
- Remove the interactive prompt that asked users to resume in-progress sessions
- Remove unused new_session parameter from run_interactive()
- Remove unused info_inline() function from G3Status
- Explicit --resume <session_id> flag still works
2026-02-05 12:40:27 +11:00
Dhanji R. Prasanna
8bbaf6f02e Tighten system prompt and tool definitions
Prompt changes (native.md):
- Remove duplicate 'Temporary files' section
- Consolidate 'remember' instructions into single authoritative location
- Remove motivational 'Benefits' list from Plan Mode
- Add 'Code Search Tool Selection' guidance (code_search vs rg)

Tool changes (tool_definitions.rs, tool_dispatch.rs):
- Remove screenshot tool (webdriver_screenshot remains)
- Remove coverage tool
- Reduce plan_write description from 22 lines to 1 line
- Update tool count tests (16 -> 14 core tools)

Net result: ~6 lines removed from prompt, ~56 lines removed from
tool definitions, clearer tool selection guidance added.
2026-02-05 12:36:49 +11:00
Dhanji R. Prasanna
b6d25824f3 Tighten system prompt 2026-02-05 12:01:01 +11:00
Dhanji R. Prasanna
25ad198b83 Sync agent plan mode state on CLI startup
CLI starts in plan mode by default (when not in agent mode), but was not
calling agent.set_plan_mode(true) at initialization. This meant the gate
check would not run until the user explicitly entered plan mode via /plan.
2026-02-05 11:47:38 +11:00
Dhanji R. Prasanna
b86901a86b Merge sessions/interactive/47299e3b 2026-02-05 11:47:24 +11:00
Dhanji R. Prasanna
3d3f68e6da Externalize native system prompt to markdown file
- Move system prompt for native tool calling models to prompts/system/native.md
- Use include_str! to embed at compile time
- Remove concatenated SHARED_* string constants
- Prompt is now readable/editable as a complete markdown document
- Non-native prompt still uses Rust constants (acceptable for now)
2026-02-05 11:46:49 +11:00
Dhanji R. Prasanna
0f919237ea Make plan approval gate only active in plan mode
- Add in_plan_mode flag to Agent struct
- Add set_plan_mode() and is_plan_mode() methods
- Gate check now only runs when in_plan_mode is true
- CLI calls set_plan_mode(true) on /plan command and EnterPlanMode
- CLI calls set_plan_mode(false) on approval and CTRL-D exit
- Update integration test to enable plan mode
- Fix test YAML to use Vec<Check> for negative/boundary checks
2026-02-05 11:41:52 +11:00
Dhanji R. Prasanna
3d284b8b60 Merge sessions/interactive/179ac8a6 2026-02-05 11:37:07 +11:00
Dhanji R. Prasanna
1f1a517620 feat(plan): support multiple negative and boundary checks
Change Plan Mode to allow multiple negative and boundary checks per item,
while keeping happy path as a single check.

Schema change:
- checks.negative: Check -> Vec<Check> (>=1 required)
- checks.boundary: Check -> Vec<Check> (>=1 required)
- checks.happy: Check (unchanged, single)

This better reflects real-world tasks where there are often multiple
error conditions and edge cases worth tracking.

Changes:
- Update Checks struct to use Vec<Check> for negative/boundary
- Update validation to require at least 1 of each
- Update prompts and tool definitions with new array syntax
- Add 4 new tests for multi-check scenarios
2026-02-05 11:36:45 +11:00
Dhanji R. Prasanna
41839b909e Remove stray test file 2026-02-05 11:34:15 +11:00
Dhanji R. Prasanna
c347a73cbd Add plan approval gate to block file changes without approved plan
- Add check_plan_approval_gate() in tools/plan.rs that runs after each tool call
- Detects file changes via git status --porcelain when plan exists but not approved
- Reverts changes: git checkout for modified files, rm for new untracked files
- Returns blocking message instructing LLM to create/approve plan first
- Add ApprovalGateResult enum with Allowed/Blocked/NotGitRepo variants
- Add set_session_id() and set_working_dir() methods on Agent for testing
- Add integration test using MockProvider to simulate blocked write_file
2026-02-05 11:34:10 +11:00
Dhanji R. Prasanna
add8060526 Add studio sdlc command for SDLC maintenance pipeline
Implements a pipeline that orchestrates 7 g3 agents in sequence:
1. euler - dependency graph and hotspots analysis
2. breaker - whitebox exploration and edge-case discovery
3. hopper - deep testing and regression integrity
4. fowler - refactoring to deduplicate and reduce complexity
5. carmack - in-place rewriting for readability and concision
6. lamport - human-readable documentation and validation
7. huffman - semantic compression of memory

Features:
- Commit cursor tracking (--from flag to set starting point)
- Crash recovery (resumes from last incomplete stage)
- Git worktree isolation for all pipeline work
- Visual pipeline display with status icons
- Summary generation saved to .g3/sessions/sdlc/
- Pipeline state persisted to analysis/sdlc/pipeline.json

CLI:
- studio sdlc run [-c N] [--from COMMIT]
- studio sdlc status
- studio sdlc reset

Also adds huffman agent to embedded agents list.
2026-02-05 10:46:10 +11:00
Dhanji R. Prasanna
fdb1255f02 Add --resume <session-id> flag for explicit session resumption
- Add --resume CLI flag that conflicts with --new-session
- Add load_continuation_by_id() to load sessions by full or partial ID
- Support loading from latest.json or falling back to session.json
- Handle --resume in both normal and agent modes
- Agent mode validates session belongs to correct agent
2026-02-05 10:23:39 +11:00
Dhanji R. Prasanna
3046f0dd6e feat: Add invariants system for Plan Mode verification
Adds rulespec.yaml and envelope.yaml support for machine-readable
invariant checking during plan completion.

- Add invariants module with Rulespec, ActionEnvelope, and evaluation logic
- Add Invariants section to system prompt with workflow instructions
- Show rulespec/envelope file status in plan verification output
- Rulespec written during planning (captures constraints from task)
- Envelope written after implementation (documents what was built)
2026-02-04 20:49:58 +11:00
Dhanji R. Prasanna
a5f6475603 feat: implement Agent Skills specification support
Implements the Agent Skills specification (https://agentskills.io) for
portable skill packages that give the agent new capabilities.

Changes:
- Add skills module with SKILL.md parser (YAML frontmatter + markdown body)
- Implement skill discovery from ~/.g3/skills/, config extra_paths, and .g3/skills/
- Generate <available_skills> XML for system prompt injection
- Add SkillsConfig to g3-config with enabled flag and extra_paths
- Wire skills discovery into CLI startup
- Add 29 unit tests for parser, discovery, and prompt generation
- Update README with Agent Skills documentation

Skill locations (priority order):
1. ~/.g3/skills/ (global)
2. Config extra_paths
3. .g3/skills/ (workspace, highest priority)

At startup, g3 scans skill directories and injects a summary into the
system prompt. When the agent needs a skill, it reads the full SKILL.md
using the read_file tool.
2026-02-04 12:58:57 +11:00
Dhanji R. Prasanna
95d9847354 Update dependency analysis artifacts with detailed evidence
- hotspots.md: Added specific dependent file lists for each hotspot
- hotspots.md: Added cross-crate coupling points table
- hotspots.md: Added crate-level coupling scores
- limitations.md: Expanded coverage of unobservable patterns
- limitations.md: Added confidence levels for inferences
- limitations.md: Added extraction method details table

Agent: euler
2026-02-02 17:20:15 +11:00
Dhanji R. Prasanna
263a838d31 Remove redundant 'No plan exists' message from plan_read output
The UI already shows 'empty' via print_plan_compact, so returning an
empty string avoids duplicate output.
2026-02-02 17:19:01 +11:00
Dhanji R. Prasanna
e332109273 Auto-approve plans in non-interactive (autonomous/one-shot) mode
- Add auto-approval logic in execute_plan_write() when ctx.is_autonomous is true
- Update system prompt to document auto-approval behavior
- Plans still require explicit approval in interactive mode
2026-02-02 17:16:21 +11:00
Dhanji R. Prasanna
0aead8d86d fix: Enable compact UI output for plan_approve tool
Added plan_approve to the compact tool list in format_tool_result_summary()
so it displays in the same format as other tools like read_file and write_file.

The format_plan_approve_summary() function already existed but was never
called because plan_approve was missing from the matches! block.
2026-02-02 17:06:10 +11:00
Dhanji R. Prasanna
f8448e5622 feat: Plan Mode interactive flow with approval shortcuts
- Start g3 in plan mode with ' >>' prompt and welcome message
- Add is_approval_input() to detect 'approve', 'a', 'yes', etc. and misspellings
- Allow trailing punctuation (!, ., ,) on approval words
- Call plan_approve tool directly without LLM when approval detected
- Add synthetic assistant message after approval for LLM context
- Exit plan mode after successful approval, return to 'g3>' prompt
- CTRL-D in plan mode exits plan mode first, then exits g3
- /plan command enters plan mode and shows welcome message
- Agent mode (--agent) does not start in plan mode
- Add CommandResult enum to signal plan mode entry from commands
2026-02-02 16:59:52 +11:00
Dhanji R. Prasanna
9024f693fa Fix plan tool UI formatting
- Fix vertical bar continuation: │ continues all the way down, only the
  very last sub-line (boundary of last item) gets └
- Add visual gap before plan file path and change 📄 to ->
- Dedent file path to align with tree root
- Fix plan_approve to use proper compact tool format (was missing from
  is_compact_tool matches! in print_tool_compact, causing it to fall
  through to regular output with | prefix)
2026-02-02 16:29:37 +11:00
Dhanji R. Prasanna
e893794029 Rename /feature command to /plan
- Update command matching from /feature to /plan in commands.rs
- Update help text, usage message, and example
- Update workspace memory references
- /feature is no longer recognized (completely removed)
2026-02-02 16:00:09 +11:00
Dhanji R. Prasanna
8705228fda Fix input formatter bugs: apostrophe highlighting and line duplication
Fixes two bugs in the input formatter:

1. Single/double quote regex now requires word boundaries:
   - Contractions like it's, don't, won't no longer trigger highlighting
   - Only properly quoted text like 'special' or "hello" gets cyan
   - Mixed input like "it's a 'test' case" only highlights 'test'

2. Visual line calculation fix for exact terminal width:
   - When text exactly fills terminal width, cursor wraps to next line
   - Added +1 adjustment to account for this edge case
   - Extracted calculate_visual_lines() for testability

Added 9 new tests covering all edge cases.
2026-02-02 15:54:38 +11:00
Dhanji R. Prasanna
571188305a feat: add compact UI output for Plan Mode tools
Plan tools (plan_read, plan_write) now display with elegant tree-style
formatting similar to the old todo_write UI:

- State indicators: □ (todo), ◐ (doing), ■ (done), ⊘ (blocked)
- Tree prefixes (├/└) for items with child details
- Strikethrough for completed items
- Shows touches and all three checks (happy/negative/boundary)
- Displays plan file path link at the end

plan_approve uses compact single-line format like read_file:
- Shows approval status and revision number
- Handles already-approved and error cases

Changes:
- Add print_plan_compact() to UiWriter trait with default impl
- Implement print_plan_compact() in ConsoleUiWriter
- Call print_plan_compact() from execute_plan_read/write
- Add plan_read/plan_write to is_self_handled_tool()
- Add plan_approve to is_compact_tool() with format_plan_approve_summary()
- Add serde_yaml dependency to g3-cli
2026-02-02 15:30:05 +11:00
Dhanji R. Prasanna
d6b7177107 Implement plan_verify() for deterministic evidence validation
Adds a verification system that checks evidence in completed plan items:

- Evidence parsing: supports code locations (file:line, file:line-line, file only)
  and test references (file::test_name)
- Code location verification: checks file exists, validates line numbers in range
- Test reference verification: checks test file exists, searches for fn pattern
- Verification results: Verified, Warning, Error, Skipped statuses
- Loud output formatting with emoji indicators for warnings/errors
- Integration with execute_plan_write(): runs when plan is complete and approved
- 12 new unit tests covering parsing and verification

Warnings are advisory (don't block), errors are loud but also don't block.
Blocked items are skipped during verification.
2026-02-02 15:15:03 +11:00
Dhanji R. Prasanna
a63950d8f5 Add Plan Mode to replace TODO system
Plan Mode is a cognitive forcing system that requires reasoning about:
- Happy path
- Negative case
- Boundary condition

New tools:
- plan_read: Read current plan for session
- plan_write: Create/update plan with YAML content (validates structure)
- plan_approve: Mark current revision as approved

New command:
- /feature <description>: Start Plan Mode for a new feature

Plan schema requires:
- plan_id, revision, approved_revision
- items with id, description, state, touches, checks (happy/negative/boundary)
- evidence and notes required when marking items done

Verification:
- plan_verify() called automatically when all items are done/blocked

Removed:
- todo_read, todo_write tools
- todo.rs module and related tests
2026-02-02 14:38:25 +11:00
Dhanji R. Prasanna
7fc9eb0778 Fix doc-test failure in GLM adapter
Use quadruple backticks for outer code fence to properly escape
the nested code fence example showing JSON format.
2026-01-30 14:53:04 +11:00
Dhanji R. Prasanna
afc5bc8574 Readability improvements across streaming_parser, input_formatter, commands
- streaming_parser.rs: Reduced ~70 lines by removing redundant comments,
  consolidating doc comments, using slice syntax for TOOL_CALL_PATTERNS
- input_formatter.rs: Lazy regex compilation via once_cell (performance),
  cleaner function structure, reduced comment noise
- commands.rs: Extracted format_research_task_summary() and
  format_research_report_header() helpers, reduced ~40 lines of duplication
- pending_research.rs: Fixed 2 unused variable warnings in tests

All changes are behavior-preserving. 446 tests pass.

Agent: carmack
2026-01-30 14:48:08 +11:00