mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
Merge pull request #4106 from ruvnet/fix/tui-pagebar-help-policytrust
fix(console,cli): ruflo tui page bar marks the AI page, help says 1-6, policy-trust path never relative (console 0.43.1)
This commit is contained in:
10 files changed
+172
-10
No files matched your search
@@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="666" viewBox="0 0 1024 666" role="img" aria-labelledby="t d"><title id="t">ruflo tui walkthrough</title><desc id="d">A looping walkthrough of the optional standalone ruflo terminal UI: the five read-only pages, then the same Swarm page in a small 80 by 24 window. Sample project and sample agents only.</desc><style>.t{font-family:DejaVu Sans Mono, Menlo, Consolas, monospace;font-size:16px}.cap{font:600 18px system-ui,Segoe UI,Helvetica,Arial,sans-serif;fill:#e6edf3}.num{font:14px DejaVu Sans Mono, Menlo, Consolas, monospace;fill:#8b949e}.p{opacity:0;animation:show 20.4s infinite}.p0{animation-delay:0s}.p1{animation-delay:3.4s}.p2{animation-delay:6.8s}.p3{animation-delay:10.2s}.p4{animation-delay:13.6s}.p5{animation-delay:17s}@keyframes show{0%,16.657%{opacity:1}16.667%,100%{opacity:0}}@media (prefers-reduced-motion:reduce){.p{animation:none}.p0{opacity:1}}</style><defs><g id="r0"><rect fill="#c9d1d9" x="0" y="0" width="120" height="19"/><text fill="#0d1117" x="10" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">1</text><text fill="#0d1117" x="30" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">Overview</text><text fill="#c9d1d9" x="140" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">2</text><text fill="#c9d1d9" x="160" y="14.5" textLength="40" lengthAdjust="spacing" xml:space="preserve">Cost</text><text fill="#c9d1d9" x="230" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">3</text><text fill="#c9d1d9" x="250" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">Swarm</text><text fill="#c9d1d9" x="330" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">4</text><text fill="#c9d1d9" x="350" y="14.5" textLength="60" lengthAdjust="spacing" xml:space="preserve">Events</text><text fill="#c9d1d9" x="440" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">5</text><text fill="#c9d1d9" x="460" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">Missions</text><text fill="#c9d1d9" x="570" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">6</text><text fill="#c9d1d9" x="590" y="14.5" textLength="20" lengthAdjust="spacing" xml:space="preserve">AI</text></g><g id="r2"><text x="1" y="14.5" font-size="15" font-family="Noto Color Emoji, Apple Color Emoji, Segoe UI Emoji, DejaVu Sans Mono, Menlo, Consolas, monospace">🏠</text><text fill="rgb(215,135,95)" font-weight="700" x="30" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">Overview</text><text fill="rgb(215,135,95)" font-weight="700" x="120" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">—</text><text fill="rgb(215,135,95)" font-weight="700" x="140" y="14.5" textLength="40" lengthAdjust="spacing" xml:space="preserve">what</text><text fill="rgb(215,135,95)" font-weight="700" x="190" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">ruflo</text><text fill="rgb(215,135,95)" font-weight="700" x="250" y="14.5" textLength="20" lengthAdjust="spacing" xml:space="preserve">is</text><text fill="rgb(215,135,95)" font-weight="700" x="280" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">doing</text><text fill="rgb(215,135,95)" font-weight="700" x="340" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">here:</text><text fill="rgb(215,135,95)" font-weight="700" x="400" y="14.5" textLength="110" lengthAdjust="spacing" xml:space="preserve">subsystems,</text><text fill="rgb(215,135,95)" font-weight="700" x="520" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">mods,</text><text fill="rgb(215,135,95)" font-weight="700" x="580" y="14.5" textLength="60" lengthAdjust="spacing" xml:space="preserve">health</text><text fill="rgb(215,135,95)" font-weight="700" x="650" y="14.5" textLength="60" lengthAdjust="spacing" xml:space="preserve">alerts</text><text fill="rgb(215,135,95)" font-weight="700" x="720" y="14.5" textLength="30" lengthAdjust="spacing" xml:space="preserve">and</text><text fill="rgb(215,135,95)" font-weight="700" x="760" y="14.5" textLength="40" lengthAdjust="spacing" xml:space="preserve">live</text><text fill="rgb(215,135,95)" font-weight="700" x="810" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">activity</text></g><g id="r4"><path transform="translate(0,0)" d="M5 19V12Q5 9.5 8 9.5H10" fill="none" stroke="rgb(175,175,255)" stroke-width="1.2"/><path d="M10 9.5h980" stroke="rgb(175,175,255)" stroke-width="1.2" fill="none"/><path transform="translate(990,0)" d="M5 19V12Q5 9.5 2 9.5H0" fill="none" stroke="rgb(175,175,255)" stroke-width="1.2"/></g><g id="r6"><path transform="translate(0,0)" d="M5 0V19" fill="none" stroke="#c9d1d9" stroke-width="1.2"/><text fill="#c9d1d9" font-weight="700" x="20" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">Start</text><text fill="#c9d1d9" font-weight="700"Line truncated
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="666" viewBox="0 0 1024 666" role="img" aria-labelledby="t d"><title id="t">ruflo tui: the optional terminal UI, page by page</title><desc id="d">A looping recording of the optional ruflo terminal UI in a sample project: Overview, Cost, Swarm, Events, Missions, the AI page with its ask-first card, and the Swarm page in a small 80 by 24 window.</desc><style>.t{font-family:DejaVu Sans Mono, Menlo, Consolas, monospace;font-size:16px}.cap{font:600 18px system-ui,Segoe UI,Helvetica,Arial,sans-serif;fill:#e6edf3}.num{font:14px DejaVu Sans Mono, Menlo, Consolas, monospace;fill:#8b949e}.p{opacity:0;animation:show 22.4s infinite}.p0{animation-delay:0s}.p1{animation-delay:2.8s}.p2{animation-delay:5.6s}.p3{animation-delay:8.4s}.p4{animation-delay:11.2s}.p5{animation-delay:14s}.p6{animation-delay:16.8s}.p7{animation-delay:19.6s}@keyframes show{0%,12.490%{opacity:1}12.500%,100%{opacity:0}}@media (prefers-reduced-motion:reduce){.p{animation:none}.p0{opacity:1}}</style><defs><g id="r0"><rect fill="#c9d1d9" x="0" y="0" width="120" height="19"/><text fill="#0d1117" x="10" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">1</text><text fill="#0d1117" x="30" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">Overview</text><text fill="#c9d1d9" x="140" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">2</text><text fill="#c9d1d9" x="160" y="14.5" textLength="40" lengthAdjust="spacing" xml:space="preserve">Cost</text><text fill="#c9d1d9" x="230" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">3</text><text fill="#c9d1d9" x="250" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">Swarm</text><text fill="#c9d1d9" x="330" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">4</text><text fill="#c9d1d9" x="350" y="14.5" textLength="60" lengthAdjust="spacing" xml:space="preserve">Events</text><text fill="#c9d1d9" x="440" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">5</text><text fill="#c9d1d9" x="460" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">Missions</text><text fill="#c9d1d9" x="570" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">6</text><text fill="#c9d1d9" x="590" y="14.5" textLength="20" lengthAdjust="spacing" xml:space="preserve">AI</text></g><g id="r2"><text x="1" y="14.5" font-size="15" font-family="Noto Color Emoji, Apple Color Emoji, Segoe UI Emoji, DejaVu Sans Mono, Menlo, Consolas, monospace">🏠</text><text fill="rgb(215,135,95)" font-weight="700" x="30" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">Overview</text><text fill="rgb(215,135,95)" font-weight="700" x="120" y="14.5" textLength="10" lengthAdjust="spacing" xml:space="preserve">—</text><text fill="rgb(215,135,95)" font-weight="700" x="140" y="14.5" textLength="40" lengthAdjust="spacing" xml:space="preserve">what</text><text fill="rgb(215,135,95)" font-weight="700" x="190" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">ruflo</text><text fill="rgb(215,135,95)" font-weight="700" x="250" y="14.5" textLength="20" lengthAdjust="spacing" xml:space="preserve">is</text><text fill="rgb(215,135,95)" font-weight="700" x="280" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">doing</text><text fill="rgb(215,135,95)" font-weight="700" x="340" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">here:</text><text fill="rgb(215,135,95)" font-weight="700" x="400" y="14.5" textLength="110" lengthAdjust="spacing" xml:space="preserve">subsystems,</text><text fill="rgb(215,135,95)" font-weight="700" x="520" y="14.5" textLength="50" lengthAdjust="spacing" xml:space="preserve">mods,</text><text fill="rgb(215,135,95)" font-weight="700" x="580" y="14.5" textLength="60" lengthAdjust="spacing" xml:space="preserve">health</text><text fill="rgb(215,135,95)" font-weight="700" x="650" y="14.5" textLength="60" lengthAdjust="spacing" xml:space="preserve">alerts</text><text fill="rgb(215,135,95)" font-weight="700" x="720" y="14.5" textLength="30" lengthAdjust="spacing" xml:space="preserve">and</text><text fill="rgb(215,135,95)" font-weight="700" x="760" y="14.5" textLength="40" lengthAdjust="spacing" xml:space="preserve">live</text><text fill="rgb(215,135,95)" font-weight="700" x="810" y="14.5" textLength="80" lengthAdjust="spacing" xml:space="preserve">activity</text></g><g id="r4"><path transform="translate(0,0)" d="M5 19V12Q5 9.5 8 9.5H10" fill="none" stroke="rgb(175,175,255)" stroke-width="1.2"/><path d="M10 9.5h980" stroke="rgb(175,175,255)" stroke-width="1.2" fill="none"/><path transform="translate(990,0)" d="M5 19V12Q5 9.5 2 9.5H0" fill="none" stroke="rgb(175,175,255)" stroke-width="1.2"/></g><g id="r6"><path transform="translate(0,0)" d="M5 0V19" fill="none" stroke="#c9d1d9" stroke-width="1.2"/><text fill="#c9d1d9" font-weight="700" x="20" y="14.5" textLength="90" lLine truncated
|
||||
|
Before Width: | Height: | Size: 157 KiB After Width: | Height: | Size: 198 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ruflo-console",
|
||||
"description": "ruflo's cockpit inside Claude Code and the one /ruflo command for every ruflo mod (function hooks, early access). Views: overview with health alerts, swarm topology graph, claims flow with TTL rings, federation map, plugin health matrix, learning curve and pipeline, MetaHarness radar and audit trend, memory, cost gauge, agent timeline, approvals queue, event stream, a main menu, an x.ruv.io federation board, an AI terminal (codex, claude or both in remembered sessions, streamed), Skills (npx skills), a Hive-Mind view, a MetaHarness lab, agent drill-down; a command palette for confirm-gated actions through the ruflo CLI; a band above the prompt. Reads ruflo's files and the CLI's local JSON; anything not measured reads n/a. The one network call it makes by itself is a daily read of the published plugin.json at github.com/ruvnet/ruflo to offer an update (Settings → Updates: ask, auto, or off); it installs only through Claude Code's own claude plugin update, and never a new major version without asking.",
|
||||
"version": "0.43.0",
|
||||
"version": "0.43.1",
|
||||
"author": {
|
||||
"name": "ruvnet",
|
||||
"url": "https://github.com/ruvnet"
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
Newest first. One `## <version> — <date>` heading per version, then `feat:`, `fix:`, `breaking:` and `chore:` bullets (ADR-478). Built from git history; older versions: `git log -- plugins/ruflo-console`.
|
||||
|
||||
## 0.43.1 — 2026-10-12
|
||||
- fix: `ruflo tui` marks the page on screen in the page bar: on the AI page it kept the previous page lit (`5 Missions`, or `1 Overview` after a number key) because the bar was painted from the console view the session last showed and the AI page is not one; it is now drawn from the page itself, through Tab, Shift-Tab, letters, digits and resize
|
||||
- fix: `ruflo tui --help` and the console README list the page keys as `1-6` and `o c s e m a` (they said `1-5`); a test holds the help text
|
||||
- fix: the CLI no longer builds its trust-store path (`~/.config/ruflo/policy-trust`) from an empty or relative `$HOME`, which put the anchor mirror and key under the working directory; it uses the account home, or says `$HOME` must be absolute
|
||||
|
||||
## 0.43.0 — 2026-10-12
|
||||
- feat: an optional Orbital look (black telemetry panels, square borders, a rotating globe, a scan sweep and a shaded Ruflo header that stays visible after boot) and Theme Studio: pick Classic BBS, plain or Orbital, six bundled color presets, up to twelve named custom themes, a color picker with a 3:1 minimum contrast, motion layers and speed, and a generate-console-theme skill whose JSON is imported through a strict, size-bounded schema. Classic BBS stays the default; open it from Main Menu → Tools, Settings or /ruflo themes
|
||||
- fix: Theme Studio has its own boot-log line and help guide, and is reached by name (every hotkey letter is taken)
|
||||
|
||||
@@ -50,7 +50,7 @@ CONSOLE_DRIVE_INSTALL="$PWD:ruflo-mods@ruflo" RUFLO_E2E_LIVE=1 bash plugins/rufl
|
||||
The same views the mod draws, on five pages (Overview, Cost, Swarm, Events, Missions), drawn by a small standalone terminal host instead of Claude Code, and a sixth, AI, that asks Codex or OpenRouter. The five are read-only; the AI page shows a card of exactly what would be sent and sends only after a `y`; `npx ruflo tui` (the `ruflo` package and `@claude-flow/cli` carry the bundle).
|
||||
|
||||
```bash
|
||||
npx ruflo tui # interactive: 1-5 or o c s e m pick a page, Tab/Shift-Tab cycle, j/k, PgUp/PgDn, g/G, r refresh, q quit
|
||||
npx ruflo tui # interactive: 1-6 or o c s e m a pick a page, Tab/Shift-Tab cycle, j/k, PgUp/PgDn, g/G, r refresh, q quit
|
||||
npx ruflo tui --view swarm # start on the Swarm page
|
||||
npx ruflo tui --view ai --model openai/gpt-4o-mini --max-spend-usd 0.1 # ask OpenRouter on a cheap model, stopping at $0.10 reported (key in $OPENROUTER_API_KEY, never shown)
|
||||
npx ruflo tui --no-ai # without the AI page
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
* The console's version, shown on the header so a person can tell which build is running. Kept equal to the plugin's manifest
|
||||
* (`.claude-plugin/plugin.json`); tests/version.spec.ts fails if the two drift.
|
||||
*/
|
||||
export const CONSOLE_VERSION = '0.43.0'
|
||||
export const CONSOLE_VERSION = '0.43.1'
|
||||
@@ -11,9 +11,9 @@ step() { printf "→ %s ... " "$1"; }
|
||||
ok() { printf "PASS\n"; PASS=$((PASS+1)); }
|
||||
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
|
||||
|
||||
step "1. plugin.json declares ruflo-console 0.43.0"
|
||||
step "1. plugin.json declares ruflo-console 0.43.1"
|
||||
grep -q '"name": "ruflo-console"' "$ROOT/.claude-plugin/plugin.json" \
|
||||
&& grep -q '"version": "0.43.0"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
|
||||
&& grep -q '"version": "0.43.1"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
|
||||
|
||||
step "2. hooks.json names exactly one module and no classic hook commands"
|
||||
grep -q '"modules": \["./register.ts"\]' "$HOOKS/hooks.json" && ! grep -q '"command"' "$HOOKS/hooks.json" \
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* `ruflo tui`: the page bar always marks the page that is on screen, the AI page included. The bar used to be painted from the
|
||||
* console view the session last showed, and the AI page is not a console view, so on page 6 the bar kept the previous page lit.
|
||||
* npx vitest run plugins/ruflo-console/tests/tui-pagebar.spec.ts
|
||||
*/
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
|
||||
import { runTui, type TuiIO } from '../tui/run'
|
||||
import { TUI_VIEWS } from '../tui/session'
|
||||
import { RUFLO_FILES } from './fixtures/ruflo-run'
|
||||
|
||||
const ESC = '\u001b'
|
||||
const LABEL: Record<string, string> = { overview: '1 Overview', cost: '2 Cost', swarm: '3 Swarm', events: '4 Events', missions: '5 Missions', ai: '6 AI' }
|
||||
let root: string
|
||||
let project: string
|
||||
|
||||
beforeAll(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'tui-pagebar-'))
|
||||
project = join(root, 'project')
|
||||
for (const [path, body] of Object.entries(RUFLO_FILES)) {
|
||||
mkdirSync(dirname(join(project, path)), { recursive: true })
|
||||
writeFileSync(join(project, path), body)
|
||||
}
|
||||
})
|
||||
afterAll(() => rmSync(root, { recursive: true, force: true }))
|
||||
|
||||
function terminal(columns = 100, rows = 30) {
|
||||
const out: string[] = []
|
||||
const listeners: Array<(chunk: string) => void> = []
|
||||
const resizers: Array<() => void> = []
|
||||
const stdout = { isTTY: true, columns, rows, write: (text: string) => void out.push(text), on: (_e: 'resize', fn: () => void) => void resizers.push(fn), off: () => void resizers.splice(0) }
|
||||
const io: TuiIO = {
|
||||
stdin: { isTTY: true, setRawMode: () => undefined, on: (_e, fn) => void listeners.push(fn as never), off: () => void listeners.splice(0), resume: () => undefined, pause: () => undefined },
|
||||
stdout,
|
||||
stderr: { write: () => undefined },
|
||||
env: { TERM: 'xterm-256color' },
|
||||
}
|
||||
|
||||
return { io, out, press: (key: string) => listeners.forEach(fn => fn(key)), resize: (c: number, r = rows) => { stdout.columns = c; stdout.rows = r; resizers.forEach(fn => fn()) } }
|
||||
}
|
||||
|
||||
const settle = (ms = 120) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
/** The page bar (first row) of the last frame drawn, escapes kept. */
|
||||
const bar = (chunks: string[]) => (chunks.join('').split(`${ESC}[H`).pop() ?? '').split('\r\n')[0] ?? ''
|
||||
/** The label(s) drawn in reverse video on the bar. */
|
||||
const lit = (row: string) => [...row.matchAll(/\u001b\[7m ([^\u001b]*) \u001b\[0m/g)].map(match => match[1])
|
||||
|
||||
async function run(columns = 100) {
|
||||
const t = terminal(columns)
|
||||
const running = runTui({ cwd: project, home: join(root, 'home'), aiPage: {} }, t.io)
|
||||
|
||||
await settle(250)
|
||||
|
||||
return { ...t, finish: async () => { t.press(`${ESC}`); t.press('q'); await running } }
|
||||
}
|
||||
|
||||
describe('the page bar follows the page on screen', () => {
|
||||
for (const [index, view] of TUI_VIEWS.entries()) {
|
||||
it(`marks ${LABEL[view]} after the ${index + 1} key and after its letter`, async () => {
|
||||
const t = await run()
|
||||
|
||||
// Go somewhere else first, so a stale bar cannot pass by accident.
|
||||
t.press(view === 'overview' ? '2' : '1')
|
||||
await settle()
|
||||
t.press(String(index + 1))
|
||||
await settle()
|
||||
expect(lit(bar(t.out)), `digit ${index + 1}`).toEqual([LABEL[view]])
|
||||
|
||||
await t.finish()
|
||||
})
|
||||
}
|
||||
|
||||
it('marks AI, not the page before it, when AI is reached with its letter from Missions', async () => {
|
||||
const t = await run()
|
||||
|
||||
t.press('m')
|
||||
await settle()
|
||||
expect(lit(bar(t.out))).toEqual([LABEL.missions])
|
||||
t.press('a')
|
||||
await settle()
|
||||
expect(lit(bar(t.out))).toEqual([LABEL.ai])
|
||||
await t.finish()
|
||||
})
|
||||
|
||||
it('marks AI when Tab walks onto it from Missions, and keeps it lit through a resize and a redraw', async () => {
|
||||
const t = await run(120)
|
||||
|
||||
t.press('5')
|
||||
await settle()
|
||||
t.press('\t')
|
||||
await settle()
|
||||
expect(lit(bar(t.out))).toEqual([LABEL.ai])
|
||||
|
||||
t.resize(90, 24)
|
||||
await settle(150)
|
||||
expect(lit(bar(t.out)), 'after a resize').toEqual([LABEL.ai])
|
||||
await t.finish()
|
||||
})
|
||||
|
||||
it('shows the position form on a narrow terminal, with AI as 6/6', async () => {
|
||||
const t = await run(50)
|
||||
|
||||
t.press('6')
|
||||
await settle()
|
||||
|
||||
const row = (bar(t.out)).replace(/\u001b\[[0-9;]*m/g, '')
|
||||
|
||||
expect(row).toContain('6/6 AI')
|
||||
await t.finish()
|
||||
})
|
||||
})
|
||||
@@ -1,10 +1,10 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { isAbsolute, join } from 'node:path';
|
||||
import { tmpdir, userInfo } from 'node:os';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { evaluatePolicyRequest } from '../src/services/policy-runtime.js';
|
||||
import { anchorPosture } from '../src/services/policy-ledger-anchor.js';
|
||||
import { anchorPosture, policyTrustRoot } from '../src/services/policy-ledger-anchor.js';
|
||||
|
||||
// #3919: the anchor mirror and trust key were resolved with userInfo().homedir,
|
||||
// which ignores a throwaway HOME, so tests (and sandboxed runs) wrote into the
|
||||
@@ -72,3 +72,23 @@ describe('policy trust files honour a throwaway HOME (#3919)', () => {
|
||||
expect(existsSync(join(xdg, 'ruflo'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('an empty or relative HOME never puts trust material relative to the working directory', () => {
|
||||
it('falls back to the account home directory, always an absolute path', () => {
|
||||
for (const bad of ['', 'relative/home', '.']) {
|
||||
process.env.HOME = bad;
|
||||
const root = policyTrustRoot();
|
||||
|
||||
expect(isAbsolute(root), `HOME=${JSON.stringify(bad)} gave ${root}`).toBe(true);
|
||||
expect(root).toBe(join(userInfo().homedir, '.config', 'ruflo', 'policy-trust'));
|
||||
}
|
||||
});
|
||||
|
||||
it('still follows an absolute $HOME and an absolute XDG_CONFIG_HOME exactly as before', () => {
|
||||
const home = scratch('ruflo-home-ok-');
|
||||
process.env.HOME = home;
|
||||
expect(policyTrustRoot()).toBe(join(home, '.config', 'ruflo', 'policy-trust'));
|
||||
process.env.XDG_CONFIG_HOME = join(home, 'xdg');
|
||||
expect(policyTrustRoot()).toBe(join(home, 'xdg', 'ruflo', 'policy-trust'));
|
||||
});
|
||||
});
|
||||
@@ -104,6 +104,15 @@ describe('tui command', () => {
|
||||
expect(tuiCommand.examples?.some(example => example.command.includes('--plain'))).toBe(true);
|
||||
});
|
||||
|
||||
it('tells the truth about the page keys: six pages, so 1-6 and a for AI, never 1-5', () => {
|
||||
const source = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'src', 'commands', 'tui.ts'), 'utf8');
|
||||
const text = [tuiCommand.description, ...(tuiCommand.examples ?? []).map(example => example.description), source].join('\n');
|
||||
|
||||
expect(text).toMatch(/keys 1-6/);
|
||||
expect(text).not.toMatch(/keys 1-5/);
|
||||
expect(text).toMatch(/o c s e m a/);
|
||||
});
|
||||
|
||||
it.skipIf(locateTuiBundle() === null)('--plain prints one plain frame to stdout and exits 0 (real bundle)', async () => {
|
||||
const lines: string[] = [];
|
||||
const real = process.stdout.write.bind(process.stdout);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { existsSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
|
||||
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
import { homedir, userInfo } from 'node:os';
|
||||
import type { PolicyState } from '@claude-flow/security';
|
||||
|
||||
export type AnchorEvent = 'append' | 'migrated-from-state' | 'establish-anchor';
|
||||
@@ -42,6 +42,20 @@ const MIRROR_FILE = 'ledger-anchor-head.json';
|
||||
|
||||
export const anchorLogPath = (projectRoot: string): string => join(resolve(projectRoot), '.claude-flow', 'policy', LOG_FILE);
|
||||
|
||||
/**
|
||||
* The home directory trust material lives under: $HOME when it is an absolute path, else the account's home. An empty or relative
|
||||
* $HOME (an unset variable in a wrapper script, `HOME=. cmd`) would make join() yield a path relative to the working directory and
|
||||
* drop the HMAC key and anchor mirror into the project; that is never wanted, so it falls back to the account home or refuses.
|
||||
*/
|
||||
function trustHome(): string {
|
||||
const home = homedir();
|
||||
if (home && isAbsolute(home)) return home;
|
||||
let account = '';
|
||||
try { account = userInfo().homedir; } catch { /* no account entry for this uid */ }
|
||||
if (account && isAbsolute(account)) return account;
|
||||
throw new Error('policy-trust-home-unresolved: $HOME is empty or relative and this account has no home directory; set HOME to an absolute path');
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory holding per-project trust material (anchor mirror, HMAC key).
|
||||
* Resolved from the environment at call time (#3919): $XDG_CONFIG_HOME when it
|
||||
@@ -50,7 +64,7 @@ export const anchorLogPath = (projectRoot: string): string => join(resolve(proje
|
||||
* user who already has trust state under the legacy ~/.config keeps using it.
|
||||
*/
|
||||
export function policyTrustRoot(): string {
|
||||
const legacy = join(homedir(), '.config', 'ruflo', 'policy-trust');
|
||||
const legacy = join(trustHome(), '.config', 'ruflo', 'policy-trust');
|
||||
const xdg = process.env.XDG_CONFIG_HOME;
|
||||
if (!xdg || !isAbsolute(xdg)) return legacy;
|
||||
const preferred = join(xdg, 'ruflo', 'policy-trust');
|
||||
|
||||
Reference in new issue
Block a user