@phren/cli 0.3.73 → 0.3.75

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.
@@ -149,6 +149,10 @@ export declare function getRetentionPolicy(phrenPath: string, projectName?: stri
149
149
  export declare function updateRetentionPolicy(phrenPath: string, patch: RetentionPolicyPatch): PhrenResult<RetentionPolicy>;
150
150
  export declare function getWorkflowPolicy(phrenPath: string, projectName?: string): WorkflowPolicy;
151
151
  export declare function updateWorkflowPolicy(phrenPath: string, patch: Partial<WorkflowPolicy>): PhrenResult<WorkflowPolicy>;
152
+ /** An index glob is matched from each project's folder and stays inside it:
153
+ * relative, with no `..` and no backslash (an escape in a glob, a separator
154
+ * on Windows). Blank entries are not globs. */
155
+ export declare function isProjectGlob(glob: unknown): glob is string;
152
156
  export declare function getIndexPolicy(phrenPath: string): IndexPolicy;
153
157
  export declare function updateIndexPolicy(phrenPath: string, patch: Partial<IndexPolicy>): PhrenResult<IndexPolicy>;
154
158
  export declare function getRuntimeHealth(phrenPath: string): RuntimeHealth;
@@ -584,10 +584,18 @@ function patchedWorkflowPolicy(current, patch) {
584
584
  };
585
585
  return next;
586
586
  }
587
+ /** An index glob is matched from each project's folder and stays inside it:
588
+ * relative, with no `..` and no backslash (an escape in a glob, a separator
589
+ * on Windows). Blank entries are not globs. */
590
+ export function isProjectGlob(glob) {
591
+ return typeof glob === "string" && glob.trim().length > 0
592
+ && !/^([/~]|[A-Za-z]:)/.test(glob.trim()) && !glob.includes("..") && !glob.includes("\\");
593
+ }
587
594
  export function getIndexPolicy(phrenPath) {
588
595
  const parsed = readJsonFile(govFile(phrenPath, "index-policy"), {});
589
596
  const merged = withDefaults(parsed, DEFAULT_INDEX_POLICY);
590
- merged.includeGlobs = merged.includeGlobs.filter((glob) => typeof glob === "string" && glob.trim().length > 0);
597
+ // The file syncs with the store, so what it holds is checked on every read.
598
+ merged.includeGlobs = merged.includeGlobs.filter(isProjectGlob);
591
599
  merged.excludeGlobs = merged.excludeGlobs.filter((glob) => typeof glob === "string" && glob.trim().length > 0);
592
600
  if (!merged.includeGlobs.length)
593
601
  merged.includeGlobs = DEFAULT_INDEX_POLICY.includeGlobs;
@@ -596,6 +604,11 @@ export function getIndexPolicy(phrenPath) {
596
604
  return merged;
597
605
  }
598
606
  export function updateIndexPolicy(phrenPath, patch) {
607
+ const outside = Array.isArray(patch.includeGlobs)
608
+ ? patch.includeGlobs.filter(glob => typeof glob === "string" && glob.trim().length > 0 && !isProjectGlob(glob)) : [];
609
+ if (outside.length) {
610
+ return phrenErr(`Index globs are matched inside each project folder: use a relative pattern with no ".." or backslash. Not accepted: ${outside.join(", ")}`, PhrenError.VALIDATION_ERROR);
611
+ }
599
612
  const file = govFile(phrenPath, "index-policy");
600
613
  const next = withFileLock(file, () => {
601
614
  const merged = patchedIndexPolicy(getIndexPolicy(phrenPath), patch);
@@ -8,7 +8,7 @@ function normalizeSummary(summary) {
8
8
  return trimmed ? trimmed : undefined;
9
9
  }
10
10
  function sessionMessagesFileForId(phrenPath, sessionId) {
11
- return path.join(runtimeSessionsDir(phrenPath), `session-${sessionId}-messages.json`);
11
+ return sessionFileForId(phrenPath, sessionId, "-messages");
12
12
  }
13
13
  function inferProjectForSession(phrenPath, sessionId) {
14
14
  return readSessionState(phrenPath, sessionId)?.project;
@@ -19,7 +19,10 @@ export interface SessionState {
19
19
  agentCreated?: boolean;
20
20
  }
21
21
  export declare function runtimeSessionsDir(phrenPath: string): string;
22
- export declare function sessionFileForId(phrenPath: string, sessionId: string): string;
22
+ export declare function isSessionId(value: unknown): value is string;
23
+ /** `session-<id><suffix>.json` in the sessions folder. Throws for anything
24
+ * that is not a session id; callers taking an id from outside check first. */
25
+ export declare function sessionFileForId(phrenPath: string, sessionId: string, suffix?: string): string;
23
26
  export declare function isSessionStateFileName(name: string): boolean;
24
27
  export declare function readSessionStateFile(file: string): SessionState | null;
25
28
  export declare function writeSessionStateFile(file: string, state: SessionState): void;
@@ -16,8 +16,19 @@ export function runtimeSessionsDir(phrenPath) {
16
16
  fs.mkdirSync(dir, { recursive: true });
17
17
  return dir;
18
18
  }
19
- export function sessionFileForId(phrenPath, sessionId) {
20
- return path.join(runtimeSessionsDir(phrenPath), `session-${sessionId}.json`);
19
+ /** A session id is one plain name. phren's own are UUIDs; one handed in by a
20
+ * tool call is used only in this shape, so the file it names is always
21
+ * inside the sessions folder. */
22
+ const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
23
+ export function isSessionId(value) {
24
+ return typeof value === "string" && SESSION_ID.test(value);
25
+ }
26
+ /** `session-<id><suffix>.json` in the sessions folder. Throws for anything
27
+ * that is not a session id; callers taking an id from outside check first. */
28
+ export function sessionFileForId(phrenPath, sessionId, suffix = "") {
29
+ if (!isSessionId(sessionId))
30
+ throw new Error("That is not a session id.");
31
+ return path.join(runtimeSessionsDir(phrenPath), `session-${sessionId}${suffix}.json`);
21
32
  }
22
33
  export function isSessionStateFileName(name) {
23
34
  return name.startsWith("session-") &&
@@ -18,7 +18,7 @@ import { getActiveTaskForSession } from "../task/lifecycle.js";
18
18
  import { listTaskCheckpoints, writeTaskCheckpoint } from "../session/checkpoints.js";
19
19
  import { findMostRecentSummaryWithProject as findMostRecentSummaryRecord, writeLastSummary, } from "../session/artifacts.js";
20
20
  import { markImpactEntriesCompletedForSession } from "../finding/impact.js";
21
- import { debugError, scanSessionFiles, runtimeSessionsDir, sessionFileForId, readSessionStateFile, writeSessionStateFile, } from "../session/utils.js";
21
+ import { debugError, scanSessionFiles, runtimeSessionsDir, isSessionId, sessionFileForId, readSessionStateFile, writeSessionStateFile, } from "../session/utils.js";
22
22
  import { getRuntimeHealth } from "../governance/policy.js";
23
23
  import { getProjectSourcePath, readProjectConfig } from "../project-config.js";
24
24
  const STALE_SESSION_MS = 24 * 60 * 60 * 1000; // 24 hours
@@ -148,6 +148,9 @@ function findMostRecentSummaryWithProject(phrenPath) {
148
148
  function resolveSessionFile(phrenPath, sessionId, connectionId) {
149
149
  const effectiveId = sessionId ?? (connectionId ? _sessionMap.get(connectionId) : undefined);
150
150
  if (effectiveId) {
151
+ // An id that is not one of ours names no session.
152
+ if (!isSessionId(effectiveId))
153
+ return null;
151
154
  const file = sessionFileForId(phrenPath, effectiveId);
152
155
  const state = readSessionStateFile(file);
153
156
  if (!state)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.73",
3
+ "version": "0.3.75",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {
@@ -207,13 +207,13 @@
207
207
  "dependencies": {
208
208
  "@modelcontextprotocol/sdk": "^1.32.0",
209
209
  "chalk": "^6.0.1",
210
- "glob": "^13.0.6",
210
+ "glob": "^14.0.2",
211
211
  "inquirer": "^14.2.3",
212
212
  "js-yaml": "^5.4.2",
213
213
  "sql.js-fts5": "^1.4.0",
214
214
  "uqr": "0.1.3",
215
215
  "ws": "8.22.0",
216
- "zod": "^4.6.5"
216
+ "zod": "^4.6.6"
217
217
  },
218
218
  "engines": {
219
219
  "node": ">=22.19.0"