Commit graph

3052 commits

Author SHA1 Message Date
Mikael Hugo
02a4339a51 refactor: rename pi-* packages to forge-native names (Phase 1)
Rename all four packages/pi-* directories to forge-native names,
stripping the 'pi' identity and establishing forge's own:

- packages/pi-coding-agent → packages/coding-agent
- packages/pi-ai → packages/ai
- packages/pi-agent-core → packages/agent-core
- packages/pi-tui → packages/tui

Package names updated:
- @singularity-forge/pi-coding-agent → @singularity-forge/coding-agent
- @singularity-forge/pi-ai → @singularity-forge/ai
- @singularity-forge/pi-agent-core → @singularity-forge/agent-core
- @singularity-forge/pi-tui → @singularity-forge/tui

All import references, bare string references, path references,
internal variable names (_bundledPi*), and dist files updated.
@mariozechner/pi-* third-party compat aliases preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 11:28:01 +02:00
Mikael Hugo
05953e9599 fix(lint): restore 0 Biome diagnostics and fix web-mode-onboarding test timeout
- Remove/prefix unused imports and variables across 11 src/ files to clear
  74 diagnostics introduced by 37 subsequent commits since run #3
- Fix pre-existing timeout in web-mode-onboarding integration test:
  - Add timeoutMs: 120_000 to launchPackagedWebHost call (was unbounded)
  - Raise AbortSignal.timeout on simple fetches 10s → 30s (under parallel load)
  - Raise overall test timeout 180s → 420s (budget: 120+60+30+30+120+30=390s)
- Log autoresearch run #4 and update lessons in autoresearch.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 11:01:43 +02:00
Mikael Hugo
b2bcb922de sf snapshot: uncommitted changes after 37m inactivity 2026-05-10 09:56:56 +02:00
Mikael Hugo
7e8e3aa846 sf snapshot: pre-dispatch, uncommitted changes after 30m inactivity 2026-05-10 09:19:51 +02:00
Mikael Hugo
e58e138457 feat(db): DB-only UAT verdicts — backfill on open, write on ASSESSMENT save, no file fallbacks
- sf-db.js: add backfillUatVerdicts(basePath) that scans ASSESSMENT/UAT_RESULT
  files for slices with no uat_verdict in DB and populates them on open
- dynamic-tools.js: call backfillUatVerdicts after openDatabase succeeds so
  all 3 repos with existing verdict files are covered on next launch
- workflow-tool-executors.js: call setSliceUatVerdict when saving ASSESSMENT
  at slice scope so future verdicts are written directly to DB
- workflow-helpers.js: remove all file fallbacks from checkNeedsRunUat;
  verdict check is DB-only (backfill guarantees DB is populated on open)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 08:49:45 +02:00
Mikael Hugo
6c113be473 fix(uat): treat ASSESSMENT file with verdict as completed UAT result
checkNeedsRunUat only checked for UAT_RESULT file, but the autonomous
runner writes ASSESSMENT files. This caused run-uat to dispatch 5x with
no verdict when only an ASSESSMENT (with verdict: PASS) existed.

Now ASSESSMENT file with any verdict counts as a completed UAT result,
stopping the infinite dispatch loop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 08:32:21 +02:00
Mikael Hugo
d8c687702b fix(auto): cache lastCommandCtx from any SF command so Ctrl+Y works immediately
Previously required /autonomous first. Now any slash command (/next, /chat,
/clear etc.) caches the ExtensionCommandContext, so Ctrl+Y YOLO shortcut
works on first press after any command interaction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 08:10:27 +02:00
Mikael Hugo
d56e68c789 fix(auto): revert YOLO shortcut to ctrl+y
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 07:59:10 +02:00
Mikael Hugo
60ee46aebb fix(auto): cache lastCommandCtx to survive shortcut-handler restarts
Shortcut handlers (registerShortcut) receive ExtensionContext which has
no newSession(). This caused autonomous mode started via Ctrl+Y to
always crash with 'newSession is not a function'.

- AutoSession.lastCommandCtx: new field that persists across stopAuto/reset
  so shortcut handlers can fall back to the last valid command context
- startAuto(): cache valid command ctx; fall back and notify user if ctx
  has no newSession; return early with actionable message if no cache yet
- dispatchHookUnit(): same guard — resolve hookCtx before s.cmdCtx = ctx
- run-unit.js: last-resort guard before newSession() call returns clean
  error category instead of TypeError
- steerable-autonomous-extension.js: rename ctrl+y → ctrl+alt+y to avoid
  conflict with terminal yank built-in

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 07:56:31 +02:00
Mikael Hugo
529138db9a sf snapshot: uncommitted changes after 33m inactivity 2026-05-10 07:54:07 +02:00
Mikael Hugo
7085ad850d refactor(tools): remove sf_ prefix from all remaining tool names
plan_milestone, plan_slice, plan_task, complete_task, complete_slice,
complete_milestone, skip_slice, replan_slice, reassess_roadmap,
validate_milestone, save_requirement, update_requirement, milestone_status

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 07:20:56 +02:00
Mikael Hugo
e7bd6a76b9 refactor(tools): improve description fields to be action-oriented and agent-facing
Rewrite all 13 renamed tool descriptions to follow Copilot tool conventions:
- Imperative verb opening
- One sentence on what it returns
- One sentence on when to use it
- No internal jargon or SF-specific acronyms

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 07:13:59 +02:00
Mikael Hugo
ac371926cb refactor(tools): rename SF tools to cleaner action-oriented names
Align tool names with Copilot coding agent conventions:
- sf_exec → run_command
- sf_exec_search → read_output
- sf_resume → resume_agent
- capture_thought → log_reasoning
- sf_log_judgment → log_decision
- sf_self_report → report_issue
- sf_self_feedback_resolve → resolve_issue
- sf_save_gate_result → record_gate
- sf_autonomous_checkpoint → checkpoint
- sf_milestone_generate_id → new_milestone_id
- sf_graph → memory_graph
- memory_query → memory_search
- sf_retrieval_evidence → search_evidence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 07:10:41 +02:00
Mikael Hugo
1322bc7d9a feat: implement Copilot coding agent lessons in SF
- fix(compaction): tokensBefore undefined crash on reload
  compaction-orchestrator now falls back to preparation.totalTokens when
  extension returns tokensBefore: undefined; compaction-summary-message
  guards with ?? 0 defensively

- feat(exec): inline truncation notice in sf_exec digest
  appends [stdout truncated — read full output: <path>] when
  stdout_truncated=true so agent knows to use sf_exec_search

- feat(exec): wire onUpdate progress for sf_exec
  calls onUpdate before execution starts with status/command so TUI
  shows live feedback during long-running commands

- feat(security): prompt injection defense for external content
  new sanitize-external-content.js utility: strips HTML comments,
  detects 15 injection patterns (instruction override, role reassignment,
  fake system messages, encoded payloads); wired into exec-tool digest

- feat(tools): sf_session_todo tool (persisted cross-compaction)
  add/check/list ops; persists to .sf/session_todo.json; pending todos
  injected into compaction summary block for context continuity

- feat(hooks): shell hooks surface (.sf/hooks/pre-tool/*.sh, post-tool/*.sh)
  pre-tool hooks block tool execution (exit≠0 = block with stdout reason)
  post-tool hooks fire-and-forget; JSON context piped to stdin; 5s timeout

- fix(db): WAL autocheckpoint disabled to prevent corruption
  PRAGMA wal_autocheckpoint=0 in initSchema(); explicit checkpointWal()
  after successful finalize verification — the only safe checkpoint point

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 07:01:28 +02:00
Mikael Hugo
97619cbc74 fix: resolve 3 test failures and 1 pre-existing code bug
- unit-runtime: fall back to STATE.md for nextActionAdvanced when DB is
  unavailable (restores test compat for reconcileDurableCompleteUnitRuntime-
  Records; DB path still preferred in production)
- browser-slash-command-dispatch: remove 'stop' from SF_PASSTHROUGH_COMMANDS
  so /stop correctly returns { kind: 'reject' } in browser mode (was falling
  through to prompt/rpc instead of builtin-reject)
- bg-events: export MAX_PENDING_ALERTS so process-manager can re-export it;
  satisfies session-memory-leaks contract test
- commands-handlers: guard effectiveScope assignment — only use requestedScope
  when mode=audit AND requestedScope is truthy (avoids undefined propagation)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 04:55:56 +02:00
Mikael Hugo
be785ea13f fix(tui): restore auto mode bottom banner
Remove setFooter(hideFooter) calls in auto-start.js and auto.js that were
overriding the sf-tui footer with a near-invisible stub. The sf-tui footer
already checks isAutoActive() and routes to renderAutoFooter — no override
needed. Also remove now-unused hideFooter import from auto.js.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 04:33:54 +02:00
Mikael Hugo
01d58c570d sf snapshot: uncommitted changes after 36m inactivity 2026-05-10 04:27:43 +02:00
Mikael Hugo
1a0222fc71 fix(uok): reclassify 'tool unavailable' when checkpoint tool IS registered
The repair loop was classifying agent reports of 'tool unavailable' as
'checkpoint-tool-unavailable' even when sf_autonomous_checkpoint IS
registered in the manifest. This caused a self-referential loop: the
repair prompt re-requested the same tool call, the agent re-reported
unavailability, and the cycle repeated (4 repair attempts).

Fix: before classifying as 'checkpoint-tool-unavailable', verify the tool
is in the manifest. If it IS registered, reclassify as
'mentioned-checkpoint-without-tool' — the tool exists, the agent just
didn't call it. Also added existsSync to the ES module fs import in
autonomous-solver.js.

Test: new case in autonomous-solver.test.mjs verifies the reclassification
when tool IS in manifest.
2026-05-10 03:51:25 +02:00
Mikael Hugo
6b7d327672 sf snapshot: uncommitted changes after 30m inactivity 2026-05-10 03:21:24 +02:00
Mikael Hugo
1a681caa86 fix(auto): repair retries reuse session context instead of starting cold
When the autonomous solver fails to produce a checkpoint and enters the
repair loop, subsequent retries previously called newSession() each time,
wiping the conversation history. The agent restarted cold with no memory
of what it had tried, what tools it had called, or why it failed — making
meaningful repair nearly impossible.

This change adds a keepSession option to runUnit(). When true, the
newSession() call and session-switch guard logic are skipped; the repair
prompt is sent as a follow-up in the existing conversation. The agent can
now see its prior tool calls, file reads, and failure context when deciding
how to fix the issue.

Policy:
- First attempt at each unit: keepSession=false (clean session, correct
  for independent slice boundaries — system prompt carries project state)
- Repair retries within the same unit: keepSession=true (agent carries
  full context of what it already tried)
- Next unit after success/failure: keepSession=false (clean boundary)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 02:50:57 +02:00
Mikael Hugo
b464f2a78e fix: auto-fallback to ready provider instead of stopping autonomous mode
When the selected model's provider is not request-ready:
1. Pre-flight check before runUnit: find any ready provider, switch to it
   and continue. Only stop if no ready provider exists.
2. Post-runUnit cancelled handler: same logic — reselect + return 'continue'
   instead of silently breaking.
3. Both paths now emit a visible ctx.ui.notify so the user can see what
   happened ('provider X not ready — retrying with Y/model').

Previously: cancelled instantly, all 4 repair attempts also cancelled,
paused with misleading solver-missing-checkpoint and no user notification.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 02:33:23 +02:00
Mikael Hugo
7c970088f1 fix: skip missing-checkpoint repair loop when runUnit is cancelled
When runUnit() returns status='cancelled' (provider not ready, session
failed, timeout), there is no checkpoint to repair. Previously the code
called assessAutonomousSolverTurn() which saw no checkpoint and entered
the 4-attempt repair loop — all of which also cancelled instantly,
burning retries before pausing with a misleading solver-missing-checkpoint
reason instead of surfacing the real provider/session error.

Now: cancelled result short-circuits to { action: 'none' }, skipping the
repair loop and falling through to the existing cancelled handler which
correctly surfaces provider-not-ready, timeout, and session-failed errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 02:29:41 +02:00
Mikael Hugo
d6bd49d0b6 fix: sfdb-doctor agent partial - lazy imports in agent-end-recovery, db-tools uses milestone-ids.js
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 02:18:55 +02:00
Mikael Hugo
a3f2479a4c fix: remove stale M001/M002 milestone dirs; fix dispatch-guard circular dep; fix telemetry normalization
- Remove stale .sf/milestones/M001/ and M002/ (not in DB, were blocking dispatch)
- dispatch-guard.js: import findMilestoneIds from milestone-ids.js directly (not
  via guided-flow.js, which is in the circular-dep cluster)
- auto.js: normalize 'Cannot dispatch' → prior-slice-blocker, 'SF resources updated'
  → resources-stale, 'Stuck:' → stuck in telemetry (was silently bucketing as 'other')

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 02:12:13 +02:00
Mikael Hugo
ea360f6ad2 feat: add circular dep detection tool + fix duplicate milestone dirs + fix metrics NULL
- Add scripts/check-circular-deps.mjs using madge; npm run check:circular
  and check:circular:ext scan src/ and the SF extension respectively
- findMilestoneIds() is now DB-first: reads from milestones table when DB is
  open so stale/duplicate filesystem dirs (M001/ and M001-6377a4/) are never
  returned; falls back to fs scan only during early bootstrap
- milestone-id-utils.js was a stale duplicate; replaced with re-exports from
  canonical milestone-ids.js
- metrics-central.js: guard null/undefined counter/gauge/histogram values
  with ?? 0 to prevent NOT NULL constraint failure on metrics.value

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 01:56:08 +02:00
Mikael Hugo
15185c2e7d sf snapshot: uncommitted changes after 60m inactivity 2026-05-10 01:29:08 +02:00
Mikael Hugo
f66555456f sf snapshot: uncommitted changes after 72m inactivity 2026-05-10 00:28:55 +02:00
Mikael Hugo
6f174cabc1 sf snapshot: uncommitted changes after 59m inactivity 2026-05-09 23:16:14 +02:00
Mikael Hugo
d895cf2a16 fix: silence OpenTelemetry diag and LogTape meta startup warnings
- Align google-gemini-cli-provider's @google/gemini-cli-core dep from
  0.40.1 → 0.41.2 to match root; npm deduplicates to a single module
  instance, so diag.setLogger is called only once (no 'overwritten' warn)
- Add logtape.meta logger config at 'warning' level to suppress LogTape's
  own 'loggers are configured' info message on every startup

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 21:54:26 +02:00
Mikael Hugo
024485f050 feat(traceability): append SF-Session id to autonomous commit messages
- git-service.js autoCommit() accepts optional sessionId param
  - Appends 'SF-Session: <id>' trailer to commit message when present
  - Falls through cleanly when sessionId is undefined (quick tasks, templates)
- worktree.js autoCommitCurrentBranch() forwards sessionId
- auto-post-unit.js autoCommitUnit() reads session ID from getAutoSession()
  via s.cmdCtx?.sessionManager?.getSessionId?.() — same pattern as auto.js

Mirrors Copilot's session logs linked to each commit for cross-session traceability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 21:10:02 +02:00
Mikael Hugo
692328ad45 feat(memory): TTL expiry — supersede stale memories after 28/90 days
- Add expireStaleMemories(unstartedTtlDays=28, maxTtlDays=90) to sf-db.js
  - Never-accessed (hit_count=0) memories expire after 28 days
  - All memories expire after 90 days regardless of hit_count
  - Marks superseded_by='ttl-expired' (non-destructive, same as CAP_EXCEEDED pattern)
  - Returns count of expired memories (non-fatal on failure)
- Call from auto-start.js after DB opens at autonomous session start
  - Logs warning with count if any memories expired
  - Catches errors silently — TTL failure never blocks autonomous start

Mirrors Copilot Memory's 28-day TTL model learned from research.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 21:09:53 +02:00
Mikael Hugo
d2eda0cc12 feat(yolo): bypass all sandboxing — iteration limit, memory gates, guard breaks
YOLO = all guardrails off. When s.isYolo() is true the loop:
- Skips MAX_LOOP_ITERATIONS stop (logs warning, keeps going)
- Skips memory pressure stop (logs warning, accepts OOM risk)
- Bypasses guard breaks (logs warning, continues to next unit)

Build mode respects all these gates. YOLO does not.

Also fix notify messages: YOLO = no sandboxing, not just 'no prompts'
(autonomous mode already skips prompts — YOLO removes the safety net).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 20:00:56 +02:00
Mikael Hugo
6c132d5db0 fix(modes): clarify Build vs YOLO — Build can still pause; YOLO = no stops
Build mode: autonomous + broad permissions, may still pause at gates or
risky operations.
YOLO: Build + deep model + no stops, no confirmations at all.

- Fix Ask→Build confirm dialog message (was wrongly saying 'no further prompts')
- Fix YOLO notify messages to be accurate about what YOLO uniquely adds
- YOLO-off message clarifies Build may still pause

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 19:57:56 +02:00
Mikael Hugo
b9ea000341 feat(modes): Ask mode gates autonomous start with Build mode confirmation
When SF would start autonomous execution (startAuto) and the session is
in Ask mode (runControl=manual), it shows a confirm dialog:

  'Switch to Build mode? SF will execute without further prompts.'
  [Switch to Build] [Stay in Ask]

- On confirm: atomically applies the build preset (autonomous +
  unrestricted), then proceeds with execution.
- On decline: returns without starting — user stays in Ask.
- skipModeGate option available for callers that already handle this
  (e.g., explicit /autonomous command after user intent is clear).

This covers all startAuto callers: checkAutoStartAfterDiscuss, guided
flow action buttons, /next, and /autonomous.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 19:56:24 +02:00
Mikael Hugo
0712577f85 refactor(modes): collapse to Ask/Build; YOLO is a flag not a mode
- Remove 'plan' preset — ask covers discussion + planning, build covers execution
- Shift+Tab now cycles Ask ↔ Build (two stops, no awkward middle)
- YOLO (Ctrl+Y) forces Build mode if in Ask, then slams autonomous+deep+unrestricted
- Notify message shows 'switched to Build' when YOLO triggers a mode change
- YOLO off restores the pre-YOLO mode as before

Flow: Ask (user drives) → Build (SF drives) → Ctrl+Y (full send, no stops)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 19:53:22 +02:00
Mikael Hugo
fc60de80f5 fix(modes): presets own permissionProfile; build=unrestricted; default=normal
- Each preset now declares its own permissionProfile:
    ask  → normal   (conversational, can read/run safe commands)
    plan → normal   (structuring, not executing)
    build → unrestricted  (go do it, no permission prompts)

- setMode() calls for Shift+Tab and /mode now include permissionProfile
  so switching preset atomically sets all four axes.

- inferPresetName() includes permissionProfile in the match so status
  display shows 'build mode' only when permissions are also unrestricted.

- AutoSession default permissionProfile: 'restricted' → 'normal'
  (restricted was too conservative even for ask/chat use).

Flow: Ask (discuss) → Plan (structure) → Build (autonomous+unrestricted)
YOLO (Ctrl+Y) = build + autonomous + deep + unrestricted (turbo on top).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 19:46:57 +02:00
Mikael Hugo
b93409cfa4 feat(headless): add -y / --yolo CLI flag to sf headless
- HeadlessOptions.yolo added
- parseHeadlessArgs handles --yolo and -y (short form)
- SF_YOLO=1 is injected into the RPC child env when flag is set
- AutoSession._loadPersistedModeState() checks SF_YOLO=1 and
  auto-activates YOLO mode (build+autonomous+deep+unrestricted)
  on session startup

Usage:
  sf headless -y autonomous       # YOLO + autonomous mode
  sf headless --yolo next         # YOLO + run next unit

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 19:05:32 +02:00
Mikael Hugo
995a57335b fix(surfaces): stamp correct surface in AutoSession + /mode yolo headless command
Surface stamp:
- AutoSession._loadPersistedModeState() now calls detectSurface() to stamp
  the correct surface (headless/web/tui) from env vars on every startup.
  Persisted surface value was the previous launch's surface — wrong when
  switching between TUI and headless on the same project.
  SF_HEADLESS=1 → 'headless', SF_WEB_BRIDGE_TUI=1 → 'web', else 'tui'.

/mode yolo:
- handleModeCommand now recognises 'yolo' as a toggleable special case.
  Headless callers can now run: sf headless --command '/mode yolo'
  Same behaviour as Ctrl+Y: full-autonomy slam + settingsManager bypass.
  /mode catalog description updated to list 'yolo' as an option.

Documentation:
- headless.ts /query and /doctor short-circuits annotated as intentional
  architecture trade-offs with a note to keep them in sync with the extension.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 17:03:33 +02:00
Mikael Hugo
38a654d5e4 fix(ux): exit YOLO before Shift+Tab or /mode preset switch
Ghost state bug: pressing Shift+Tab or /mode while YOLO was active left
session.yolo=true and settingsManager bypass ON even though mode changed.

- Shift+Tab handler calls s.toggleYolo() + settingsManager.toggleYOLO()
  before cycling to the next preset when YOLO is active
- handleModeCommand does the same before applying a named preset

This keeps yolo flag, status display ('SF — 🚀 YOLO'), and safe-git bypass
in sync with the actual running mode at all times.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:56:14 +02:00
Mikael Hugo
f7381781fa feat(ux): Ask/Plan/Build mode presets + YOLO full-autonomy
- Add SF_MODE_PRESETS (ask/plan/build) to operating-model.js
  ask  = chat  | manual     | fast
  plan = plan  | assisted   | smart
  build = build | autonomous | smart

- Shift+Tab cycles Ask → Plan → Build presets instead of raw workModes
- /mode ask|plan|build sets all three axes atomically
- formatModeState shows preset name when current mode matches a preset

YOLO (Ctrl+Y):
- session.toggleYolo() slams all axes to build+autonomous+deep+unrestricted
  and saves pre-YOLO mode for restore on toggle-off
- Terminal title shows 🚀 badge when YOLO is active
- Status line shows 'SF — 🚀 YOLO' when active
- Also calls settingsManager.toggleYOLO() for safe-git prompt bypass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:47:14 +02:00
Mikael Hugo
6fb411df90 refactor(commands): eliminate dead handlers and catalog duplicates
Dead code removed:
- ops.js: second 'rate' handler block (lines 248-256) — unreachable because
  the top-level import block at line 187 fires first and returns true
- autonomous.js: 'stop' handler (trimmed === 'stop') — /stop is in
  BASE_RUNTIME_COMMANDS, platform intercepts it before SF extension sees it
- core.js: 'session-rename' handler block — /rename is the canonical command;
  alias added zero value and created confusion

Catalog duplicates fixed:
- 'plan' appeared twice (line 85 + 248) with contradictory descriptions;
  merged into single entry describing both phase-trigger and artifact-promotion
- 'steer' appeared twice (line 72 + 167); removed the TUI-panel shortcut
  entry (Shift+Tab is a keyboard binding, not a slash command)

Discoverability fix:
- 'recover' was handled in ops.js but absent from catalog and manifest;
  added to both with accurate description (reconstruct DB hierarchy from
  markdown on disk)
- 'session-rename' removed from catalog and manifest; users use /rename

Check script improvements:
- HIDDEN_OR_ALIAS_SUBCOMMANDS now filters both directions of the catalog
  ↔ handler consistency check (was only filtering 'handled but missing from
  catalog', not 'catalog but no SF handler')
- Added 'stop' to HIDDEN_OR_ALIAS_SUBCOMMANDS with comment explaining it is
  platform-intercepted; removed 'recover' (now properly in catalog)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:36:04 +02:00
Mikael Hugo
aca13d1d9b fix(build): fix build:core — native tsconfig types, inventory sync, compat alias catalog
- packages/native/tsconfig.json: add types:["node"] so Buffer/process/
  __dirname resolve correctly (root tsconfig has no lib/types for node)
- scripts/check-sf-extension-inventory.mjs: add footer-config, undo-turn,
  review-code to HIDDEN_OR_ALIAS_SUBCOMMANDS (they are aliases for statusline,
  rewind, rubber-duck)
- src/resources/extensions/sf/commands/catalog.js: add session-rename entry
  (real command handled in core.js, was missing from TOP_LEVEL_SUBCOMMANDS)
- src/resources/extensions/sf/extension-manifest.json: add 19 commands that
  exist in catalog but were absent from provides.commands
- src/resources/extensions/sf/guided-flow.js: remove showSmartEntry compat alias
  (no live imports — only a comment reference in headless-context.ts)
- src/resources/extensions/sf/graph.js: remove graphFromDefinition compat alias

build:core now passes end-to-end.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:18:11 +02:00
Mikael Hugo
29d2750687 feat(db): metrics ledger → DB-first unit_metrics table (schema v54)
- Add unit_metrics and project_metrics_meta tables in schema v54
- Export upsertUnitMetrics, getAllUnitMetrics, pruneUnitMetrics,
  getProjectStartedAt, setProjectStartedAt from sf-db.js
- Rewrite metrics.js disk I/O: remove json-persistence/paths imports,
  replace saveJsonFile/loadJsonFile with DB calls
- Public API surface unchanged: loadLedgerFromDisk, getLedger,
  pruneMetricsLedger all return same shapes
- Update schema version assertion in sf-db-migration.test.mjs to 54

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:05:06 +02:00
Mikael Hugo
830a259630 chore: delete superseded esbuild test-compile scripts
compile-tests.mjs and dist-test-resolve.mjs were for an older esbuild+node
--test approach. The project now uses Vitest end-to-end. Dead code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:04:41 +02:00
Mikael Hugo
9df46d2d88 feat(db): routing-history → DB-first (schema v53)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 16:02:47 +02:00
Mikael Hugo
bd0c612993 refactor(retire): drop JSONL fallback from judgment-log + delete one-shot migration scripts
- judgment-log.js: DB is always available; strip appendFileSync/readFileSync
  JSONL fallback paths and resolveJudgmentLogPath export. Non-fatal on DB
  failure is preserved — agent loop must never be disrupted.
- Delete scripts/migrate-to-vitest{,-all}.mjs and fix-vitest-api.mjs —
  one-shot migration tools that have already run; no longer needed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 15:55:10 +02:00
Mikael Hugo
a70004cf2a refactor(db-first): migrate triage outputs and runtime counters to sf.db
- sf-db.js v52: triage_runs/evals/items/skills, runtime_counters,
  validation_attention_markers tables + CRUD functions
- commands-todo.js: write triage evals/items/skills to DB instead of JSONL;
  keep markdown report as human artifact
- auto-dispatch.js: rewrite-count + uat-count use runtime_counters table
  with file fallback; validation attention markers use DB with file fallback
- migration test: bump expected schema version 51 → 52
- jsonl-schema-versioning.test.mjs: update triage test to assert DB rows

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 15:47:38 +02:00
Mikael Hugo
3b249c4144 feat(deploy): vision-to-production pipeline — deploy/smoke/release/rollback/challenge
- sf-db.js: ensureDeployTables() adds deploy_runs, smoke_results, release_records,
  rollback_runs (schema v51); migration block follows sleeptime v50
- preferences.js: deploy block merged (target, command, url, auto_release,
  release_type, publish_channel, adversarial_review)
- auto-prompts.js: buildDeployPrompt, buildSmokeProductionPrompt,
  buildReleasePrompt, buildRollbackPrompt, buildChallengePrompt
- auto-dispatch.js: 5 new rules — completing-milestone→challenge,
  completing-milestone→release, release-done→deploy,
  deploy-done→smoke-production, smoke-failed→rollback
- prompts/: deploy.md, smoke-production.md, release.md, rollback.md, challenge.md
- sf-db-migration test: bump expected schema version 49→51

The autonomous loop can now carry a milestone from complete-milestone all the
way to a live, smoke-verified, tagged release. Each stage is gated by prefs
(auto_release, deploy.target, deploy.url) so projects opt in per stage.
Challenge (adversarial review) runs before release when adversarial_review is set.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 15:25:47 +02:00
Mikael Hugo
00dc1ece89 feat(uok): 8-role swarm topology + DB-first sleeptime consolidation queue
- VALID_ROLES: coordinator/worker/scout/reviewer/planner/verifier/scribe/adversary (dropped architect)
- swarm-roles.js: PlannerAgent, VerifierAgent, ScribeAgent, AdversaryAgent + createDefaultSwarm wires all 8
- agent-swarm.js: route() maps plan/verify/document/challenge to new roles; _deriveWorkMode() covers all unitType patterns; getTopology() exposes all 8 role buckets; sleeptime case is now non-blocking (INSERT to DB queue instead of blocking memoryAgent.receive())
- sf-db.js: sleeptime_consolidation_queue table (schema v50) — id, conversation_agent, memory_agent, content, status, created_at, processed_at, result
- auto/loop.js: drainSleeptimeQueue() runs between every autonomous unit; reads pending queue rows, runs consolidation via PersistentAgent, marks done/error in DB
- core.js: workModes list includes verify/document/challenge
- skills/loader.js: isSkillRelevant() handles verify→review and document→docs trigger aliases
- swarm.test.mjs: updated topology assertions for 9-agent swarm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 15:11:19 +02:00
Mikael Hugo
5dbd318a76 refactor(uok): rename scheduler-v2 and plan-v2 to drop v2 suffix
v1 no longer exists — the suffix is just noise. Update all import sites
and rename the test file to match.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-09 14:45:02 +02:00