@phren/cli 0.1.26 → 0.1.28
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/dist/cli/actions.d.ts +1 -1
- package/dist/cli/actions.js +1 -12
- package/dist/cli/namespaces-profile.d.ts +1 -1
- package/dist/cli/namespaces-profile.js +4 -6
- package/dist/cli/namespaces-skills.js +2 -2
- package/dist/cli/namespaces-store.js +1 -2
- package/dist/cli/namespaces-utils.d.ts +0 -1
- package/dist/cli/namespaces-utils.js +0 -7
- package/dist/cli/search.js +0 -12
- package/dist/cli/team.js +1 -23
- package/dist/cli-handlers.d.ts +17 -0
- package/dist/cli-handlers.js +204 -0
- package/dist/cli-help.d.ts +6 -0
- package/dist/cli-help.js +125 -0
- package/dist/cli-registry.d.ts +45 -0
- package/dist/cli-registry.js +715 -0
- package/dist/entrypoint.d.ts +0 -1
- package/dist/entrypoint.js +74 -420
- package/dist/hooks.js +4 -1
- package/dist/init/setup.js +63 -12
- package/dist/link/link.js +10 -0
- package/dist/phren-paths.d.ts +1 -0
- package/dist/phren-paths.js +1 -1
- package/dist/proactivity.d.ts +1 -0
- package/dist/proactivity.js +1 -1
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +2 -2
- package/dist/utils-helpers.d.ts +2 -0
- package/dist/utils-helpers.js +24 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -6
- package/package.json +2 -2
- package/dist/cli/cli.d.ts +0 -3
- package/dist/cli/cli.js +0 -125
- package/starter/global/skills/audit.md +0 -106
- package/starter/global/skills/humanize.md +0 -30
package/dist/entrypoint.d.ts
CHANGED
package/dist/entrypoint.js
CHANGED
|
@@ -1,198 +1,12 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import { parseMcpMode, runInit } from "./init/init.js";
|
|
4
3
|
import { errorMessage } from "./utils.js";
|
|
5
4
|
import { logger } from "./logger.js";
|
|
6
|
-
import { defaultPhrenPath, expandHomePath,
|
|
5
|
+
import { defaultPhrenPath, expandHomePath, getPhrenPath, readRootManifest, } from "./shared.js";
|
|
6
|
+
import { resolveRuntimeProfile } from "./runtime-profile.js";
|
|
7
7
|
import { VERSION } from "./package-metadata.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
const HELP_TEXT = `phren - persistent memory for AI agents
|
|
11
|
-
|
|
12
|
-
phren Interactive memory shell
|
|
13
|
-
phren init Set up phren
|
|
14
|
-
phren quickstart Quick setup: init + project scaffold
|
|
15
|
-
phren add [path] Register a project
|
|
16
|
-
phren search <query> Search what phren knows
|
|
17
|
-
phren status Health check
|
|
18
|
-
phren doctor [--fix] Diagnose and repair
|
|
19
|
-
phren web-ui Open the knowledge graph
|
|
20
|
-
phren tasks Cross-project task view
|
|
21
|
-
phren graph Fragment knowledge graph
|
|
22
|
-
phren shell Interactive memory shell
|
|
23
|
-
|
|
24
|
-
phren manage <command> Alias for the top-level commands above
|
|
25
|
-
phren mem <command> Alias for \`phren manage\`
|
|
26
|
-
|
|
27
|
-
Legacy shortcuts still work:
|
|
28
|
-
phren init, phren search, phren task, phren config, ...
|
|
29
|
-
|
|
30
|
-
phren help <topic> Detailed help
|
|
31
|
-
Topics: projects, skills, hooks, config, maintain, setup, stores, team, env, all
|
|
32
|
-
`;
|
|
33
|
-
const INTEGRATED_HELP_TEXT = HELP_TEXT;
|
|
34
|
-
const HELP_TOPICS = {
|
|
35
|
-
projects: `Projects:
|
|
36
|
-
phren add [path] [--ownership <mode>] Register a project
|
|
37
|
-
phren projects list List all tracked projects
|
|
38
|
-
phren projects configure <name> [--ownership <mode>] [--hooks on|off]
|
|
39
|
-
Update per-project settings
|
|
40
|
-
phren projects remove <name> Remove a project
|
|
41
|
-
`,
|
|
42
|
-
skills: `Skills:
|
|
43
|
-
phren skills list List installed skills
|
|
44
|
-
phren skills add <project> <path> Link a skill into a project
|
|
45
|
-
phren skills show <name> Show skill content
|
|
46
|
-
phren skills resolve <project|global> Print resolved skill manifest
|
|
47
|
-
phren skills doctor <project|global> Diagnose skill visibility
|
|
48
|
-
phren skills sync <project|global> Regenerate skill mirror
|
|
49
|
-
phren skills enable <project|global> <name> Enable a disabled skill
|
|
50
|
-
phren skills disable <project|global> <name> Disable a skill without deleting
|
|
51
|
-
phren skills remove <project> <name> Remove a skill
|
|
52
|
-
phren detect-skills [--import] Find untracked skills in ~/.claude/skills/
|
|
53
|
-
`,
|
|
54
|
-
hooks: `Hooks:
|
|
55
|
-
phren hooks list [--project <name>] Show hook status per tool
|
|
56
|
-
phren hooks enable <tool> Enable hooks for a tool
|
|
57
|
-
phren hooks disable <tool> Disable hooks for a tool
|
|
58
|
-
phren hooks add-custom <event> <cmd> Add a custom hook
|
|
59
|
-
phren hooks remove-custom <event> Remove custom hooks
|
|
60
|
-
phren hooks errors [--limit <n>] Show recent hook errors
|
|
61
|
-
`,
|
|
62
|
-
config: `Configuration:
|
|
63
|
-
phren config show [--project <name>] Show current config
|
|
64
|
-
phren config policy [get|set ...] Retention, TTL, confidence, decay
|
|
65
|
-
phren config workflow [get|set ...] Risky-memory thresholds
|
|
66
|
-
phren config proactivity [level] Set proactivity level
|
|
67
|
-
phren config task-mode [mode] Set task automation mode
|
|
68
|
-
phren config finding-sensitivity [lvl] Set finding capture sensitivity
|
|
69
|
-
phren config index [get|set ...] Indexer include/exclude globs
|
|
70
|
-
phren config synonyms [list|add|remove] Manage learned synonyms
|
|
71
|
-
phren config project-ownership [mode] Default ownership for new projects
|
|
72
|
-
phren config machines Registered machines
|
|
73
|
-
phren config profiles Profiles and projects
|
|
74
|
-
phren config telemetry [on|off] Opt-in usage telemetry
|
|
75
|
-
|
|
76
|
-
All config subcommands accept --project <name> for per-project overrides.
|
|
77
|
-
`,
|
|
78
|
-
maintain: `Maintenance:
|
|
79
|
-
phren maintain govern [project] Queue stale memories for review
|
|
80
|
-
phren maintain prune [project] Delete expired entries
|
|
81
|
-
phren maintain consolidate [project] Deduplicate findings
|
|
82
|
-
phren maintain extract [project] Mine git/GitHub signals
|
|
83
|
-
`,
|
|
84
|
-
setup: `Setup:
|
|
85
|
-
phren init [--mode shared|project-local] [--machine <n>] [--profile <n>] [--dry-run] [-y]
|
|
86
|
-
phren quickstart Quick setup: init + project scaffold
|
|
87
|
-
phren mcp-mode [on|off|status] Toggle MCP integration
|
|
88
|
-
phren hooks-mode [on|off|status] Toggle hook execution
|
|
89
|
-
phren verify Check init completed OK
|
|
90
|
-
phren uninstall Remove phren config and hooks
|
|
91
|
-
phren update [--refresh-starter] Update to latest version
|
|
92
|
-
`,
|
|
93
|
-
stores: `Stores:
|
|
94
|
-
phren store list List registered stores
|
|
95
|
-
phren store add <name> --remote <url> Add a team store
|
|
96
|
-
phren store remove <name> Remove a store (local only)
|
|
97
|
-
phren store sync Pull all stores
|
|
98
|
-
`,
|
|
99
|
-
team: `Team:
|
|
100
|
-
phren team init <name> [--remote <url>] Create a new team store
|
|
101
|
-
phren team join <git-url> [--name <name>] Join an existing team store
|
|
102
|
-
phren team add-project <store> <project> Add a project to a team store
|
|
103
|
-
phren team list List team stores
|
|
104
|
-
`,
|
|
105
|
-
env: `Environment variables:
|
|
106
|
-
PHREN_PATH Override phren directory (default: ~/.phren)
|
|
107
|
-
PHREN_PROFILE Active profile name
|
|
108
|
-
PHREN_DEBUG Enable debug logging (set to 1)
|
|
109
|
-
|
|
110
|
-
Embeddings:
|
|
111
|
-
PHREN_OLLAMA_URL Ollama base URL (default: http://localhost:11434, 'off' to disable)
|
|
112
|
-
PHREN_EMBEDDING_API_URL OpenAI-compatible /embeddings endpoint
|
|
113
|
-
PHREN_EMBEDDING_API_KEY API key for embedding endpoint
|
|
114
|
-
PHREN_EMBEDDING_MODEL Embedding model (default: nomic-embed-text)
|
|
115
|
-
|
|
116
|
-
Context injection:
|
|
117
|
-
PHREN_CONTEXT_TOKEN_BUDGET Max tokens injected per prompt (default: 550)
|
|
118
|
-
PHREN_MAX_INJECT_TOKENS Hard cap on total injected tokens (default: 2000)
|
|
119
|
-
PHREN_HOOK_TIMEOUT_MS Hook subprocess timeout in ms (default: 14000)
|
|
120
|
-
|
|
121
|
-
Feature flags:
|
|
122
|
-
PHREN_FEATURE_AUTO_EXTRACT=0 Disable auto memory extraction
|
|
123
|
-
PHREN_FEATURE_AUTO_CAPTURE=1 Extract insights from conversations
|
|
124
|
-
PHREN_FEATURE_SEMANTIC_DEDUP=1 LLM-based dedup on add_finding
|
|
125
|
-
PHREN_FEATURE_HYBRID_SEARCH=0 Disable TF-IDF cosine fallback
|
|
126
|
-
|
|
127
|
-
Run 'phren help all' to see everything.
|
|
128
|
-
`,
|
|
129
|
-
};
|
|
130
|
-
function buildFullHelp() {
|
|
131
|
-
return `phren - persistent knowledge for your agents
|
|
132
|
-
|
|
133
|
-
Usage:
|
|
134
|
-
phren Interactive shell
|
|
135
|
-
phren init Set up phren
|
|
136
|
-
phren quickstart Quick setup: init + project scaffold
|
|
137
|
-
phren add [path] Register a project
|
|
138
|
-
phren search <query> Search what phren knows
|
|
139
|
-
phren status Health check
|
|
140
|
-
phren doctor [--fix] Diagnose and repair
|
|
141
|
-
phren web-ui Open the knowledge graph
|
|
142
|
-
phren tasks Cross-project task view
|
|
143
|
-
phren graph Fragment knowledge graph
|
|
144
|
-
phren add-finding <p> "." Tell phren what you learned
|
|
145
|
-
phren pin <p> "..." Save a truth
|
|
146
|
-
phren review [project] Show review queue
|
|
147
|
-
phren session-context Current session state
|
|
148
|
-
|
|
149
|
-
${Object.values(HELP_TOPICS).join("\n")}`;
|
|
150
|
-
}
|
|
151
|
-
export const CLI_COMMANDS = [
|
|
152
|
-
"search",
|
|
153
|
-
"shell",
|
|
154
|
-
"update",
|
|
155
|
-
"config",
|
|
156
|
-
"maintain",
|
|
157
|
-
"hook-prompt",
|
|
158
|
-
"hook-session-start",
|
|
159
|
-
"hook-stop",
|
|
160
|
-
"hook-context",
|
|
161
|
-
"hook-tool",
|
|
162
|
-
"add-finding",
|
|
163
|
-
"pin",
|
|
164
|
-
"doctor",
|
|
165
|
-
"debug-injection",
|
|
166
|
-
"inspect-index",
|
|
167
|
-
"web-ui",
|
|
168
|
-
"quality-feedback",
|
|
169
|
-
"skill-list",
|
|
170
|
-
"skills",
|
|
171
|
-
"hooks",
|
|
172
|
-
"detect-skills",
|
|
173
|
-
"task",
|
|
174
|
-
"tasks",
|
|
175
|
-
"finding",
|
|
176
|
-
"quickstart",
|
|
177
|
-
"background-maintenance",
|
|
178
|
-
"background-sync",
|
|
179
|
-
"projects",
|
|
180
|
-
"extract-memories",
|
|
181
|
-
"govern-memories",
|
|
182
|
-
"prune-memories",
|
|
183
|
-
"consolidate-memories",
|
|
184
|
-
"index-policy",
|
|
185
|
-
"policy",
|
|
186
|
-
"workflow",
|
|
187
|
-
"access",
|
|
188
|
-
"review",
|
|
189
|
-
"consolidation-status",
|
|
190
|
-
"session-context",
|
|
191
|
-
"truths",
|
|
192
|
-
"store",
|
|
193
|
-
"team",
|
|
194
|
-
"promote",
|
|
195
|
-
];
|
|
8
|
+
import { TOPIC_ORDER, helpTopicNames, lookupCommand, } from "./cli-registry.js";
|
|
9
|
+
import { formatCheatSheet, formatCommand, formatDocTopic, formatFullHelp, formatTopic, } from "./cli-help.js";
|
|
196
10
|
function looksLikePhrenRootArg(arg) {
|
|
197
11
|
if (!arg || arg.startsWith("-"))
|
|
198
12
|
return false;
|
|
@@ -231,7 +45,7 @@ export function resolveTopLevelInvocation(argv) {
|
|
|
231
45
|
return { kind: "manage", argv };
|
|
232
46
|
}
|
|
233
47
|
export function printIntegratedHelp() {
|
|
234
|
-
console.log(
|
|
48
|
+
console.log(formatCheatSheet());
|
|
235
49
|
}
|
|
236
50
|
export function printIntegratedVersion() {
|
|
237
51
|
console.log(`phren v${VERSION}`);
|
|
@@ -248,258 +62,98 @@ async function finish(exitCode) {
|
|
|
248
62
|
await flushTopLevelOutput();
|
|
249
63
|
return true;
|
|
250
64
|
}
|
|
251
|
-
function
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return prefixed ? prefixed.slice(name.length + 1) : undefined;
|
|
65
|
+
function buildCliContext() {
|
|
66
|
+
return {
|
|
67
|
+
phrenPath: () => getPhrenPath(),
|
|
68
|
+
profile: () => resolveRuntimeProfile(getPhrenPath()),
|
|
69
|
+
};
|
|
257
70
|
}
|
|
258
|
-
function
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
i += 1;
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
if (optionNamesWithValues.some((name) => arg.startsWith(`${name}=`))) {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
if (!arg.startsWith("--"))
|
|
270
|
-
positions.push(arg);
|
|
71
|
+
async function runHelp(args) {
|
|
72
|
+
const target = args[0]?.toLowerCase();
|
|
73
|
+
if (!target) {
|
|
74
|
+
console.log(formatCheatSheet());
|
|
75
|
+
return finish();
|
|
271
76
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
function parseTaskModeFlag(raw) {
|
|
275
|
-
if (!raw)
|
|
276
|
-
return undefined;
|
|
277
|
-
const normalized = raw.trim().toLowerCase();
|
|
278
|
-
return ["off", "manual", "suggest", "auto"].includes(normalized)
|
|
279
|
-
? normalized
|
|
280
|
-
: undefined;
|
|
281
|
-
}
|
|
282
|
-
function parseProactivityFlag(raw) {
|
|
283
|
-
if (!raw)
|
|
284
|
-
return undefined;
|
|
285
|
-
const normalized = raw.trim().toLowerCase();
|
|
286
|
-
return ["high", "medium", "low"].includes(normalized)
|
|
287
|
-
? normalized
|
|
288
|
-
: undefined;
|
|
289
|
-
}
|
|
290
|
-
async function promptProjectOwnership(phrenPath, fallback) {
|
|
291
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
292
|
-
return fallback;
|
|
293
|
-
const readline = await import("readline");
|
|
294
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
295
|
-
return new Promise((resolve) => {
|
|
296
|
-
rl.question(`Project ownership [${PROJECT_OWNERSHIP_MODES.join("/")}] (${fallback}): `, (input) => {
|
|
297
|
-
rl.close();
|
|
298
|
-
resolve(parseProjectOwnershipMode(input.trim()) ?? fallback);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
export async function runTopLevelCommand(argv, opts = {}) {
|
|
303
|
-
const argvCommand = argv[0];
|
|
304
|
-
if (argvCommand === "--help" || argvCommand === "-h" || argvCommand === "help") {
|
|
305
|
-
const topic = argv[1]?.toLowerCase();
|
|
306
|
-
if (topic === "all") {
|
|
307
|
-
console.log(buildFullHelp());
|
|
308
|
-
}
|
|
309
|
-
else if (topic && HELP_TOPICS[topic]) {
|
|
310
|
-
console.log(HELP_TOPICS[topic]);
|
|
311
|
-
}
|
|
312
|
-
else if (topic) {
|
|
313
|
-
console.log(`Unknown topic: ${topic}\nAvailable: ${Object.keys(HELP_TOPICS).join(", ")}, all`);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
console.log(HELP_TEXT);
|
|
317
|
-
}
|
|
77
|
+
if (target === "all") {
|
|
78
|
+
console.log(formatFullHelp());
|
|
318
79
|
return finish();
|
|
319
80
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const profile = (process.env.PHREN_PROFILE) || undefined;
|
|
326
|
-
if (!fs.existsSync(phrenPath) || !fs.existsSync(path.join(phrenPath, ".config"))) {
|
|
327
|
-
console.log("phren is not set up yet. Run: phren init");
|
|
328
|
-
return finish(1);
|
|
329
|
-
}
|
|
330
|
-
const ownership = ownershipArg
|
|
331
|
-
? parseProjectOwnershipMode(ownershipArg)
|
|
332
|
-
: await promptProjectOwnership(phrenPath, getProjectOwnershipDefault(phrenPath));
|
|
333
|
-
if (ownershipArg && !ownership) {
|
|
334
|
-
console.error(`Invalid --ownership value "${ownershipArg}". Use one of: ${PROJECT_OWNERSHIP_MODES.join(", ")}`);
|
|
335
|
-
return finish(1);
|
|
336
|
-
}
|
|
337
|
-
try {
|
|
338
|
-
const added = addProjectFromPath(phrenPath, path.resolve(targetPath), profile, ownership);
|
|
339
|
-
if (!added.ok) {
|
|
340
|
-
console.error(added.error);
|
|
341
|
-
return finish(1);
|
|
342
|
-
}
|
|
343
|
-
console.log(`Added project "${added.data.project}" (${added.data.ownership})`);
|
|
344
|
-
if (added.data.files.claude)
|
|
345
|
-
console.log(` ${added.data.files.claude}`);
|
|
346
|
-
console.log(` ${added.data.files.findings}`);
|
|
347
|
-
console.log(` ${added.data.files.task}`);
|
|
348
|
-
console.log(` ${added.data.files.summary}`);
|
|
349
|
-
}
|
|
350
|
-
catch (e) {
|
|
351
|
-
console.error(`Could not add project: ${e instanceof Error ? e.message : String(e)}`);
|
|
352
|
-
return finish(1);
|
|
353
|
-
}
|
|
81
|
+
// Topic precedence: a name that's both a topic and a command (e.g. "projects",
|
|
82
|
+
// "skills") shows the topic view, which lists every command in that group.
|
|
83
|
+
// Matches the legacy HELP_TOPICS behavior.
|
|
84
|
+
if (TOPIC_ORDER.includes(target)) {
|
|
85
|
+
console.log(formatTopic(target));
|
|
354
86
|
return finish();
|
|
355
87
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const profileIdx = initArgs.indexOf("--profile");
|
|
360
|
-
const mcpIdx = initArgs.indexOf("--mcp");
|
|
361
|
-
const templateIdx = initArgs.indexOf("--template");
|
|
362
|
-
const modeArg = getOptionValue(initArgs, "--mode");
|
|
363
|
-
if (modeArg && !["shared", "project-local"].includes(modeArg)) {
|
|
364
|
-
console.error(`Invalid --mode value "${modeArg}". Use "shared" or "project-local".`);
|
|
365
|
-
return finish(1);
|
|
366
|
-
}
|
|
367
|
-
const ownershipMode = parseProjectOwnershipMode(getOptionValue(initArgs, "--project-ownership"));
|
|
368
|
-
const taskMode = parseTaskModeFlag(getOptionValue(initArgs, "--task-mode"));
|
|
369
|
-
const findingsProactivity = parseProactivityFlag(getOptionValue(initArgs, "--findings-proactivity"));
|
|
370
|
-
const taskProactivity = parseProactivityFlag(getOptionValue(initArgs, "--task-proactivity"));
|
|
371
|
-
const mcpMode = mcpIdx !== -1 ? parseMcpMode(initArgs[mcpIdx + 1]) : undefined;
|
|
372
|
-
if (mcpIdx !== -1 && !mcpMode) {
|
|
373
|
-
console.error(`Invalid --mcp value "${initArgs[mcpIdx + 1] || ""}". Use "on" or "off".`);
|
|
374
|
-
return finish(1);
|
|
375
|
-
}
|
|
376
|
-
const ownershipArg = getOptionValue(initArgs, "--project-ownership");
|
|
377
|
-
if (ownershipArg && !ownershipMode) {
|
|
378
|
-
console.error(`Invalid --project-ownership value "${ownershipArg}". Use one of: ${PROJECT_OWNERSHIP_MODES.join(", ")}`);
|
|
379
|
-
return finish(1);
|
|
380
|
-
}
|
|
381
|
-
const taskModeArg = getOptionValue(initArgs, "--task-mode");
|
|
382
|
-
if (taskModeArg && !taskMode) {
|
|
383
|
-
console.error(`Invalid --task-mode value "${taskModeArg}". Use one of: off, manual, suggest, auto.`);
|
|
384
|
-
return finish(1);
|
|
385
|
-
}
|
|
386
|
-
const findingsArg = getOptionValue(initArgs, "--findings-proactivity");
|
|
387
|
-
if (findingsArg && !findingsProactivity) {
|
|
388
|
-
console.error(`Invalid --findings-proactivity value "${findingsArg}". Use one of: high, medium, low.`);
|
|
389
|
-
return finish(1);
|
|
390
|
-
}
|
|
391
|
-
const taskArg = getOptionValue(initArgs, "--task-proactivity");
|
|
392
|
-
if (taskArg && !taskProactivity) {
|
|
393
|
-
console.error(`Invalid --task-proactivity value "${taskArg}". Use one of: high, medium, low.`);
|
|
394
|
-
return finish(1);
|
|
395
|
-
}
|
|
396
|
-
const cloneUrl = getOptionValue(initArgs, "--clone-url");
|
|
397
|
-
try {
|
|
398
|
-
await runInit({
|
|
399
|
-
mode: modeArg,
|
|
400
|
-
machine: machineIdx !== -1 ? initArgs[machineIdx + 1] : undefined,
|
|
401
|
-
profile: profileIdx !== -1 ? initArgs[profileIdx + 1] : undefined,
|
|
402
|
-
mcp: mcpMode,
|
|
403
|
-
projectOwnershipDefault: ownershipMode,
|
|
404
|
-
taskMode,
|
|
405
|
-
findingsProactivity,
|
|
406
|
-
taskProactivity,
|
|
407
|
-
template: templateIdx !== -1 ? initArgs[templateIdx + 1] : undefined,
|
|
408
|
-
applyStarterUpdate: initArgs.includes("--apply-starter-update"),
|
|
409
|
-
dryRun: initArgs.includes("--dry-run"),
|
|
410
|
-
yes: initArgs.includes("--yes") || initArgs.includes("-y"),
|
|
411
|
-
express: initArgs.includes("--express"),
|
|
412
|
-
force: initArgs.includes("--force"),
|
|
413
|
-
_walkthroughCloneUrl: cloneUrl,
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
catch (err) {
|
|
417
|
-
console.error(errorMessage(err));
|
|
418
|
-
return finish(1);
|
|
419
|
-
}
|
|
88
|
+
const cmdHelp = formatCommand(target);
|
|
89
|
+
if (cmdHelp !== null) {
|
|
90
|
+
console.log(cmdHelp);
|
|
420
91
|
return finish();
|
|
421
92
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
await runUninstall({ yes: skipConfirm });
|
|
93
|
+
const docHelp = formatDocTopic(target);
|
|
94
|
+
if (docHelp !== null) {
|
|
95
|
+
console.log(docHelp);
|
|
426
96
|
return finish();
|
|
427
97
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
98
|
+
console.log(`Unknown topic: ${target}\nAvailable: ${helpTopicNames().join(", ")}`);
|
|
99
|
+
return finish();
|
|
100
|
+
}
|
|
101
|
+
export async function runTopLevelCommand(argv, opts = {}) {
|
|
102
|
+
const argvCommand = argv[0];
|
|
103
|
+
// Health ping. Must run before lookupCommand - `--health` starts with `--`
|
|
104
|
+
// so it's never a registered command name.
|
|
105
|
+
if (argvCommand === "--health")
|
|
431
106
|
return finish();
|
|
107
|
+
if (argvCommand === "--help" || argvCommand === "-h" || argvCommand === "help") {
|
|
108
|
+
return runHelp(argv.slice(1));
|
|
432
109
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (!check.ok && check.fix) {
|
|
443
|
-
console.log(` fix: ${check.fix}`);
|
|
110
|
+
// Bare invocation. On a TTY (and unless suppressed), drop into the shell.
|
|
111
|
+
// On a non-TTY pipeline, fall through to the unknown-command path below;
|
|
112
|
+
// matches legacy behavior so scripts that grep stderr for "Unknown command"
|
|
113
|
+
// keep working.
|
|
114
|
+
if (!argvCommand) {
|
|
115
|
+
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
116
|
+
if (opts.allowDefaultShell === false) {
|
|
117
|
+
console.log(formatCheatSheet());
|
|
118
|
+
return finish();
|
|
444
119
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (note)
|
|
449
|
-
console.log(`\nNote: ${note}`);
|
|
450
|
-
console.log(`\nRun \`phren init\` to fix setup issues.`);
|
|
451
|
-
}
|
|
452
|
-
return finish(result.ok ? 0 : 1);
|
|
453
|
-
}
|
|
454
|
-
if (argvCommand === "mcp-mode") {
|
|
455
|
-
const { runMcpMode } = await import("./init/init.js");
|
|
456
|
-
try {
|
|
457
|
-
await runMcpMode(argv[1]);
|
|
458
|
-
return finish();
|
|
459
|
-
}
|
|
460
|
-
catch (err) {
|
|
461
|
-
console.error(errorMessage(err));
|
|
462
|
-
return finish(1);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (argvCommand === "hooks-mode") {
|
|
466
|
-
const { runHooksMode } = await import("./init/init.js");
|
|
467
|
-
try {
|
|
468
|
-
await runHooksMode(argv[1]);
|
|
120
|
+
const shellCmd = lookupCommand("shell");
|
|
121
|
+
if (shellCmd)
|
|
122
|
+
await shellCmd.run([], buildCliContext());
|
|
469
123
|
return finish();
|
|
470
124
|
}
|
|
471
|
-
|
|
472
|
-
console.error(errorMessage(err));
|
|
473
|
-
return finish(1);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (argvCommand === "link") {
|
|
477
|
-
console.error("`phren link` has been removed. Use `phren init` instead.");
|
|
478
|
-
return finish(1);
|
|
479
|
-
}
|
|
480
|
-
if (argvCommand === "--health") {
|
|
481
|
-
return finish();
|
|
125
|
+
return false;
|
|
482
126
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
127
|
+
const cmd = lookupCommand(argvCommand);
|
|
128
|
+
if (!cmd)
|
|
129
|
+
return false;
|
|
130
|
+
// Intercept before any handler runs - in particular before namespace
|
|
131
|
+
// handlers that used to print their own per-subcommand help text.
|
|
132
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
133
|
+
const out = formatCommand(cmd.name);
|
|
134
|
+
if (out)
|
|
135
|
+
console.log(out);
|
|
490
136
|
return finish();
|
|
491
137
|
}
|
|
492
|
-
|
|
493
|
-
|
|
138
|
+
// Telemetry. Broadens from the legacy CLI_COMMANDS-only branch - natives
|
|
139
|
+
// (add/init/etc.) are now tracked too. Telemetry is opt-in. Hidden internal
|
|
140
|
+
// commands (hook-prompt, background-sync, etc.) are skipped: they fire on
|
|
141
|
+
// every prompt and would drown the meaningful counts.
|
|
142
|
+
if (!cmd.hidden) {
|
|
494
143
|
try {
|
|
495
144
|
const { trackCliCommand } = await import("./telemetry.js");
|
|
496
|
-
trackCliCommand(defaultPhrenPath(),
|
|
145
|
+
trackCliCommand(defaultPhrenPath(), cmd.name);
|
|
497
146
|
}
|
|
498
147
|
catch (err) {
|
|
499
148
|
logger.debug("cli", `trackCliCommand: ${errorMessage(err)}`);
|
|
500
149
|
}
|
|
501
|
-
await runCliCommand(argvCommand, argv.slice(1));
|
|
502
|
-
return finish();
|
|
503
150
|
}
|
|
504
|
-
|
|
151
|
+
try {
|
|
152
|
+
const code = await cmd.run(argv.slice(1), buildCliContext());
|
|
153
|
+
return finish(typeof code === "number" ? code : undefined);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
console.error(errorMessage(err));
|
|
157
|
+
return finish(1);
|
|
158
|
+
}
|
|
505
159
|
}
|
package/dist/hooks.js
CHANGED
|
@@ -24,7 +24,10 @@ export function commandExists(cmd) {
|
|
|
24
24
|
}
|
|
25
25
|
export function detectInstalledTools() {
|
|
26
26
|
const tools = new Set();
|
|
27
|
-
if (commandExists("
|
|
27
|
+
if (commandExists("copilot")
|
|
28
|
+
|| commandExists("github-copilot-cli")
|
|
29
|
+
|| fs.existsSync(homePath(".local", "share", "gh", "extensions", "gh-copilot"))
|
|
30
|
+
|| fs.existsSync(homePath(".copilot", "config.json"))) {
|
|
28
31
|
tools.add("copilot");
|
|
29
32
|
}
|
|
30
33
|
if (commandExists("cursor")) {
|
package/dist/init/setup.js
CHANGED
|
@@ -20,6 +20,7 @@ import { getProjectOwnershipDefault, parseProjectOwnershipMode, readProjectConfi
|
|
|
20
20
|
import { getBuiltinTopicConfig, normalizeBuiltinTopicDomain } from "../project-topics.js";
|
|
21
21
|
import { writeSkillMd } from "../link/skills.js";
|
|
22
22
|
import { syncScopeSkillsToDir } from "../skill/files.js";
|
|
23
|
+
import { detectInstalledTools } from "../hooks.js";
|
|
23
24
|
import { logger } from "../logger.js";
|
|
24
25
|
const LEGACY_SAMPLE_PROJECTS = new Set(["my-api", "my-frontend"]);
|
|
25
26
|
function normalizeProjects(raw) {
|
|
@@ -155,21 +156,38 @@ function ensureGlobalStarterAssets(phrenPath) {
|
|
|
155
156
|
}
|
|
156
157
|
const starterSkillsDir = path.join(starterGlobal, "skills");
|
|
157
158
|
const targetSkillsDir = path.join(targetGlobalDir, "skills");
|
|
159
|
+
fs.mkdirSync(targetSkillsDir, { recursive: true });
|
|
158
160
|
if (fs.existsSync(starterSkillsDir)) {
|
|
159
|
-
fs.mkdirSync(targetSkillsDir, { recursive: true });
|
|
160
161
|
for (const entry of fs.readdirSync(starterSkillsDir, { withFileTypes: true })) {
|
|
161
|
-
if (!entry.isFile())
|
|
162
|
-
continue;
|
|
163
162
|
const source = path.join(starterSkillsDir, entry.name);
|
|
164
163
|
const target = path.join(targetSkillsDir, entry.name);
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
165
|
+
if (fs.existsSync(target))
|
|
166
|
+
continue;
|
|
167
|
+
fs.copyFileSync(source, target);
|
|
168
|
+
created.push(path.join("global", "skills", entry.name));
|
|
169
|
+
}
|
|
170
|
+
else if (entry.isDirectory() && fs.existsSync(path.join(source, "SKILL.md"))) {
|
|
171
|
+
if (fs.existsSync(target))
|
|
172
|
+
continue;
|
|
173
|
+
copyDirRecursive(source, target);
|
|
174
|
+
created.push(path.join("global", "skills", entry.name) + path.sep);
|
|
175
|
+
}
|
|
169
176
|
}
|
|
170
177
|
}
|
|
171
178
|
return created;
|
|
172
179
|
}
|
|
180
|
+
function copyDirRecursive(src, dest) {
|
|
181
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
182
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
183
|
+
const s = path.join(src, entry.name);
|
|
184
|
+
const d = path.join(dest, entry.name);
|
|
185
|
+
if (entry.isDirectory())
|
|
186
|
+
copyDirRecursive(s, d);
|
|
187
|
+
else if (entry.isFile())
|
|
188
|
+
fs.copyFileSync(s, d);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
173
191
|
function ensureRuntimeAssets(phrenPath) {
|
|
174
192
|
const created = [];
|
|
175
193
|
const runtimeDir = path.join(phrenPath, ".runtime");
|
|
@@ -222,6 +240,18 @@ function ensureGeneratedSkillArtifacts(phrenPath, preferredHome) {
|
|
|
222
240
|
catch (err) {
|
|
223
241
|
debugLog(`ensureGeneratedSkillArtifacts: global skill mirror sync failed: ${errorMessage(err)}`);
|
|
224
242
|
}
|
|
243
|
+
const copilotSkillsDir = path.join(preferredHome, ".copilot", "skills");
|
|
244
|
+
const hadCopilotSkillsDir = fs.existsSync(copilotSkillsDir);
|
|
245
|
+
if (detectInstalledTools().has("copilot")) {
|
|
246
|
+
try {
|
|
247
|
+
syncScopeSkillsToDir(phrenPath, "global", copilotSkillsDir);
|
|
248
|
+
if (!hadCopilotSkillsDir && fs.existsSync(copilotSkillsDir))
|
|
249
|
+
created.push("~/.copilot/skills/");
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
debugLog(`ensureGeneratedSkillArtifacts: copilot skill mirror sync failed: ${errorMessage(err)}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
225
255
|
const skillMdPath = path.join(phrenPath, "phren.SKILL.md");
|
|
226
256
|
if (!fs.existsSync(skillMdPath)) {
|
|
227
257
|
try {
|
|
@@ -445,15 +475,36 @@ export function applyStarterTemplateUpdates(phrenPath) {
|
|
|
445
475
|
if (fs.existsSync(starterSkillsDir)) {
|
|
446
476
|
fs.mkdirSync(targetSkillsDir, { recursive: true });
|
|
447
477
|
for (const f of fs.readdirSync(starterSkillsDir, { withFileTypes: true })) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
478
|
+
const src = path.join(starterSkillsDir, f.name);
|
|
479
|
+
const dest = path.join(targetSkillsDir, f.name);
|
|
480
|
+
if (f.isFile() && f.name.endsWith(".md")) {
|
|
481
|
+
const written = copyStarterFile(phrenPath, src, dest);
|
|
482
|
+
if (written)
|
|
483
|
+
updates.push(path.relative(phrenPath, written));
|
|
484
|
+
}
|
|
485
|
+
else if (f.isDirectory() && fs.existsSync(path.join(src, "SKILL.md"))) {
|
|
486
|
+
for (const inner of walkSkillFolder(src)) {
|
|
487
|
+
const written = copyStarterFile(phrenPath, path.join(src, inner), path.join(dest, inner));
|
|
488
|
+
if (written)
|
|
489
|
+
updates.push(path.relative(phrenPath, written));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
453
492
|
}
|
|
454
493
|
}
|
|
455
494
|
return updates;
|
|
456
495
|
}
|
|
496
|
+
function walkSkillFolder(root, prefix = "") {
|
|
497
|
+
const out = [];
|
|
498
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
499
|
+
const rel = path.join(prefix, entry.name);
|
|
500
|
+
const abs = path.join(root, entry.name);
|
|
501
|
+
if (entry.isDirectory())
|
|
502
|
+
out.push(...walkSkillFolder(abs, rel));
|
|
503
|
+
else if (entry.isFile())
|
|
504
|
+
out.push(rel);
|
|
505
|
+
}
|
|
506
|
+
return out;
|
|
507
|
+
}
|
|
457
508
|
export function ensureGovernanceFiles(phrenPath) {
|
|
458
509
|
const created = [];
|
|
459
510
|
const govDir = path.join(phrenPath, ".config");
|