@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single "lookup event" — emitted each time a memory search lands on a result.
|
|
3
|
+
* Powers the live activity feed in the web UI (SSE) and the VS Code extension
|
|
4
|
+
* (file watcher). Kept deliberately compact so the JSONL stays cheap to tail.
|
|
5
|
+
*/
|
|
6
|
+
export interface LookupEvent {
|
|
7
|
+
/** ISO timestamp of when the lookup happened. */
|
|
8
|
+
at: string;
|
|
9
|
+
/** The search query that surfaced this memory. */
|
|
10
|
+
query: string;
|
|
11
|
+
/** Project the memory belongs to. */
|
|
12
|
+
project: string;
|
|
13
|
+
/** Memory filename (e.g. "findings.md", "reference/api/auth.md"). */
|
|
14
|
+
filename: string;
|
|
15
|
+
/** Doc type: findings, reference, summary, task, skill, claude. */
|
|
16
|
+
type: string;
|
|
17
|
+
/** Source key / path of the memory, when available. */
|
|
18
|
+
path?: string;
|
|
19
|
+
/** Precomputed graph node id for this hit (e.g. a specific finding), when resolvable. */
|
|
20
|
+
nodeId?: string;
|
|
21
|
+
/** Short snippet of the matched content. */
|
|
22
|
+
snippet?: string;
|
|
23
|
+
/** What triggered the lookup: "search" (MCP search) | "inject" (hook). */
|
|
24
|
+
source: string;
|
|
25
|
+
/** Originating session id, when known. */
|
|
26
|
+
session?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Append one or more lookup events to the live log. Best-effort: a logging
|
|
30
|
+
* failure must never break a search, so all errors are swallowed (debug-logged).
|
|
31
|
+
*/
|
|
32
|
+
export declare function recordLookupEvents(phrenPath: string, events: Array<Omit<LookupEvent, "at"> & {
|
|
33
|
+
at?: string;
|
|
34
|
+
}>): void;
|
|
35
|
+
/** Read the most recent lookup events (newest first), parsed from the JSONL log. */
|
|
36
|
+
export declare function readRecentLookups(phrenPath: string, limit?: number): LookupEvent[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { lookupEventsLogFile } from "../phren-paths.js";
|
|
4
|
+
import { debugLog } from "../shared.js";
|
|
5
|
+
import { errorMessage } from "../utils.js";
|
|
6
|
+
const MAX_LOG_LINES = 500;
|
|
7
|
+
const ROTATE_BYTES = 500_000;
|
|
8
|
+
const MAX_SNIPPET_CHARS = 240;
|
|
9
|
+
function clampSnippet(snippet) {
|
|
10
|
+
if (!snippet)
|
|
11
|
+
return undefined;
|
|
12
|
+
const flat = snippet.replace(/\s+/g, " ").trim();
|
|
13
|
+
if (flat.length <= MAX_SNIPPET_CHARS)
|
|
14
|
+
return flat;
|
|
15
|
+
return flat.slice(0, MAX_SNIPPET_CHARS - 1) + "…";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Append one or more lookup events to the live log. Best-effort: a logging
|
|
19
|
+
* failure must never break a search, so all errors are swallowed (debug-logged).
|
|
20
|
+
*/
|
|
21
|
+
export function recordLookupEvents(phrenPath, events) {
|
|
22
|
+
if (!events.length)
|
|
23
|
+
return;
|
|
24
|
+
const logPath = lookupEventsLogFile(phrenPath);
|
|
25
|
+
try {
|
|
26
|
+
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
|
27
|
+
const now = new Date().toISOString();
|
|
28
|
+
const lines = events.map((e) => JSON.stringify({
|
|
29
|
+
at: e.at ?? now,
|
|
30
|
+
query: e.query,
|
|
31
|
+
project: e.project,
|
|
32
|
+
filename: e.filename,
|
|
33
|
+
type: e.type,
|
|
34
|
+
...(e.path ? { path: e.path } : {}),
|
|
35
|
+
...(e.nodeId ? { nodeId: e.nodeId } : {}),
|
|
36
|
+
...(e.snippet ? { snippet: clampSnippet(e.snippet) } : {}),
|
|
37
|
+
source: e.source,
|
|
38
|
+
...(e.session ? { session: e.session } : {}),
|
|
39
|
+
}));
|
|
40
|
+
fs.appendFileSync(logPath, lines.join("\n") + "\n");
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
debugLog(`recordLookupEvents write failed: ${errorMessage(err)}`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const stat = fs.statSync(logPath);
|
|
48
|
+
if (stat.size > ROTATE_BYTES) {
|
|
49
|
+
const content = fs.readFileSync(logPath, "utf8");
|
|
50
|
+
const kept = content.split("\n").filter(Boolean).slice(-MAX_LOG_LINES);
|
|
51
|
+
fs.writeFileSync(logPath, kept.join("\n") + "\n");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
debugLog(`recordLookupEvents rotation failed: ${errorMessage(err)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Read the most recent lookup events (newest first), parsed from the JSONL log. */
|
|
59
|
+
export function readRecentLookups(phrenPath, limit = 40) {
|
|
60
|
+
const logPath = lookupEventsLogFile(phrenPath);
|
|
61
|
+
try {
|
|
62
|
+
if (!fs.existsSync(logPath))
|
|
63
|
+
return [];
|
|
64
|
+
const lines = fs.readFileSync(logPath, "utf8").split("\n").filter(Boolean);
|
|
65
|
+
const recent = lines.slice(-limit).reverse();
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const line of recent) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = JSON.parse(line);
|
|
70
|
+
if (parsed && typeof parsed.at === "string")
|
|
71
|
+
out.push(parsed);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Skip malformed lines rather than failing the whole read.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
debugLog(`readRecentLookups failed: ${errorMessage(err)}`);
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -17,6 +17,23 @@
|
|
|
17
17
|
* The actor is read from the PHREN_ACTOR env var (falls back to open if unset).
|
|
18
18
|
*/
|
|
19
19
|
type RbacAction = "add_finding" | "remove_finding" | "edit_finding" | "complete_task" | "add_task" | "remove_task" | "update_task" | "pin_task" | "manage_config";
|
|
20
|
+
export declare const ACCESS_ROLE_KEYS: readonly ["admins", "contributors", "readers"];
|
|
21
|
+
export type AccessRole = (typeof ACCESS_ROLE_KEYS)[number];
|
|
22
|
+
export type AccessRolePatch = Partial<Record<AccessRole, string[]>>;
|
|
23
|
+
/**
|
|
24
|
+
* Single source of truth for writing access-control role lists. Writes to the
|
|
25
|
+
* global `.config/access-control.json` or, when `project` is given, to that
|
|
26
|
+
* project's `phren.project.yaml` under the `access` key (merged with any
|
|
27
|
+
* existing roles). Returns the role lists as written at the chosen scope.
|
|
28
|
+
*
|
|
29
|
+
* Shared by the CLI (`phren config access`) and the MCP `set_config` tool so
|
|
30
|
+
* the two paths can never diverge.
|
|
31
|
+
*/
|
|
32
|
+
export declare function setAccessRoles(phrenPath: string, patch: AccessRolePatch, project?: string): {
|
|
33
|
+
admins: string[];
|
|
34
|
+
contributors: string[];
|
|
35
|
+
readers: string[];
|
|
36
|
+
};
|
|
20
37
|
/**
|
|
21
38
|
* Convenience wrapper: returns a permission-denied MCP error string,
|
|
22
39
|
* or null if the action is allowed.
|
package/dist/governance/rbac.js
CHANGED
|
@@ -20,7 +20,7 @@ import * as fs from "fs";
|
|
|
20
20
|
import * as path from "path";
|
|
21
21
|
import { debugLog } from "../shared.js";
|
|
22
22
|
import { errorMessage } from "../utils.js";
|
|
23
|
-
import { readProjectConfig } from "../project-config.js";
|
|
23
|
+
import { readProjectConfig, writeProjectConfig } from "../project-config.js";
|
|
24
24
|
function configDir(phrenPath) {
|
|
25
25
|
return path.join(phrenPath, ".config");
|
|
26
26
|
}
|
|
@@ -45,6 +45,42 @@ function normalizeStringArray(value) {
|
|
|
45
45
|
return [];
|
|
46
46
|
return value.filter((item) => typeof item === "string" && item.trim().length > 0);
|
|
47
47
|
}
|
|
48
|
+
export const ACCESS_ROLE_KEYS = ["admins", "contributors", "readers"];
|
|
49
|
+
/**
|
|
50
|
+
* Single source of truth for writing access-control role lists. Writes to the
|
|
51
|
+
* global `.config/access-control.json` or, when `project` is given, to that
|
|
52
|
+
* project's `phren.project.yaml` under the `access` key (merged with any
|
|
53
|
+
* existing roles). Returns the role lists as written at the chosen scope.
|
|
54
|
+
*
|
|
55
|
+
* Shared by the CLI (`phren config access`) and the MCP `set_config` tool so
|
|
56
|
+
* the two paths can never diverge.
|
|
57
|
+
*/
|
|
58
|
+
export function setAccessRoles(phrenPath, patch, project) {
|
|
59
|
+
const clean = {};
|
|
60
|
+
for (const key of ACCESS_ROLE_KEYS) {
|
|
61
|
+
if (patch[key] !== undefined)
|
|
62
|
+
clean[key] = normalizeStringArray(patch[key]);
|
|
63
|
+
}
|
|
64
|
+
if (project) {
|
|
65
|
+
const current = readProjectConfig(phrenPath, project).access ?? {};
|
|
66
|
+
writeProjectConfig(phrenPath, project, { access: { ...current, ...clean } });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const current = readGlobalAccessControl(phrenPath) ?? {};
|
|
70
|
+
const next = { ...current, ...clean };
|
|
71
|
+
const dir = configDir(phrenPath);
|
|
72
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
73
|
+
fs.writeFileSync(path.join(dir, "access-control.json"), JSON.stringify(next, null, 2) + "\n");
|
|
74
|
+
}
|
|
75
|
+
const written = project
|
|
76
|
+
? (readProjectConfig(phrenPath, project).access ?? {})
|
|
77
|
+
: (readGlobalAccessControl(phrenPath) ?? {});
|
|
78
|
+
return {
|
|
79
|
+
admins: normalizeStringArray(written.admins),
|
|
80
|
+
contributors: normalizeStringArray(written.contributors),
|
|
81
|
+
readers: normalizeStringArray(written.readers),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
48
84
|
function mergeAccessControl(global, projectAccess) {
|
|
49
85
|
// If neither global nor project access is configured, open mode
|
|
50
86
|
if (!global && !projectAccess)
|