@phren/cli 0.1.33 → 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/cli/config-proactivity.js +12 -6
- package/dist/cli/config-synonyms.js +7 -4
- package/dist/cli/team.js +26 -13
- package/dist/content/dedup.js +25 -3
- package/dist/content/learning.js +10 -16
- package/dist/generated/memory-ui-graph.browser.js +1 -1
- package/dist/governance/scores.js +26 -45
- package/dist/index.js +32 -1
- package/dist/memory-ui-graph.runtime.js +1 -1
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +90 -17
- package/dist/shared/retrieval.js +25 -6
- package/dist/telemetry.js +4 -1
- package/dist/tools/finding.d.ts +1 -0
- package/dist/tools/finding.js +40 -2
- package/package.json +3 -3
|
@@ -41,7 +41,8 @@ export function handleConfigProactivity(subcommand, args) {
|
|
|
41
41
|
if (projectArg) {
|
|
42
42
|
if (!isValidProjectName(projectArg)) {
|
|
43
43
|
console.error(`Invalid project name: "${projectArg}"`);
|
|
44
|
-
process.
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
return;
|
|
45
46
|
}
|
|
46
47
|
const resolved = mergeConfig(phrenPath, projectArg);
|
|
47
48
|
console.log(JSON.stringify({
|
|
@@ -57,17 +58,20 @@ export function handleConfigProactivity(subcommand, args) {
|
|
|
57
58
|
}
|
|
58
59
|
if (filteredArgs.length !== 1) {
|
|
59
60
|
printProactivityUsage(subcommand);
|
|
60
|
-
process.
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
return;
|
|
61
63
|
}
|
|
62
64
|
const level = normalizeProactivityLevel(value);
|
|
63
65
|
if (!level) {
|
|
64
66
|
printProactivityUsage(subcommand);
|
|
65
|
-
process.
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
return;
|
|
66
69
|
}
|
|
67
70
|
if (projectArg) {
|
|
68
71
|
if (!isValidProjectName(projectArg)) {
|
|
69
72
|
console.error(`Invalid project name: "${projectArg}"`);
|
|
70
|
-
process.
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
return;
|
|
71
75
|
}
|
|
72
76
|
warnIfUnregistered(phrenPath, projectArg);
|
|
73
77
|
const key = subcommand === "proactivity" ? "proactivity"
|
|
@@ -117,12 +121,14 @@ export function handleConfigProjectOwnership(args) {
|
|
|
117
121
|
}
|
|
118
122
|
if (args.length !== 1) {
|
|
119
123
|
console.error(`Usage: phren config project-ownership [${PROJECT_OWNERSHIP_MODES.join("|")}]`);
|
|
120
|
-
process.
|
|
124
|
+
process.exitCode = 1;
|
|
125
|
+
return;
|
|
121
126
|
}
|
|
122
127
|
const ownership = parseProjectOwnershipMode(value);
|
|
123
128
|
if (!ownership) {
|
|
124
129
|
console.error(`Usage: phren config project-ownership [${PROJECT_OWNERSHIP_MODES.join("|")}]`);
|
|
125
|
-
process.
|
|
130
|
+
process.exitCode = 1;
|
|
131
|
+
return;
|
|
126
132
|
}
|
|
127
133
|
writeInstallPreferences(phrenPath, { projectOwnershipDefault: ownership });
|
|
128
134
|
console.log(JSON.stringify(projectOwnershipConfigSnapshot(phrenPath), null, 2));
|
|
@@ -24,7 +24,8 @@ export function handleConfigSynonyms(args) {
|
|
|
24
24
|
}
|
|
25
25
|
if (!project || !isValidProjectName(project)) {
|
|
26
26
|
printSynonymsUsage();
|
|
27
|
-
process.
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
28
29
|
}
|
|
29
30
|
if (action === "list") {
|
|
30
31
|
console.log(JSON.stringify({
|
|
@@ -39,7 +40,8 @@ export function handleConfigSynonyms(args) {
|
|
|
39
40
|
const synonyms = parseSynonymItems(args[3]);
|
|
40
41
|
if (!term || synonyms.length === 0) {
|
|
41
42
|
printSynonymsUsage();
|
|
42
|
-
process.
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
return;
|
|
43
45
|
}
|
|
44
46
|
const updated = learnSynonym(phrenPath, project, term, synonyms);
|
|
45
47
|
console.log(JSON.stringify({ project, term, synonyms: updated[term.toLowerCase()] ?? [], updated }, null, 2));
|
|
@@ -49,12 +51,13 @@ export function handleConfigSynonyms(args) {
|
|
|
49
51
|
const term = args[2];
|
|
50
52
|
if (!term) {
|
|
51
53
|
printSynonymsUsage();
|
|
52
|
-
process.
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
return;
|
|
53
56
|
}
|
|
54
57
|
const updated = removeLearnedSynonym(phrenPath, project, term, parseSynonymItems(args[3]));
|
|
55
58
|
console.log(JSON.stringify({ project, term: term.toLowerCase(), updated }, null, 2));
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
printSynonymsUsage();
|
|
59
|
-
process.
|
|
62
|
+
process.exitCode = 1;
|
|
60
63
|
}
|
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" ||
|