@phren/cli 0.1.31 → 0.1.33
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/capabilities/cli.js +2 -2
- package/dist/cli/config-access.d.ts +1 -0
- package/dist/cli/config-access.js +59 -0
- package/dist/cli/config-llm.d.ts +1 -0
- package/dist/cli/config-llm.js +60 -0
- package/dist/cli/config-policy.d.ts +11 -0
- package/dist/cli/config-policy.js +328 -0
- package/dist/cli/config-proactivity.d.ts +15 -0
- package/dist/cli/config-proactivity.js +129 -0
- package/dist/cli/config-shared.d.ts +6 -0
- package/dist/cli/config-shared.js +23 -0
- package/dist/cli/config-synonyms.d.ts +1 -0
- package/dist/cli/config-synonyms.js +60 -0
- package/dist/cli/config.d.ts +6 -24
- package/dist/cli/config.js +13 -670
- package/dist/finding-graph-id.d.ts +15 -0
- package/dist/finding-graph-id.js +58 -0
- package/dist/generated/memory-ui-graph.browser.js +15 -15
- package/dist/governance/activity.d.ts +36 -0
- package/dist/governance/activity.js +83 -0
- package/dist/governance/rbac.d.ts +17 -0
- package/dist/governance/rbac.js +37 -1
- package/dist/memory-ui-graph.runtime.js +15 -15
- package/dist/phren-paths.d.ts +6 -0
- package/dist/phren-paths.js +8 -0
- package/dist/shared/governance.d.ts +1 -0
- package/dist/shared/governance.js +1 -0
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +1 -1
- package/dist/tools/config.js +39 -2
- package/dist/tools/finding.js +5 -11
- package/dist/tools/search.js +28 -1
- package/dist/tools/tasks.js +3 -12
- package/dist/ui/data.d.ts +2 -0
- package/dist/ui/data.js +8 -3
- package/dist/ui/graph.js +2 -0
- package/dist/ui/page.js +45 -2
- package/dist/ui/scripts.d.ts +13 -0
- package/dist/ui/scripts.js +229 -2
- package/dist/ui/server.js +165 -1
- package/dist/ui/styles.d.ts +1 -0
- package/dist/ui/styles.js +38 -0
- package/package.json +1 -1
- package/dist/cli-hooks-prompt.d.ts +0 -18
- package/dist/cli-hooks-prompt.js +0 -359
- package/dist/cli-hooks-session-handlers.d.ts +0 -3
- package/dist/cli-hooks-session-handlers.js +0 -356
- package/dist/cli-hooks-stop.d.ts +0 -11
- package/dist/cli-hooks-stop.js +0 -584
- package/dist/init-bootstrap.d.ts +0 -5
- package/dist/init-bootstrap.js +0 -21
- package/dist/init-detect.d.ts +0 -8
- package/dist/init-detect.js +0 -38
- package/dist/init-env.d.ts +0 -6
- package/dist/init-env.js +0 -114
- package/dist/init-fresh.d.ts +0 -10
- package/dist/init-fresh.js +0 -234
- package/dist/init-hooks.d.ts +0 -5
- package/dist/init-hooks.js +0 -26
- package/dist/init-mcp.d.ts +0 -8
- package/dist/init-mcp.js +0 -65
- package/dist/init-modes.d.ts +0 -4
- package/dist/init-modes.js +0 -135
- package/dist/init-npm.d.ts +0 -10
- package/dist/init-npm.js +0 -37
- package/dist/init-project-local.d.ts +0 -2
- package/dist/init-project-local.js +0 -99
- package/dist/init-semantic.d.ts +0 -4
- package/dist/init-semantic.js +0 -48
- package/dist/init-types.d.ts +0 -59
- package/dist/init-types.js +0 -1
- package/dist/init-update.d.ts +0 -10
- package/dist/init-update.js +0 -96
package/dist/capabilities/cli.js
CHANGED
|
@@ -38,8 +38,8 @@ export const cliManifest = {
|
|
|
38
38
|
"health.check": { implemented: true, handler: "cli-actions.ts:handleDoctor" },
|
|
39
39
|
"health.doctor_fix": { implemented: true, handler: "cli-actions.ts:handleDoctor --fix" },
|
|
40
40
|
"health.sync": { implemented: true, handler: "hook-stop auto-commit" },
|
|
41
|
-
"session.start": { implemented: true, handler: "cli-
|
|
42
|
-
"session.end": { implemented: true, handler: "cli-
|
|
41
|
+
"session.start": { implemented: true, handler: "cli/session-start.ts (hook)" },
|
|
42
|
+
"session.end": { implemented: true, handler: "cli/session-stop.ts (hook)" },
|
|
43
43
|
// Skill management
|
|
44
44
|
"skill.list": { implemented: true, handler: "cli-actions.ts:handleSkillList" },
|
|
45
45
|
"skill.read": { implemented: true, handler: "cli-actions.ts:handleSkills read" },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleConfigAccess(args: string[]): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getPhrenPath } from "../shared.js";
|
|
2
|
+
import { buildConfigView } from "../config/resolve.js";
|
|
3
|
+
import { isValidProjectName } from "../utils.js";
|
|
4
|
+
import { ACCESS_ROLE_KEYS, setAccessRoles } from "../governance/rbac.js";
|
|
5
|
+
import { parseProjectArg, warnIfUnregistered } from "./config-shared.js";
|
|
6
|
+
// ── Access control ───────────────────────────────────────────────────────────
|
|
7
|
+
function parseRoleList(raw) {
|
|
8
|
+
return raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
9
|
+
}
|
|
10
|
+
function printAccessSnapshot(phrenPath, projectArg) {
|
|
11
|
+
const view = buildConfigView(phrenPath, projectArg);
|
|
12
|
+
console.log(JSON.stringify({
|
|
13
|
+
_project: projectArg ?? null,
|
|
14
|
+
_note: "Effective lists are the union of global and per-project roles. All lists empty everywhere = open mode.",
|
|
15
|
+
admins: view.fields["access.admins"].value,
|
|
16
|
+
contributors: view.fields["access.contributors"].value,
|
|
17
|
+
readers: view.fields["access.readers"].value,
|
|
18
|
+
}, null, 2));
|
|
19
|
+
}
|
|
20
|
+
export function handleConfigAccess(args) {
|
|
21
|
+
const phrenPath = getPhrenPath();
|
|
22
|
+
const { project: projectArg, rest } = parseProjectArg(args);
|
|
23
|
+
const action = rest[0];
|
|
24
|
+
if (projectArg && !isValidProjectName(projectArg)) {
|
|
25
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
if (!action || action === "get") {
|
|
29
|
+
printAccessSnapshot(phrenPath, projectArg);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (action === "set") {
|
|
33
|
+
const patch = {};
|
|
34
|
+
let touched = false;
|
|
35
|
+
for (const arg of rest.slice(1)) {
|
|
36
|
+
if (!arg.startsWith("--"))
|
|
37
|
+
continue;
|
|
38
|
+
const [k, v] = arg.slice(2).split("=");
|
|
39
|
+
if (!k || v === undefined)
|
|
40
|
+
continue;
|
|
41
|
+
if (ACCESS_ROLE_KEYS.includes(k)) {
|
|
42
|
+
patch[k] = parseRoleList(v);
|
|
43
|
+
touched = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!touched) {
|
|
47
|
+
console.error("Usage: phren config access [--project <name>] set --admins=a,b --contributors=c --readers=d");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
if (projectArg) {
|
|
51
|
+
warnIfUnregistered(phrenPath, projectArg);
|
|
52
|
+
}
|
|
53
|
+
setAccessRoles(phrenPath, patch, projectArg);
|
|
54
|
+
printAccessSnapshot(phrenPath, projectArg);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
console.error("Usage: phren config access [--project <name>] [get|set --admins=a,b --contributors=c --readers=d]");
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleConfigLlm(args: string[]): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// ── LLM config ───────────────────────────────────────────────────────────────
|
|
2
|
+
const EXPENSIVE_MODEL_RE = /opus|sonnet|gpt-4(?!o-mini)/i;
|
|
3
|
+
const DEFAULT_LLM_MODEL = "gpt-4o-mini / claude-haiku-4-5-20251001";
|
|
4
|
+
function printSemanticCostNotice(model) {
|
|
5
|
+
const effectiveModel = model || process.env.PHREN_LLM_MODEL || DEFAULT_LLM_MODEL;
|
|
6
|
+
console.log(` Note: Each semantic check is ~80 input + ~5 output tokens (one call per 'maybe' pair, cached 24h).`);
|
|
7
|
+
console.log(` Current model: ${effectiveModel}`);
|
|
8
|
+
if (model && EXPENSIVE_MODEL_RE.test(model)) {
|
|
9
|
+
console.log(` Warning: This model is 20x more expensive than Haiku for yes/no checks.`);
|
|
10
|
+
console.log(` Consider: PHREN_LLM_MODEL=claude-haiku-4-5-20251001`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function llmConfigSnapshot() {
|
|
14
|
+
return {
|
|
15
|
+
model: process.env.PHREN_LLM_MODEL || null,
|
|
16
|
+
endpoint: process.env.PHREN_LLM_ENDPOINT || null,
|
|
17
|
+
keySet: Boolean(process.env.PHREN_LLM_KEY || process.env.ANTHROPIC_API_KEY || process.env.OPENAI_API_KEY),
|
|
18
|
+
note: `Set via environment variables. Each semantic check: ~80 input + ~5 output tokens. Default model: ${DEFAULT_LLM_MODEL}.`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function handleConfigLlm(args) {
|
|
22
|
+
const action = args[0];
|
|
23
|
+
if (!action || action === "get") {
|
|
24
|
+
const snapshot = llmConfigSnapshot();
|
|
25
|
+
console.log(JSON.stringify(snapshot, null, 2));
|
|
26
|
+
const model = process.env.PHREN_LLM_MODEL;
|
|
27
|
+
if (model && EXPENSIVE_MODEL_RE.test(model)) {
|
|
28
|
+
process.stderr.write(`\nWarning: PHREN_LLM_MODEL=${model} is expensive for yes/no semantic checks.\n`);
|
|
29
|
+
process.stderr.write(`Consider: PHREN_LLM_MODEL=claude-haiku-4-5-20251001\n`);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (action === "set") {
|
|
34
|
+
const key = args[1];
|
|
35
|
+
const value = args[2];
|
|
36
|
+
if (!key || !value) {
|
|
37
|
+
console.error("Usage: phren config llm set model <name>");
|
|
38
|
+
console.error(" phren config llm set endpoint <url>");
|
|
39
|
+
console.error(" phren config llm set key <api-key>");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const envMap = {
|
|
43
|
+
model: "PHREN_LLM_MODEL",
|
|
44
|
+
endpoint: "PHREN_LLM_ENDPOINT",
|
|
45
|
+
key: "PHREN_LLM_KEY",
|
|
46
|
+
};
|
|
47
|
+
const envVar = envMap[key];
|
|
48
|
+
if (!envVar) {
|
|
49
|
+
console.error(`Unknown setting "${key}". Valid: model, endpoint, key`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
console.log(`Set ${envVar}=${value} in your shell or ~/.phren/.env`);
|
|
53
|
+
if (key === "model") {
|
|
54
|
+
printSemanticCostNotice(value);
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
console.error("Usage: phren config llm [get|set model <name>|set endpoint <url>|set key <api-key>]");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FindingSensitivityLevel } from "../shared/governance.js";
|
|
2
|
+
export declare const FINDING_SENSITIVITY_CONFIG: Record<FindingSensitivityLevel, {
|
|
3
|
+
sessionCap: number;
|
|
4
|
+
proactivityFindings: string;
|
|
5
|
+
agentInstruction: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function handleConfigTaskMode(args: string[]): void;
|
|
8
|
+
export declare function handleConfigFindingSensitivity(args: string[]): void;
|
|
9
|
+
export declare function handleIndexPolicy(args: string[]): Promise<void>;
|
|
10
|
+
export declare function handleRetentionPolicy(args: string[]): Promise<void>;
|
|
11
|
+
export declare function handleWorkflowPolicy(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { getPhrenPath } from "../shared.js";
|
|
2
|
+
import { getIndexPolicy, updateIndexPolicy, getRetentionPolicy, updateRetentionPolicy, getWorkflowPolicy, updateWorkflowPolicy, mergeConfig, VALID_TASK_MODES, VALID_FINDING_SENSITIVITY, } from "../shared/governance.js";
|
|
3
|
+
import { updateProjectConfigOverrides } from "../project-config.js";
|
|
4
|
+
import { isValidProjectName } from "../utils.js";
|
|
5
|
+
import { parseProjectArg, warnIfUnregistered } from "./config-shared.js";
|
|
6
|
+
// ── Finding sensitivity config ────────────────────────────────────────────────
|
|
7
|
+
export const FINDING_SENSITIVITY_CONFIG = {
|
|
8
|
+
minimal: {
|
|
9
|
+
sessionCap: 0,
|
|
10
|
+
proactivityFindings: "low",
|
|
11
|
+
agentInstruction: "Only save findings when the user explicitly asks you to remember something.",
|
|
12
|
+
},
|
|
13
|
+
conservative: {
|
|
14
|
+
sessionCap: 3,
|
|
15
|
+
proactivityFindings: "medium",
|
|
16
|
+
agentInstruction: "Save decisions and pitfalls only — skip patterns and observations.",
|
|
17
|
+
},
|
|
18
|
+
balanced: {
|
|
19
|
+
sessionCap: 10,
|
|
20
|
+
proactivityFindings: "high",
|
|
21
|
+
agentInstruction: "Save non-obvious patterns, decisions, pitfalls, and bugs worth remembering next session.",
|
|
22
|
+
},
|
|
23
|
+
aggressive: {
|
|
24
|
+
sessionCap: 20,
|
|
25
|
+
proactivityFindings: "high",
|
|
26
|
+
agentInstruction: "Save everything worth remembering — err on the side of capturing.",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
function handleWorkflowField(args, opts) {
|
|
30
|
+
const phrenPath = getPhrenPath();
|
|
31
|
+
const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
|
|
32
|
+
const action = filteredArgs[0];
|
|
33
|
+
if (!action || action === "get") {
|
|
34
|
+
if (projectArg) {
|
|
35
|
+
if (!isValidProjectName(projectArg)) {
|
|
36
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
40
|
+
const value = opts.getProjectValue(resolved);
|
|
41
|
+
console.log(JSON.stringify(opts.formatProjectOutput(projectArg, value), null, 2));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log(JSON.stringify(opts.getSnapshot(phrenPath), null, 2));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const applyValue = (value) => {
|
|
48
|
+
if (projectArg) {
|
|
49
|
+
if (!isValidProjectName(projectArg)) {
|
|
50
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
warnIfUnregistered(phrenPath, projectArg);
|
|
54
|
+
updateProjectConfigOverrides(phrenPath, projectArg, (current) => ({ ...current, [opts.projectOverrideKey]: value }));
|
|
55
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
56
|
+
const eff = opts.getProjectValue(resolved);
|
|
57
|
+
console.log(JSON.stringify(opts.formatProjectOutput(projectArg, eff), null, 2));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const result = updateWorkflowPolicy(phrenPath, { [opts.workflowPatchKey]: value });
|
|
61
|
+
if (!result.ok) {
|
|
62
|
+
console.error(result.error);
|
|
63
|
+
if (result.code === "PERMISSION_DENIED")
|
|
64
|
+
process.exit(1);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
console.log(JSON.stringify(opts.getSnapshot(phrenPath), null, 2));
|
|
68
|
+
};
|
|
69
|
+
if (action === "set") {
|
|
70
|
+
const value = opts.normalize(filteredArgs[1]);
|
|
71
|
+
if (!value) {
|
|
72
|
+
console.error(`Usage: phren config ${opts.fieldName} set [${opts.validValues.join("|")}]`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
return applyValue(value);
|
|
76
|
+
}
|
|
77
|
+
const value = opts.normalize(action);
|
|
78
|
+
if (value)
|
|
79
|
+
return applyValue(value);
|
|
80
|
+
console.error(`Usage: phren config ${opts.fieldName} [--project <name>] [get|set <value>|<value>] — values: ${opts.validValues.join("|")}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
function normalizeFromList(raw, validValues) {
|
|
84
|
+
if (!raw)
|
|
85
|
+
return null;
|
|
86
|
+
const lower = raw.trim().toLowerCase();
|
|
87
|
+
return validValues.includes(lower) ? lower : null;
|
|
88
|
+
}
|
|
89
|
+
export function handleConfigTaskMode(args) {
|
|
90
|
+
handleWorkflowField(args, {
|
|
91
|
+
fieldName: "task-mode",
|
|
92
|
+
validValues: VALID_TASK_MODES,
|
|
93
|
+
normalize: (raw) => normalizeFromList(raw, VALID_TASK_MODES),
|
|
94
|
+
getSnapshot: (phrenPath) => ({ taskMode: getWorkflowPolicy(phrenPath).taskMode }),
|
|
95
|
+
getProjectValue: (resolved) => resolved.taskMode,
|
|
96
|
+
formatProjectOutput: (proj, value) => ({ _project: proj, taskMode: value }),
|
|
97
|
+
workflowPatchKey: "taskMode",
|
|
98
|
+
projectOverrideKey: "taskMode",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export function handleConfigFindingSensitivity(args) {
|
|
102
|
+
handleWorkflowField(args, {
|
|
103
|
+
fieldName: "finding-sensitivity",
|
|
104
|
+
validValues: VALID_FINDING_SENSITIVITY,
|
|
105
|
+
normalize: (raw) => normalizeFromList(raw, VALID_FINDING_SENSITIVITY),
|
|
106
|
+
getSnapshot: (phrenPath) => {
|
|
107
|
+
const policy = getWorkflowPolicy(phrenPath);
|
|
108
|
+
const level = policy.findingSensitivity;
|
|
109
|
+
return { level, ...FINDING_SENSITIVITY_CONFIG[level] };
|
|
110
|
+
},
|
|
111
|
+
getProjectValue: (resolved) => resolved.findingSensitivity,
|
|
112
|
+
formatProjectOutput: (proj, value) => ({ _project: proj, level: value, ...FINDING_SENSITIVITY_CONFIG[value] }),
|
|
113
|
+
workflowPatchKey: "findingSensitivity",
|
|
114
|
+
projectOverrideKey: "findingSensitivity",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// ── Index policy ─────────────────────────────────────────────────────────────
|
|
118
|
+
export async function handleIndexPolicy(args) {
|
|
119
|
+
if (!args.length || args[0] === "get") {
|
|
120
|
+
console.log(JSON.stringify(getIndexPolicy(getPhrenPath()), null, 2));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (args[0] === "set") {
|
|
124
|
+
const patch = {};
|
|
125
|
+
for (const arg of args.slice(1)) {
|
|
126
|
+
if (!arg.startsWith("--"))
|
|
127
|
+
continue;
|
|
128
|
+
const [k, v] = arg.slice(2).split("=");
|
|
129
|
+
if (!k || v === undefined)
|
|
130
|
+
continue;
|
|
131
|
+
if (k === "include") {
|
|
132
|
+
patch.includeGlobs = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
133
|
+
}
|
|
134
|
+
else if (k === "exclude") {
|
|
135
|
+
patch.excludeGlobs = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
136
|
+
}
|
|
137
|
+
else if (k === "includeHidden") {
|
|
138
|
+
patch.includeHidden = /^(1|true|yes|on)$/i.test(v);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const result = updateIndexPolicy(getPhrenPath(), patch);
|
|
142
|
+
if (!result.ok) {
|
|
143
|
+
console.error(result.error);
|
|
144
|
+
if (result.code === "PERMISSION_DENIED")
|
|
145
|
+
process.exit(1);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
console.error("Usage: phren index-policy [get|set --include=**/*.md,**/skills/**/*.md,.claude/skills/**/*.md --exclude=**/node_modules/**,**/.git/** --includeHidden=false]");
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
// ── Memory policy ────────────────────────────────────────────────────────────
|
|
155
|
+
export async function handleRetentionPolicy(args) {
|
|
156
|
+
const phrenPath = getPhrenPath();
|
|
157
|
+
const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
|
|
158
|
+
if (!filteredArgs.length || filteredArgs[0] === "get") {
|
|
159
|
+
if (projectArg) {
|
|
160
|
+
if (!isValidProjectName(projectArg)) {
|
|
161
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
165
|
+
console.log(JSON.stringify({ _project: projectArg, ...resolved.retentionPolicy }, null, 2));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.log(JSON.stringify(getRetentionPolicy(phrenPath), null, 2));
|
|
169
|
+
const conflictOn = process.env.PHREN_FEATURE_SEMANTIC_CONFLICT === "1";
|
|
170
|
+
process.stderr.write(`\nDedup: free Jaccard similarity scan on every add_finding (no API key needed).\n`);
|
|
171
|
+
process.stderr.write(` Near-matches (30–55% overlap) are returned in the response for the agent to decide.\n`);
|
|
172
|
+
if (conflictOn) {
|
|
173
|
+
process.stderr.write(`\nConflict detection (PHREN_FEATURE_SEMANTIC_CONFLICT=1): active.\n`);
|
|
174
|
+
process.stderr.write(` Uses an LLM for batch conflict checks. See: phren config llm\n`);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
process.stderr.write(`\nConflict detection: disabled (set PHREN_FEATURE_SEMANTIC_CONFLICT=1 to enable for batch ops).\n`);
|
|
178
|
+
process.stderr.write(` LLM needed only for batch operations (phren maintain consolidate/extract).\n`);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (filteredArgs[0] === "set") {
|
|
183
|
+
if (projectArg) {
|
|
184
|
+
if (!isValidProjectName(projectArg)) {
|
|
185
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
warnIfUnregistered(phrenPath, projectArg);
|
|
189
|
+
updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
|
|
190
|
+
const existingRetention = current.retentionPolicy ?? {};
|
|
191
|
+
const retentionPatch = { ...existingRetention };
|
|
192
|
+
for (const arg of filteredArgs.slice(1)) {
|
|
193
|
+
if (!arg.startsWith("--"))
|
|
194
|
+
continue;
|
|
195
|
+
const [k, v] = arg.slice(2).split("=");
|
|
196
|
+
if (!k || v === undefined)
|
|
197
|
+
continue;
|
|
198
|
+
const num = Number(v);
|
|
199
|
+
const value = Number.isNaN(num) ? v : num;
|
|
200
|
+
if (k.startsWith("decay.")) {
|
|
201
|
+
retentionPatch.decay = { ...(retentionPatch.decay ?? {}) };
|
|
202
|
+
retentionPatch.decay[k.slice("decay.".length)] = value;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
retentionPatch[k] = value;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { ...current, retentionPolicy: retentionPatch };
|
|
209
|
+
});
|
|
210
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
211
|
+
console.log(JSON.stringify({ _project: projectArg, ...resolved.retentionPolicy }, null, 2));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const patch = {};
|
|
215
|
+
for (const arg of filteredArgs.slice(1)) {
|
|
216
|
+
if (!arg.startsWith("--"))
|
|
217
|
+
continue;
|
|
218
|
+
const [k, v] = arg.slice(2).split("=");
|
|
219
|
+
if (!k || v === undefined)
|
|
220
|
+
continue;
|
|
221
|
+
const num = Number(v);
|
|
222
|
+
const value = Number.isNaN(num) ? v : num;
|
|
223
|
+
if (k.startsWith("decay.")) {
|
|
224
|
+
patch.decay = patch.decay || {};
|
|
225
|
+
patch.decay[k.slice("decay.".length)] = value;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
patch[k] = value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const result = updateRetentionPolicy(phrenPath, patch);
|
|
232
|
+
if (!result.ok) {
|
|
233
|
+
console.error(result.error);
|
|
234
|
+
if (result.code === "PERMISSION_DENIED")
|
|
235
|
+
process.exit(1);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
console.error("Usage: phren config policy [--project <name>] [get|set --ttlDays=120 --retentionDays=365 --autoAcceptThreshold=0.75 --minInjectConfidence=0.35 --decay.d30=1 --decay.d60=0.85 --decay.d90=0.65 --decay.d120=0.45]");
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
// ── Memory workflow ──────────────────────────────────────────────────────────
|
|
245
|
+
export async function handleWorkflowPolicy(args) {
|
|
246
|
+
const phrenPath = getPhrenPath();
|
|
247
|
+
const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
|
|
248
|
+
if (!filteredArgs.length || filteredArgs[0] === "get") {
|
|
249
|
+
if (projectArg) {
|
|
250
|
+
if (!isValidProjectName(projectArg)) {
|
|
251
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
255
|
+
console.log(JSON.stringify({ _project: projectArg, ...resolved.workflowPolicy }, null, 2));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
console.log(JSON.stringify(getWorkflowPolicy(phrenPath), null, 2));
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (filteredArgs[0] === "set") {
|
|
262
|
+
if (projectArg) {
|
|
263
|
+
if (!isValidProjectName(projectArg)) {
|
|
264
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
warnIfUnregistered(phrenPath, projectArg);
|
|
268
|
+
updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
|
|
269
|
+
const nextConfig = { ...current };
|
|
270
|
+
const existingWorkflow = current.workflowPolicy ?? {};
|
|
271
|
+
const workflowPatch = { ...existingWorkflow };
|
|
272
|
+
for (const arg of filteredArgs.slice(1)) {
|
|
273
|
+
if (!arg.startsWith("--"))
|
|
274
|
+
continue;
|
|
275
|
+
const [k, v] = arg.slice(2).split("=");
|
|
276
|
+
if (!k || v === undefined)
|
|
277
|
+
continue;
|
|
278
|
+
if (k === "riskySections") {
|
|
279
|
+
workflowPatch.riskySections = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
280
|
+
}
|
|
281
|
+
else if (k === "taskMode") {
|
|
282
|
+
nextConfig.taskMode = v;
|
|
283
|
+
}
|
|
284
|
+
else if (k === "findingSensitivity") {
|
|
285
|
+
nextConfig.findingSensitivity = v;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
const num = Number(v);
|
|
289
|
+
workflowPatch[k] = Number.isNaN(num) ? v : num;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (Object.keys(workflowPatch).length > 0 || existingWorkflow !== current.workflowPolicy) {
|
|
293
|
+
nextConfig.workflowPolicy = workflowPatch;
|
|
294
|
+
}
|
|
295
|
+
return nextConfig;
|
|
296
|
+
});
|
|
297
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
298
|
+
console.log(JSON.stringify({ _project: projectArg, ...resolved.workflowPolicy }, null, 2));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const patch = {};
|
|
302
|
+
for (const arg of filteredArgs.slice(1)) {
|
|
303
|
+
if (!arg.startsWith("--"))
|
|
304
|
+
continue;
|
|
305
|
+
const [k, v] = arg.slice(2).split("=");
|
|
306
|
+
if (!k || v === undefined)
|
|
307
|
+
continue;
|
|
308
|
+
if (k === "riskySections") {
|
|
309
|
+
patch.riskySections = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const num = Number(v);
|
|
313
|
+
patch[k] = Number.isNaN(num) ? v : num;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const result = updateWorkflowPolicy(phrenPath, patch);
|
|
317
|
+
if (!result.ok) {
|
|
318
|
+
console.log(result.error);
|
|
319
|
+
if (result.code === "PERMISSION_DENIED")
|
|
320
|
+
process.exit(1);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
console.error("Usage: phren config workflow [--project <name>] [get|set --lowConfidenceThreshold=0.7 --riskySections=Stale,Conflicts --taskMode=manual]");
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function buildProactivitySnapshot(phrenPath: string): {
|
|
2
|
+
path: string;
|
|
3
|
+
configured: {
|
|
4
|
+
proactivity: "high" | "medium" | "low" | null;
|
|
5
|
+
proactivityFindings: "high" | "medium" | "low" | null;
|
|
6
|
+
proactivityTask: "high" | "medium" | "low" | null;
|
|
7
|
+
};
|
|
8
|
+
effective: {
|
|
9
|
+
proactivity: "high" | "medium" | "low";
|
|
10
|
+
proactivityFindings: "high" | "medium" | "low";
|
|
11
|
+
proactivityTask: "high" | "medium" | "low";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare function handleConfigProactivity(subcommand: "proactivity" | "proactivity.findings" | "proactivity.tasks", args: string[]): void;
|
|
15
|
+
export declare function handleConfigProjectOwnership(args: string[]): void;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { getPhrenPath } from "../shared.js";
|
|
2
|
+
import { installPreferencesFile } from "../phren-paths.js";
|
|
3
|
+
import { mergeConfig } from "../shared/governance.js";
|
|
4
|
+
import { governanceInstallPreferencesFile, readInstallPreferences, readGovernanceInstallPreferences, writeInstallPreferences, writeGovernanceInstallPreferences, } from "../init/preferences.js";
|
|
5
|
+
import { PROACTIVITY_LEVELS, getProactivityLevel, getProactivityLevelForTask, getProactivityLevelForFindings, } from "../proactivity.js";
|
|
6
|
+
import { PROJECT_OWNERSHIP_MODES, getProjectOwnershipDefault, parseProjectOwnershipMode, updateProjectConfigOverrides, } from "../project-config.js";
|
|
7
|
+
import { isValidProjectName } from "../utils.js";
|
|
8
|
+
import { parseProjectArg, warnIfUnregistered } from "./config-shared.js";
|
|
9
|
+
export function buildProactivitySnapshot(phrenPath) {
|
|
10
|
+
const prefs = readGovernanceInstallPreferences(phrenPath);
|
|
11
|
+
return {
|
|
12
|
+
path: governanceInstallPreferencesFile(phrenPath),
|
|
13
|
+
configured: {
|
|
14
|
+
proactivity: prefs.proactivity ?? null,
|
|
15
|
+
proactivityFindings: prefs.proactivityFindings ?? null,
|
|
16
|
+
proactivityTask: prefs.proactivityTask ?? null,
|
|
17
|
+
},
|
|
18
|
+
effective: {
|
|
19
|
+
proactivity: getProactivityLevel(phrenPath),
|
|
20
|
+
proactivityFindings: getProactivityLevelForFindings(phrenPath),
|
|
21
|
+
proactivityTask: getProactivityLevelForTask(phrenPath),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function normalizeProactivityLevel(raw) {
|
|
26
|
+
if (!raw)
|
|
27
|
+
return undefined;
|
|
28
|
+
const normalized = raw.trim().toLowerCase();
|
|
29
|
+
return PROACTIVITY_LEVELS.includes(normalized)
|
|
30
|
+
? normalized
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
33
|
+
function printProactivityUsage(subcommand) {
|
|
34
|
+
console.error(`Usage: phren config ${subcommand} [high|medium|low]`);
|
|
35
|
+
}
|
|
36
|
+
export function handleConfigProactivity(subcommand, args) {
|
|
37
|
+
const phrenPath = getPhrenPath();
|
|
38
|
+
const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
|
|
39
|
+
const value = filteredArgs[0];
|
|
40
|
+
if (value === undefined) {
|
|
41
|
+
if (projectArg) {
|
|
42
|
+
if (!isValidProjectName(projectArg)) {
|
|
43
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
47
|
+
console.log(JSON.stringify({
|
|
48
|
+
_project: projectArg,
|
|
49
|
+
base: resolved.proactivity.base ?? null,
|
|
50
|
+
findings: resolved.proactivity.findings ?? null,
|
|
51
|
+
tasks: resolved.proactivity.tasks ?? null,
|
|
52
|
+
}, null, 2));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(JSON.stringify(buildProactivitySnapshot(phrenPath), null, 2));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (filteredArgs.length !== 1) {
|
|
59
|
+
printProactivityUsage(subcommand);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const level = normalizeProactivityLevel(value);
|
|
63
|
+
if (!level) {
|
|
64
|
+
printProactivityUsage(subcommand);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
if (projectArg) {
|
|
68
|
+
if (!isValidProjectName(projectArg)) {
|
|
69
|
+
console.error(`Invalid project name: "${projectArg}"`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
warnIfUnregistered(phrenPath, projectArg);
|
|
73
|
+
const key = subcommand === "proactivity" ? "proactivity"
|
|
74
|
+
: subcommand === "proactivity.findings" ? "proactivityFindings"
|
|
75
|
+
: "proactivityTask";
|
|
76
|
+
updateProjectConfigOverrides(phrenPath, projectArg, (current) => ({ ...current, [key]: level }));
|
|
77
|
+
const resolved = mergeConfig(phrenPath, projectArg);
|
|
78
|
+
console.log(JSON.stringify({
|
|
79
|
+
_project: projectArg,
|
|
80
|
+
base: resolved.proactivity.base ?? null,
|
|
81
|
+
findings: resolved.proactivity.findings ?? null,
|
|
82
|
+
tasks: resolved.proactivity.tasks ?? null,
|
|
83
|
+
}, null, 2));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
switch (subcommand) {
|
|
87
|
+
case "proactivity":
|
|
88
|
+
writeGovernanceInstallPreferences(phrenPath, { proactivity: level });
|
|
89
|
+
break;
|
|
90
|
+
case "proactivity.findings":
|
|
91
|
+
writeGovernanceInstallPreferences(phrenPath, { proactivityFindings: level });
|
|
92
|
+
break;
|
|
93
|
+
case "proactivity.tasks":
|
|
94
|
+
writeGovernanceInstallPreferences(phrenPath, { proactivityTask: level });
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
console.log(JSON.stringify(buildProactivitySnapshot(phrenPath), null, 2));
|
|
98
|
+
}
|
|
99
|
+
function projectOwnershipConfigSnapshot(phrenPath) {
|
|
100
|
+
const prefs = readInstallPreferences(phrenPath);
|
|
101
|
+
return {
|
|
102
|
+
path: installPreferencesFile(phrenPath),
|
|
103
|
+
configured: {
|
|
104
|
+
projectOwnershipDefault: prefs.projectOwnershipDefault ?? null,
|
|
105
|
+
},
|
|
106
|
+
effective: {
|
|
107
|
+
projectOwnershipDefault: getProjectOwnershipDefault(phrenPath),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function handleConfigProjectOwnership(args) {
|
|
112
|
+
const phrenPath = getPhrenPath();
|
|
113
|
+
const value = args[0];
|
|
114
|
+
if (value === undefined) {
|
|
115
|
+
console.log(JSON.stringify(projectOwnershipConfigSnapshot(phrenPath), null, 2));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (args.length !== 1) {
|
|
119
|
+
console.error(`Usage: phren config project-ownership [${PROJECT_OWNERSHIP_MODES.join("|")}]`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
const ownership = parseProjectOwnershipMode(value);
|
|
123
|
+
if (!ownership) {
|
|
124
|
+
console.error(`Usage: phren config project-ownership [${PROJECT_OWNERSHIP_MODES.join("|")}]`);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
writeInstallPreferences(phrenPath, { projectOwnershipDefault: ownership });
|
|
128
|
+
console.log(JSON.stringify(projectOwnershipConfigSnapshot(phrenPath), null, 2));
|
|
129
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function parseProjectArg(args: string[]): {
|
|
2
|
+
project?: string;
|
|
3
|
+
rest: string[];
|
|
4
|
+
};
|
|
5
|
+
export declare function checkProjectInProfile(phrenPath: string, project: string): string | null;
|
|
6
|
+
export declare function warnIfUnregistered(phrenPath: string, project: string): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { listProfiles } from "../data/access.js";
|
|
2
|
+
// ── Shared helpers used across the config sub-modules ──────────────────────────
|
|
3
|
+
export function parseProjectArg(args) {
|
|
4
|
+
const project = args.find((a) => a.startsWith("--project="))?.slice("--project=".length)
|
|
5
|
+
?? (args.indexOf("--project") !== -1 ? args[args.indexOf("--project") + 1] : undefined);
|
|
6
|
+
const rest = args.filter((a, i) => a !== "--project" && !a.startsWith("--project=") && args[i - 1] !== "--project");
|
|
7
|
+
return { project, rest };
|
|
8
|
+
}
|
|
9
|
+
export function checkProjectInProfile(phrenPath, project) {
|
|
10
|
+
const profiles = listProfiles(phrenPath);
|
|
11
|
+
if (profiles.ok) {
|
|
12
|
+
const registered = profiles.data.some((entry) => entry.projects.includes(project));
|
|
13
|
+
if (!registered) {
|
|
14
|
+
return `Warning: Project '${project}' not found in active profile. Run 'phren add /path/to/${project}' first.\n Config was written to ${phrenPath}/${project}/phren.project.yaml but won't be used until the project is registered.`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export function warnIfUnregistered(phrenPath, project) {
|
|
20
|
+
const warning = checkProjectInProfile(phrenPath, project);
|
|
21
|
+
if (warning)
|
|
22
|
+
console.error(warning);
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleConfigSynonyms(args: string[]): void;
|