phewsh 0.15.11 → 0.15.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/session.js +109 -1
- package/lib/suggest.js +111 -0
- package/package.json +1 -1
package/commands/session.js
CHANGED
|
@@ -19,6 +19,7 @@ const { readPPS } = require('../lib/pps');
|
|
|
19
19
|
const { push, pull, ensureValidToken } = require('./sync');
|
|
20
20
|
const { HARNESSES, listHarnesses, runViaHarness, cancelActive } = require('../lib/harnesses');
|
|
21
21
|
const { recordDecision, labelOutcome, pendingDecisions, outcomeStats, OUTCOMES } = require('../lib/outcomes');
|
|
22
|
+
const { suggest, suggestAll } = require('../lib/suggest');
|
|
22
23
|
const { recordSessionEvent } = require('../lib/receipts-data');
|
|
23
24
|
const configFile = require('../lib/config-file');
|
|
24
25
|
const { createFailureTracker, createLineDispatcher } = require('../lib/session-input');
|
|
@@ -330,6 +331,7 @@ async function main() {
|
|
|
330
331
|
let awaitingOutcome = null; // decision id eligible for 1-4 labeling
|
|
331
332
|
let awaitingFallback = null; // { input, fullSystem, options } after a route failure
|
|
332
333
|
let bootstrapChoices = null; // root-bootstrap menu entries when no project here
|
|
334
|
+
let nextChoices = null; // ranked /next suggestions awaiting a numeric pick
|
|
333
335
|
let decisionsThisSession = 0;
|
|
334
336
|
|
|
335
337
|
// ── The Exhale: animated brand reveal ──────────────────
|
|
@@ -454,6 +456,55 @@ async function main() {
|
|
|
454
456
|
console.log(` ${slate('pick a number, or just type — your context travels with every route')}`);
|
|
455
457
|
}
|
|
456
458
|
|
|
459
|
+
// Self-aware guidance: snapshot the session's state so phewsh can recommend
|
|
460
|
+
// the one next step worth taking, instead of leaving the user to know commands.
|
|
461
|
+
function buildSuggestState() {
|
|
462
|
+
let seqStale = false;
|
|
463
|
+
try {
|
|
464
|
+
const cwd = process.cwd();
|
|
465
|
+
const claudePath = path.join(cwd, 'CLAUDE.md');
|
|
466
|
+
const intentDir = path.join(cwd, '.intent');
|
|
467
|
+
if (fs.existsSync(claudePath) && fs.existsSync(intentDir)) {
|
|
468
|
+
const claudeT = fs.statSync(claudePath).mtimeMs;
|
|
469
|
+
const newestIntent = fs.readdirSync(intentDir)
|
|
470
|
+
.filter(f => f.endsWith('.md') || f.endsWith('.json'))
|
|
471
|
+
.reduce((m, f) => Math.max(m, fs.statSync(path.join(intentDir, f)).mtimeMs), 0);
|
|
472
|
+
seqStale = newestIntent > claudeT + 1000; // >1s newer = drift
|
|
473
|
+
}
|
|
474
|
+
} catch { /* drift detection is best-effort */ }
|
|
475
|
+
|
|
476
|
+
let ambientOn = false;
|
|
477
|
+
try {
|
|
478
|
+
const s = fs.readFileSync(path.join(os.homedir(), '.claude', 'settings.json'), 'utf-8');
|
|
479
|
+
ambientOn = s.includes('phewsh hook session-start');
|
|
480
|
+
} catch { /* no settings = ambient off */ }
|
|
481
|
+
|
|
482
|
+
let pending = 0;
|
|
483
|
+
try { pending = pendingDecisions({ project: projectName }).length; } catch { /* best-effort */ }
|
|
484
|
+
|
|
485
|
+
let installed = [];
|
|
486
|
+
try { installed = listHarnesses().filter(h => h.installed).map(h => h.id); } catch { /* best-effort */ }
|
|
487
|
+
|
|
488
|
+
return {
|
|
489
|
+
hasIntentDir: fs.existsSync(path.join(process.cwd(), '.intent')),
|
|
490
|
+
intentFileCount: intentFiles.length,
|
|
491
|
+
pendingOutcomes: pending,
|
|
492
|
+
installedHarnesses: installed,
|
|
493
|
+
route,
|
|
494
|
+
turnsThisSession: Math.floor(messages.length / 2),
|
|
495
|
+
seqStale,
|
|
496
|
+
ambientOn,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// One subtle line under the menu — the single highest-leverage nudge, if any.
|
|
501
|
+
function showInlineTip() {
|
|
502
|
+
let tip = null;
|
|
503
|
+
try { tip = suggest(buildSuggestState()); } catch { /* never block the prompt on guidance */ }
|
|
504
|
+
if (!tip) return;
|
|
505
|
+
console.log(` ${teal('⤷')} ${sage(tip.message)} ${cream(tip.command.trim())} ${slate('· /next for options')}`);
|
|
506
|
+
}
|
|
507
|
+
|
|
457
508
|
// Open a known project from the bootstrap menu: chdir, reload memory,
|
|
458
509
|
// back to the normal flow. The session is the cockpit; projects swap in.
|
|
459
510
|
function openProjectAt(dir) {
|
|
@@ -470,6 +521,7 @@ async function main() {
|
|
|
470
521
|
console.log(` ${teal('●')} ${cream(projectName)} ${slate('·')} ${sage(`.intent/ ${intentFiles.length} file${intentFiles.length !== 1 ? 's' : ''} loaded`)} ${slate('· via ' + routeLabel(route, config))}`);
|
|
471
522
|
console.log('');
|
|
472
523
|
showModeMenu();
|
|
524
|
+
showInlineTip();
|
|
473
525
|
console.log('');
|
|
474
526
|
}
|
|
475
527
|
|
|
@@ -502,6 +554,7 @@ async function main() {
|
|
|
502
554
|
showBootstrapMenu(recents);
|
|
503
555
|
} else {
|
|
504
556
|
showModeMenu();
|
|
557
|
+
showInlineTip();
|
|
505
558
|
}
|
|
506
559
|
console.log('');
|
|
507
560
|
|
|
@@ -696,7 +749,8 @@ async function main() {
|
|
|
696
749
|
'models', 'council', 'all', 'provider', 'route', 'use', 'work', 'run',
|
|
697
750
|
'clear', 'status', 'key', 'login', 'export', 'push', 'pull', 'serve',
|
|
698
751
|
'sync', 'harnesses', 'fallback', 'outcomes', 'tour', 'update', 'upgrade',
|
|
699
|
-
'agents', 'context', 'gate', 'reload', 'sequence', 'setup', 'system', 'watch',
|
|
752
|
+
'agents', 'context', 'gate', 'reload', 'sequence', 'seq', 'setup', 'system', 'watch',
|
|
753
|
+
'next', 'recommend', 'guide',
|
|
700
754
|
]);
|
|
701
755
|
const installedIds = harnesses.filter(h => h.installed).map(h => h.id);
|
|
702
756
|
let turnAbort = null; // AbortController while an API turn streams
|
|
@@ -892,6 +946,29 @@ async function main() {
|
|
|
892
946
|
return;
|
|
893
947
|
}
|
|
894
948
|
|
|
949
|
+
// /next pick: a bare number runs the chosen suggestion (slash = in place).
|
|
950
|
+
// Any non-digit input means the user moved on — drop the offer so it never
|
|
951
|
+
// shadows a later mode pick.
|
|
952
|
+
if (nextChoices && !/^[0-9]$/.test(input)) nextChoices = null;
|
|
953
|
+
if (nextChoices && /^[0-9]$/.test(input)) {
|
|
954
|
+
const pick = nextChoices[parseInt(input, 10) - 1];
|
|
955
|
+
if (!pick) {
|
|
956
|
+
console.log(` ${sage('Pick 1-' + nextChoices.length + ', or keep typing')}`);
|
|
957
|
+
rl.prompt();
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const command = pick.command.trim();
|
|
961
|
+
nextChoices = null;
|
|
962
|
+
if (command.startsWith('/')) {
|
|
963
|
+
await handleInput(command); // re-dispatch the slash command in place
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
console.log(` ${teal('⤷')} ${sage('run this in your shell:')} ${cream(command)}`);
|
|
967
|
+
console.log('');
|
|
968
|
+
rl.prompt();
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
|
|
895
972
|
// Root bootstrap: a bare number opens a project, inits, or scans
|
|
896
973
|
if (bootstrapChoices && messages.length === 0 && /^[0-9]{1,2}$/.test(input)) {
|
|
897
974
|
const choice = bootstrapChoices[parseInt(input, 10) - 1];
|
|
@@ -996,10 +1073,41 @@ async function main() {
|
|
|
996
1073
|
process.exit(0);
|
|
997
1074
|
}
|
|
998
1075
|
|
|
1076
|
+
// ── /next ──────────────────────────────────────────
|
|
1077
|
+
// The self-aware "what should I do?" button: phewsh reads the session's
|
|
1078
|
+
// state and hands back ranked, pickable next steps — no command to recall.
|
|
1079
|
+
if (cmd === 'next' || cmd === 'recommend' || cmd === 'guide') {
|
|
1080
|
+
let ranked = [];
|
|
1081
|
+
try { ranked = suggestAll(buildSuggestState()); } catch { /* best-effort */ }
|
|
1082
|
+
console.log('');
|
|
1083
|
+
if (ranked.length === 0) {
|
|
1084
|
+
console.log(` ${teal('●')} ${sage("You're aligned — nothing pressing. Keep working, or /help for everything.")}`);
|
|
1085
|
+
console.log('');
|
|
1086
|
+
nextChoices = null;
|
|
1087
|
+
rl.prompt();
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
console.log(` ${b(cream('What would move you forward'))} ${slate('— pick a number, or ignore me')}`);
|
|
1091
|
+
console.log('');
|
|
1092
|
+
nextChoices = ranked.slice(0, 3);
|
|
1093
|
+
nextChoices.forEach((s, i) => {
|
|
1094
|
+
console.log(` ${teal(String(i + 1))} ${cream(s.command.trim())} ${sage(s.message)}`);
|
|
1095
|
+
console.log(` ${slate(s.why)}`);
|
|
1096
|
+
});
|
|
1097
|
+
console.log('');
|
|
1098
|
+
console.log(` ${slate('a slash command runs in place; anything else, I show you the line to run')}`);
|
|
1099
|
+
console.log('');
|
|
1100
|
+
rl.prompt();
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
999
1104
|
if (cmd === 'help' || cmd === 'h') {
|
|
1000
1105
|
console.log('');
|
|
1001
1106
|
console.log(` ${sage('the loop: define .intent/ → sync → work → evolve → repeat')}`);
|
|
1002
1107
|
console.log('');
|
|
1108
|
+
console.log(` ${cream('not sure what to do?')}`);
|
|
1109
|
+
console.log(` ${teal('/next')} ${sage("phewsh reads your state and hands back the next step worth taking")}`);
|
|
1110
|
+
console.log('');
|
|
1003
1111
|
console.log(` ${cream('author .intent/')}`);
|
|
1004
1112
|
console.log(` ${teal('/init')} ${sage('Create .intent/ for this project')}`);
|
|
1005
1113
|
console.log(` ${teal('/intent')} ${sage('Pause and reflect — view or update .intent/ before moving on')}`);
|
package/lib/suggest.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Self-aware guidance — phewsh watching the user's state and surfacing the
|
|
2
|
+
// single most useful next step, so nobody has to memorize commands like
|
|
3
|
+
// `phewsh seq --dry-run`. Pure and deterministic: feed it a state snapshot,
|
|
4
|
+
// get back ranked suggestions. The session layer renders + offers them.
|
|
5
|
+
//
|
|
6
|
+
// Each suggestion: { id, priority, message, command, why }
|
|
7
|
+
// message — one plain line, what's true right now (the caller colorizes)
|
|
8
|
+
// command — the exact thing to run (a slash command or shell command)
|
|
9
|
+
// why — one short clause: why it helps (shown on /next, not inline)
|
|
10
|
+
//
|
|
11
|
+
// Design rules:
|
|
12
|
+
// - Never nag: a suggestion only fires when its trigger is genuinely met.
|
|
13
|
+
// - One at a time inline; up to a few on demand via /next.
|
|
14
|
+
// - Ordered by leverage — capture-intent and learn-from-outcomes first,
|
|
15
|
+
// because those are the moat; convenience nudges last.
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} s state snapshot
|
|
19
|
+
* @param {boolean} s.hasIntentDir — .intent/ exists in cwd
|
|
20
|
+
* @param {number} s.intentFileCount — .intent/ files loaded
|
|
21
|
+
* @param {number} s.pendingOutcomes — unlabeled decisions (this project)
|
|
22
|
+
* @param {string[]} s.installedHarnesses — harness ids present on the machine
|
|
23
|
+
* @param {string[]} [s.usedRoutes] — harness ids used this session
|
|
24
|
+
* @param {string|null} s.route — current route id
|
|
25
|
+
* @param {number} s.turnsThisSession — exchanges so far
|
|
26
|
+
* @param {boolean} s.seqStale — .intent/ newer than CLAUDE.md (drift)
|
|
27
|
+
* @param {boolean} s.ambientOn — ambient hooks installed
|
|
28
|
+
* @returns {Array} ranked suggestions (highest leverage first)
|
|
29
|
+
*/
|
|
30
|
+
function suggestAll(s = {}) {
|
|
31
|
+
const {
|
|
32
|
+
hasIntentDir = false,
|
|
33
|
+
intentFileCount = 0,
|
|
34
|
+
pendingOutcomes = 0,
|
|
35
|
+
installedHarnesses = [],
|
|
36
|
+
usedRoutes = [],
|
|
37
|
+
route = null,
|
|
38
|
+
turnsThisSession = 0,
|
|
39
|
+
seqStale = false,
|
|
40
|
+
ambientOn = false,
|
|
41
|
+
} = s;
|
|
42
|
+
|
|
43
|
+
const out = [];
|
|
44
|
+
|
|
45
|
+
// 1. Working without captured intent — the biggest miss. Every AI tool here
|
|
46
|
+
// could be reading the same goal; right now none are.
|
|
47
|
+
if (intentFileCount === 0 && turnsThisSession >= 2) {
|
|
48
|
+
out.push({
|
|
49
|
+
id: 'capture-intent',
|
|
50
|
+
priority: 100,
|
|
51
|
+
message: `${turnsThisSession} messages in, no captured intent — every AI here is guessing.`,
|
|
52
|
+
command: '/clarify',
|
|
53
|
+
why: 'Turns what you just said into a spec every tool (this one, Claude Code, Codex) reads.',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 2. Decisions piling up unlabeled — the record only gets smarter if labeled.
|
|
58
|
+
if (pendingOutcomes >= 3) {
|
|
59
|
+
out.push({
|
|
60
|
+
id: 'label-outcomes',
|
|
61
|
+
priority: 90,
|
|
62
|
+
message: `${pendingOutcomes} decisions unlabeled — phewsh can't learn what you keep until you say.`,
|
|
63
|
+
command: '/outcomes',
|
|
64
|
+
why: 'Labeling kept/reverted is the dataset; it weights future routing and recall.',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 3. .intent/ drifted from CLAUDE.md — the editor's AI is reading stale context.
|
|
69
|
+
if (hasIntentDir && seqStale) {
|
|
70
|
+
out.push({
|
|
71
|
+
id: 'resync-claude-md',
|
|
72
|
+
priority: 80,
|
|
73
|
+
message: `Your .intent/ changed but CLAUDE.md didn't — editor AIs are reading stale context.`,
|
|
74
|
+
command: '/seq claude',
|
|
75
|
+
why: 'Re-sequences the latest intent + memory into CLAUDE.md so every tool sees today.',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 4. Multiple harnesses installed, only leaning on one — council is free leverage.
|
|
80
|
+
const others = installedHarnesses.filter(h => h !== route);
|
|
81
|
+
if (installedHarnesses.length >= 2 && turnsThisSession >= 3 && others.length >= 1) {
|
|
82
|
+
out.push({
|
|
83
|
+
id: 'try-council',
|
|
84
|
+
priority: 60,
|
|
85
|
+
message: `You have ${installedHarnesses.length} agents installed but lean on one — the rest are idle.`,
|
|
86
|
+
command: '/council ',
|
|
87
|
+
why: 'Asks every installed harness in parallel; you keep the best answer, context shared.',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 5. Ambient off — continuity that costs nothing once turned on.
|
|
92
|
+
if (hasIntentDir && !ambientOn && installedHarnesses.includes('claude-code')) {
|
|
93
|
+
out.push({
|
|
94
|
+
id: 'enable-ambient',
|
|
95
|
+
priority: 50,
|
|
96
|
+
message: `Ambient is off — Claude Code sessions here won't get the brief unless you launch phewsh.`,
|
|
97
|
+
command: 'phewsh ambient',
|
|
98
|
+
why: 'Installs a silent SessionStart hook so continuity travels even when you forget phewsh.',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return out.sort((a, b) => b.priority - a.priority);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The single highest-leverage suggestion, or null. */
|
|
106
|
+
function suggest(s = {}) {
|
|
107
|
+
const all = suggestAll(s);
|
|
108
|
+
return all.length ? all[0] : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = { suggest, suggestAll };
|