moflo 4.9.3 → 4.9.5

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.
@@ -44,6 +44,10 @@ flo-search "[query]" --namespace guidance # Semantic search
44
44
  flo doctor --fix # Health check
45
45
  \`\`\`
46
46
 
47
+ ### After upgrading MoFlo
48
+
49
+ After running \`npm install moflo@*\` (or \`npm install\` that touches moflo), check \`.moflo/restart-pending.json\`. If it exists, surface the \`message\` field to the user verbatim (Claude Code can't pick up new hooks/MCP tools/launcher mid-session — they're only loaded at session-start), then delete the file.
50
+
47
51
  ### Full Reference
48
52
 
49
53
  - **Subagents protocol:** \`.claude/guidance/shipped/moflo-subagents.md\`
@@ -2,5 +2,5 @@
2
2
  * Auto-generated by build. Do not edit manually.
3
3
  * Source of truth: root package.json → scripts/sync-version.mjs
4
4
  */
5
- export const VERSION = '4.9.3';
5
+ export const VERSION = '4.9.5';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moflo",
3
- "version": "4.9.3",
3
+ "version": "4.9.5",
4
4
  "description": "MoFlo — AI agent orchestration for Claude Code. A standalone, opinionated toolkit with semantic memory, learned routing, gates, spells, and the /flo issue-execution skill.",
5
5
  "main": "dist/src/cli/index.js",
6
6
  "type": "module",
@@ -39,14 +39,15 @@
39
39
  "!.claude/**/*.map",
40
40
  "README.md",
41
41
  "LICENSE",
42
- "scripts/prune-native-binaries.mjs"
42
+ "scripts/prune-native-binaries.mjs",
43
+ "scripts/post-install-notice.mjs"
43
44
  ],
44
45
  "scripts": {
45
46
  "dev": "tsx watch src/cli/index.ts",
46
47
  "prebuild": "node scripts/sync-version.mjs && node scripts/clean-dist.mjs",
47
48
  "build": "tsc",
48
49
  "prepublishOnly": "npm run build",
49
- "postinstall": "node scripts/prune-native-binaries.mjs",
50
+ "postinstall": "node scripts/prune-native-binaries.mjs && node scripts/post-install-notice.mjs",
50
51
  "test": "node scripts/test-runner.mjs",
51
52
  "test:ui": "vitest --ui",
52
53
  "test:smoke": "node harness/consumer-smoke/run.mjs",
@@ -79,7 +80,7 @@
79
80
  "@typescript-eslint/eslint-plugin": "^7.18.0",
80
81
  "@typescript-eslint/parser": "^7.18.0",
81
82
  "eslint": "^8.0.0",
82
- "moflo": "^4.9.2",
83
+ "moflo": "^4.9.4",
83
84
  "tsx": "^4.21.0",
84
85
  "typescript": "^5.9.3",
85
86
  "vitest": "^4.0.0"
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall restart-nudge — drops a notice file Claude reads after upgrade.
4
+ *
5
+ * Problem this solves:
6
+ * When `npm install` runs inside Claude Code (typically because the user
7
+ * asked Claude to upgrade moflo), the just-installed bits are on disk but
8
+ * the running session still has the OLD launcher, hooks, MCP server, and
9
+ * statusline loaded. The launcher only re-reads them on the NEXT
10
+ * session-start — the upgrade is inert until the user restarts.
11
+ *
12
+ * The original v4.9.4 design printed a banner to stdout, expecting npm to
13
+ * relay it. It does not: npm 7+ defaults to `foreground-scripts: false`
14
+ * and captures install-script stdout/stderr into log files. The banner
15
+ * never reached Claude. (#856.)
16
+ *
17
+ * Fix:
18
+ * This script drops `<project>/.moflo/restart-pending.json` on every
19
+ * relevant install. Claude is instructed (via the moflo CLAUDE.md
20
+ * injection) to read + surface + delete the file after running
21
+ * `npm install moflo@*`. No reliance on npm cooperating with stdout.
22
+ *
23
+ * The banner is still printed to stdout for the rare `--foreground-scripts`
24
+ * user, and the dedup tracker is preserved so repeat postinstalls of the
25
+ * same version don't double-write the notice.
26
+ *
27
+ * Files written:
28
+ * - .moflo/restart-pending.json (the payload Claude reads)
29
+ * - .moflo/last-install-banner.json (dedup tracker, version-stamped)
30
+ *
31
+ * Gating:
32
+ * - Only fires when CLAUDE_PROJECT_DIR or CLAUDECODE is set; non-Claude
33
+ * installs and CI stay silent.
34
+ * - Dedupes by version: same (project, version) pair won't re-write.
35
+ *
36
+ * Failure posture: never blocks an install. Errors are swallowed; exit 0.
37
+ */
38
+
39
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
40
+ import { dirname, join, resolve } from 'node:path';
41
+ import { fileURLToPath, pathToFileURL } from 'node:url';
42
+
43
+ const SCRIPT_PATH = fileURLToPath(import.meta.url);
44
+
45
+ function isClaudeSession() {
46
+ return Boolean(process.env.CLAUDE_PROJECT_DIR || process.env.CLAUDECODE);
47
+ }
48
+
49
+ function consumerProjectRoot() {
50
+ // npm sets INIT_CWD to the original directory where the user ran `npm
51
+ // install` — the consumer's project root, regardless of which package's
52
+ // postinstall is running.
53
+ return process.env.INIT_CWD || process.cwd();
54
+ }
55
+
56
+ function installedVersion() {
57
+ // package.json sits one level above scripts/.
58
+ const pkgPath = resolve(dirname(SCRIPT_PATH), '..', 'package.json');
59
+ if (!existsSync(pkgPath)) return null;
60
+ try {
61
+ return JSON.parse(readFileSync(pkgPath, 'utf-8')).version || null;
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+
67
+ function readTrackedVersion(trackerPath) {
68
+ if (!existsSync(trackerPath)) return null;
69
+ try {
70
+ return JSON.parse(readFileSync(trackerPath, 'utf-8')).version || null;
71
+ } catch {
72
+ return null;
73
+ }
74
+ }
75
+
76
+ function writeJson(filePath, payload) {
77
+ try {
78
+ mkdirSync(dirname(filePath), { recursive: true });
79
+ writeFileSync(filePath, JSON.stringify(payload, null, 2));
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
85
+
86
+ function buildMessage(version) {
87
+ // Plain-text payload Claude relays verbatim. Names Claude Code explicitly
88
+ // so the assistant frames it as a restart instruction, not a log line.
89
+ return [
90
+ `MoFlo ${version} installed.`,
91
+ '',
92
+ 'Please restart Claude Code to load the new MoFlo.',
93
+ '',
94
+ 'Hooks, MCP tools, statusline, and the session-start launcher are',
95
+ 'loaded once at session-start — the running session is still on the',
96
+ 'previous moflo until you exit and reopen Claude Code.',
97
+ ].join('\n');
98
+ }
99
+
100
+ function printBanner(version, message) {
101
+ // Stdout fallback for --foreground-scripts users. With npm's default
102
+ // config this output is captured and never seen — that's why the notice
103
+ // file exists. Kept anyway because it costs nothing.
104
+ const border = '═'.repeat(67);
105
+ process.stdout.write(`\n${border}\n MoFlo ${version} installed.\n\n ⚠ ${message.split('\n')[2]}\n${border}\n\n`);
106
+ }
107
+
108
+ function run() {
109
+ if (!isClaudeSession()) return { fired: false, reason: 'not-claude' };
110
+
111
+ const version = installedVersion();
112
+ if (!version) return { fired: false, reason: 'no-version' };
113
+
114
+ const projectRoot = consumerProjectRoot();
115
+ const trackerPath = join(projectRoot, '.moflo', 'last-install-banner.json');
116
+ const noticePath = join(projectRoot, '.moflo', 'restart-pending.json');
117
+
118
+ const lastShown = readTrackedVersion(trackerPath);
119
+ if (lastShown === version) return { fired: false, reason: 'already-shown' };
120
+
121
+ const writtenAt = new Date().toISOString();
122
+ const message = buildMessage(version);
123
+
124
+ writeJson(noticePath, { version, writtenAt, message });
125
+ writeJson(trackerPath, { version, shownAt: writtenAt });
126
+
127
+ printBanner(version, message);
128
+ return { fired: true, version, noticePath };
129
+ }
130
+
131
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
132
+ try {
133
+ run();
134
+ } catch { /* never block install */ }
135
+ process.exit(0);
136
+ }