@phren/cli 0.1.32 → 0.1.34
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 +135 -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 +63 -0
- package/dist/cli/config.d.ts +6 -24
- package/dist/cli/config.js +13 -670
- package/dist/cli/team.js +26 -13
- package/dist/content/dedup.js +25 -3
- package/dist/content/learning.js +10 -16
- 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/governance/scores.js +26 -45
- package/dist/index.js +32 -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/index.d.ts +2 -0
- package/dist/shared/index.js +90 -17
- package/dist/shared/retrieval.js +25 -6
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +1 -1
- package/dist/telemetry.js +4 -1
- package/dist/tools/config.js +39 -2
- package/dist/tools/finding.d.ts +1 -0
- package/dist/tools/finding.js +40 -2
- package/dist/tools/search.js +28 -1
- 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 +3 -3
- 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/cli/team.js
CHANGED
|
@@ -28,23 +28,27 @@ async function handleTeamInit(args) {
|
|
|
28
28
|
const description = getOptionValue(args, "--description");
|
|
29
29
|
if (!name) {
|
|
30
30
|
console.error("Usage: phren team init <name> [--remote <url>] [--description <text>]");
|
|
31
|
-
process.
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
32
33
|
}
|
|
33
34
|
if (!isValidProjectName(name)) {
|
|
34
35
|
console.error(`Invalid store name: "${name}". Use lowercase letters, numbers, hyphens.`);
|
|
35
|
-
process.
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
return;
|
|
36
38
|
}
|
|
37
39
|
// Check if store already exists
|
|
38
40
|
const existing = findStoreByName(phrenPath, name);
|
|
39
41
|
if (existing) {
|
|
40
42
|
console.error(`Store "${name}" already exists at ${existing.path}`);
|
|
41
|
-
process.
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
return;
|
|
42
45
|
}
|
|
43
46
|
const storesDir = path.join(path.dirname(phrenPath), ".phren-stores");
|
|
44
47
|
const storePath = path.join(storesDir, name);
|
|
45
48
|
if (fs.existsSync(storePath)) {
|
|
46
49
|
console.error(`Directory already exists: ${storePath}`);
|
|
47
|
-
process.
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
48
52
|
}
|
|
49
53
|
// Create the team store directory
|
|
50
54
|
fs.mkdirSync(storePath, { recursive: true });
|
|
@@ -135,24 +139,28 @@ async function handleTeamJoin(args) {
|
|
|
135
139
|
const nameOverride = getOptionValue(args, "--name");
|
|
136
140
|
if (!remote) {
|
|
137
141
|
console.error("Usage: phren team join <git-url> [--name <name>]");
|
|
138
|
-
process.
|
|
142
|
+
process.exitCode = 1;
|
|
143
|
+
return;
|
|
139
144
|
}
|
|
140
145
|
const storesDir = path.join(path.dirname(phrenPath), ".phren-stores");
|
|
141
146
|
// Infer name from URL if not provided
|
|
142
147
|
const inferredName = nameOverride || path.basename(remote, ".git").toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
143
148
|
if (!isValidProjectName(inferredName)) {
|
|
144
149
|
console.error(`Invalid store name: "${inferredName}". Use --name to specify a valid name.`);
|
|
145
|
-
process.
|
|
150
|
+
process.exitCode = 1;
|
|
151
|
+
return;
|
|
146
152
|
}
|
|
147
153
|
const existing = findStoreByName(phrenPath, inferredName);
|
|
148
154
|
if (existing) {
|
|
149
155
|
console.error(`Store "${inferredName}" already exists at ${existing.path}`);
|
|
150
|
-
process.
|
|
156
|
+
process.exitCode = 1;
|
|
157
|
+
return;
|
|
151
158
|
}
|
|
152
159
|
const storePath = path.join(storesDir, inferredName);
|
|
153
160
|
if (fs.existsSync(storePath)) {
|
|
154
161
|
console.error(`Directory already exists: ${storePath}`);
|
|
155
|
-
process.
|
|
162
|
+
process.exitCode = 1;
|
|
163
|
+
return;
|
|
156
164
|
}
|
|
157
165
|
// Clone the remote
|
|
158
166
|
console.log(`Cloning ${remote}...`);
|
|
@@ -190,20 +198,24 @@ async function handleTeamAddProject(args) {
|
|
|
190
198
|
const projectName = positional[1];
|
|
191
199
|
if (!storeName || !projectName) {
|
|
192
200
|
console.error("Usage: phren team add-project <store-name> <project-name>");
|
|
193
|
-
process.
|
|
201
|
+
process.exitCode = 1;
|
|
202
|
+
return;
|
|
194
203
|
}
|
|
195
204
|
if (!isValidProjectName(projectName)) {
|
|
196
205
|
console.error(`Invalid project name: "${projectName}"`);
|
|
197
|
-
process.
|
|
206
|
+
process.exitCode = 1;
|
|
207
|
+
return;
|
|
198
208
|
}
|
|
199
209
|
const store = findStoreByName(phrenPath, storeName);
|
|
200
210
|
if (!store) {
|
|
201
211
|
console.error(`Store "${storeName}" not found. Run 'phren store list' to see available stores.`);
|
|
202
|
-
process.
|
|
212
|
+
process.exitCode = 1;
|
|
213
|
+
return;
|
|
203
214
|
}
|
|
204
215
|
if (store.role === "readonly") {
|
|
205
216
|
console.error(`Store "${storeName}" is read-only. Cannot add projects.`);
|
|
206
|
-
process.
|
|
217
|
+
process.exitCode = 1;
|
|
218
|
+
return;
|
|
207
219
|
}
|
|
208
220
|
// Create project directory in the store
|
|
209
221
|
const projectDir = path.join(store.path, projectName);
|
|
@@ -287,7 +299,8 @@ export async function handleTeamNamespace(args) {
|
|
|
287
299
|
`);
|
|
288
300
|
if (subcommand) {
|
|
289
301
|
console.error(`Unknown subcommand: ${subcommand}`);
|
|
290
|
-
process.
|
|
302
|
+
process.exitCode = 1;
|
|
303
|
+
return;
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
306
|
}
|
package/dist/content/dedup.js
CHANGED
|
@@ -284,6 +284,24 @@ function learningPolarity(text) {
|
|
|
284
284
|
return "negative";
|
|
285
285
|
return "neutral";
|
|
286
286
|
}
|
|
287
|
+
// Minimum topical overlap (Jaccard over substantive tokens, with observation tags
|
|
288
|
+
// and metadata stripped) required before two findings that share an entity and have
|
|
289
|
+
// opposing polarity are treated as a contradiction. The bare "one shared entity +
|
|
290
|
+
// opposite polarity" rule fires on unrelated findings that merely mention the same
|
|
291
|
+
// tool or word (e.g. a git-workflow decision and a security decision that both say
|
|
292
|
+
// "GitHub"); requiring genuine subject-matter overlap removes that false-positive
|
|
293
|
+
// class while keeping real same-topic contradictions.
|
|
294
|
+
const CONFLICT_MIN_TOPIC_OVERLAP = 0.12;
|
|
295
|
+
/** Strip observation tags like [decision] so a shared tag is not counted as shared topic. */
|
|
296
|
+
function stripObservationTags(text) {
|
|
297
|
+
return text.replace(/\[[a-zA-Z_-]+\]/g, " ");
|
|
298
|
+
}
|
|
299
|
+
/** Jaccard overlap of the substantive tokens of two findings (tags + metadata removed). */
|
|
300
|
+
function topicalOverlap(a, b) {
|
|
301
|
+
const ta = jaccardTokenize(stripObservationTags(stripMetadata(a)));
|
|
302
|
+
const tb = jaccardTokenize(stripObservationTags(stripMetadata(b)));
|
|
303
|
+
return jaccardSimilarity(ta, tb);
|
|
304
|
+
}
|
|
287
305
|
/** Returns existing learning lines that appear to conflict with newFinding. */
|
|
288
306
|
export function detectConflicts(newFinding, existingLines, dynamicEntities) {
|
|
289
307
|
const newEntities = extractProseEntities(newFinding, dynamicEntities);
|
|
@@ -301,9 +319,13 @@ export function detectConflicts(newFinding, existingLines, dynamicEntities) {
|
|
|
301
319
|
if (shared.length === 0)
|
|
302
320
|
continue;
|
|
303
321
|
const linePol = learningPolarity(line);
|
|
304
|
-
if (linePol
|
|
305
|
-
|
|
306
|
-
|
|
322
|
+
if (linePol === "neutral" || linePol === newPol)
|
|
323
|
+
continue;
|
|
324
|
+
// Require genuine topical overlap, not just one incidental shared entity, before
|
|
325
|
+
// flagging. Unrelated findings that happen to share a tool name fall below this bar.
|
|
326
|
+
if (topicalOverlap(newFinding, line) < CONFLICT_MIN_TOPIC_OVERLAP)
|
|
327
|
+
continue;
|
|
328
|
+
conflicts.push(line);
|
|
307
329
|
}
|
|
308
330
|
return conflicts;
|
|
309
331
|
}
|
package/dist/content/learning.js
CHANGED
|
@@ -6,7 +6,7 @@ import { normalizeMemoryScope } from "../shared.js";
|
|
|
6
6
|
import { withFileLock } from "../shared/governance.js";
|
|
7
7
|
import { isValidProjectName, safeProjectPath } from "../utils.js";
|
|
8
8
|
import { buildCitationComment, buildScopeComment, buildSourceComment, getHeadCommit, getRepoRoot, inferCitationLocation, } from "./citation.js";
|
|
9
|
-
import { isDuplicateFinding, scanForSecrets, normalizeObservationTags, resolveCoref
|
|
9
|
+
import { isDuplicateFinding, scanForSecrets, normalizeObservationTags, resolveCoref } from "./dedup.js";
|
|
10
10
|
import { validateFindingsFormat, validateFinding } from "./validate.js";
|
|
11
11
|
import { countActiveFindings, autoArchiveToReference } from "./archive.js";
|
|
12
12
|
import { resolveAutoFindingTaskItem, resolveFindingTaskReference, } from "../finding/context.js";
|
|
@@ -81,7 +81,7 @@ export function autoDetectFindingType(text) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
function prepareFinding(opts) {
|
|
84
|
-
const { finding: learning, project, fullHistory, extraAnnotations, citationInput, scope, provenance, nowIso, inferredRepo, headCommit
|
|
84
|
+
const { finding: learning, project, fullHistory, extraAnnotations, citationInput, scope, provenance, nowIso, inferredRepo, headCommit } = opts;
|
|
85
85
|
const secretType = scanForSecrets(learning);
|
|
86
86
|
if (secretType) {
|
|
87
87
|
return { status: "rejected", reason: `Contains ${secretType}` };
|
|
@@ -113,20 +113,14 @@ function prepareFinding(opts) {
|
|
|
113
113
|
if (isDuplicateFinding(fullHistory, bullet)) {
|
|
114
114
|
return { status: "duplicate" };
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
status_reason: "conflicts_with",
|
|
125
|
-
status_ref: snippet,
|
|
126
|
-
};
|
|
127
|
-
bullet += ` <!-- conflicts_with: "${snippet}" --> <!-- phren:contradicts "${snippet}" -->`;
|
|
128
|
-
debugLog(`add_finding: conflict detected for "${project}": ${snippet}`);
|
|
129
|
-
}
|
|
116
|
+
// NOTE: heuristic contradiction detection is intentionally NOT done here. The lexical
|
|
117
|
+
// heuristic (shared entity + opposing polarity) produces false positives, so it must
|
|
118
|
+
// never silently mutate the stored finding's status. Instead the MCP add_finding tool
|
|
119
|
+
// surfaces heuristic conflict *candidates* (via findConflictCandidates) in its response
|
|
120
|
+
// so the calling agent — an LLM already in the loop with full context — can judge them,
|
|
121
|
+
// exactly as it already does for potential duplicates. A hard "contradicted" status is
|
|
122
|
+
// reserved for the LLM-confirmed path (checkSemanticConflicts) and explicit user
|
|
123
|
+
// resolution via resolve_contradiction.
|
|
130
124
|
if (extraAnnotations && extraAnnotations.length > 0) {
|
|
131
125
|
const lifecycleFromExtra = parseFindingLifecycle(`- lifecycle ${extraAnnotations.join(" ")}`);
|
|
132
126
|
if (lifecycleFromExtra.status !== "active" ||
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Graph node id for a finding, derived from its score key (mirrors data.ts stableId("finding", …)). */
|
|
2
|
+
export declare function findingStableId(scoreKey: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Graph node id for a single FINDINGS.md bullet line, or null if the line is
|
|
5
|
+
* not a node-bearing finding. Covers tagged (`- [tag] text`) and plain
|
|
6
|
+
* (`- text`) bullets; heading-based findings are intentionally not matched
|
|
7
|
+
* here (they need multi-line context and are rare).
|
|
8
|
+
*/
|
|
9
|
+
export declare function findingNodeIdForLine(project: string, line: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Pick the graph node id of the finding bullet in `content` that best matches
|
|
12
|
+
* `query` (by query-term overlap). Returns null when no bullet shares a query
|
|
13
|
+
* term, so callers can fall back to the project node.
|
|
14
|
+
*/
|
|
15
|
+
export declare function bestFindingNodeId(project: string, content: string, query: string): string | null;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { entryScoreKey } from "./governance/scores.js";
|
|
3
|
+
import { FINDINGS_FILENAME } from "./data/access.js";
|
|
4
|
+
// Bullet-finding patterns — must stay in lockstep with the graph builder
|
|
5
|
+
// (ui/data.ts) so computed node ids match the rendered finding nodes.
|
|
6
|
+
const TAGGED_BULLET = /^-\s+\[([a-z_-]+)\]\s+(.+?)(?:\s*<!--.*-->)?$/;
|
|
7
|
+
const PLAIN_BULLET = /^-\s+(.+?)(?:\s*<!--.*-->)?$/;
|
|
8
|
+
const MIN_PLAIN_LENGTH = 10;
|
|
9
|
+
/** Graph node id for a finding, derived from its score key (mirrors data.ts stableId("finding", …)). */
|
|
10
|
+
export function findingStableId(scoreKey) {
|
|
11
|
+
return `finding:${createHash("sha1").update(scoreKey).digest("hex").slice(0, 12)}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Graph node id for a single FINDINGS.md bullet line, or null if the line is
|
|
15
|
+
* not a node-bearing finding. Covers tagged (`- [tag] text`) and plain
|
|
16
|
+
* (`- text`) bullets; heading-based findings are intentionally not matched
|
|
17
|
+
* here (they need multi-line context and are rare).
|
|
18
|
+
*/
|
|
19
|
+
export function findingNodeIdForLine(project, line) {
|
|
20
|
+
const tagMatch = line.match(TAGGED_BULLET);
|
|
21
|
+
if (tagMatch) {
|
|
22
|
+
const tag = tagMatch[1];
|
|
23
|
+
const text = tagMatch[2].trim();
|
|
24
|
+
return findingStableId(entryScoreKey(project, FINDINGS_FILENAME, `[${tag}] ${text}`));
|
|
25
|
+
}
|
|
26
|
+
const plainMatch = line.match(PLAIN_BULLET);
|
|
27
|
+
if (plainMatch) {
|
|
28
|
+
const text = plainMatch[1].trim();
|
|
29
|
+
if (text.length < MIN_PLAIN_LENGTH)
|
|
30
|
+
return null;
|
|
31
|
+
return findingStableId(entryScoreKey(project, FINDINGS_FILENAME, text));
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pick the graph node id of the finding bullet in `content` that best matches
|
|
37
|
+
* `query` (by query-term overlap). Returns null when no bullet shares a query
|
|
38
|
+
* term, so callers can fall back to the project node.
|
|
39
|
+
*/
|
|
40
|
+
export function bestFindingNodeId(project, content, query) {
|
|
41
|
+
const terms = query.toLowerCase().split(/\s+/).filter((t) => t.length > 2);
|
|
42
|
+
if (terms.length === 0)
|
|
43
|
+
return null;
|
|
44
|
+
let best = null;
|
|
45
|
+
for (const line of content.split("\n")) {
|
|
46
|
+
const id = findingNodeIdForLine(project, line);
|
|
47
|
+
if (!id)
|
|
48
|
+
continue;
|
|
49
|
+
const lower = line.toLowerCase();
|
|
50
|
+
let score = 0;
|
|
51
|
+
for (const t of terms)
|
|
52
|
+
if (lower.includes(t))
|
|
53
|
+
score++;
|
|
54
|
+
if (score > 0 && (!best || score > best.score))
|
|
55
|
+
best = { id, score };
|
|
56
|
+
}
|
|
57
|
+
return best ? best.id : null;
|
|
58
|
+
}
|