pi-memory-stone 0.1.2 → 0.1.4

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.
@@ -6,8 +6,10 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
6
  import { Type } from "typebox";
7
7
  import { StringEnum } from "@earendil-works/pi-ai";
8
8
  import { getRecord, softForgetRecord, upsertRecord } from "../db/index.js";
9
- import { retrieve, buildInjectionPacket, formatInjectionForLlm } from "../retrieval/index.js";
9
+ import { retrieve, buildInjectionPacket, formatInjectionForLlm, normalizeRetrievalLimit } from "../retrieval/index.js";
10
10
  import { getProjectId, getConfig } from "../config/index.js";
11
+ import { isSensitiveForGlobalMemory } from "../privacy/index.js";
12
+ import { isRecordVisibleInProject } from "../session-state/index.js";
11
13
  import type { RecordKind, RecordScope } from "../db/schema.js";
12
14
 
13
15
  export function registerTools(pi: ExtensionAPI): void {
@@ -37,12 +39,12 @@ export function registerTools(pi: ExtensionAPI): void {
37
39
  ] as const),
38
40
  ),
39
41
  scope: Type.Optional(StringEnum(["project", "global"] as const)),
40
- limit: Type.Optional(Type.Number({ description: "Max results (default 5)" })),
42
+ limit: Type.Optional(Type.Number({ description: "Max results (default 5, max 20)", minimum: 1, maximum: 20 })),
41
43
  }),
42
44
  async execute(toolCallId, params, _signal, _onUpdate, ctx) {
43
45
  const projectId = getProjectId(ctx.cwd);
44
46
  const config = getConfig(ctx.cwd);
45
- const limit = params.limit ?? 5;
47
+ const limit = normalizeRetrievalLimit(params.limit, 5);
46
48
 
47
49
  const results = retrieve(params.query, projectId, [], {
48
50
  limit,
@@ -102,10 +104,8 @@ export function registerTools(pi: ExtensionAPI): void {
102
104
  }
103
105
 
104
106
  const currentProjectId = getProjectId(ctx.cwd);
105
- const visibleInCurrentProject =
106
- record.scope === "global" || record.project_id === null || record.project_id === currentProjectId;
107
107
 
108
- if (record.status !== "active" || !visibleInCurrentProject) {
108
+ if (record.status !== "active" || !isRecordVisibleInProject(record, currentProjectId)) {
109
109
  return {
110
110
  content: [{ type: "text", text: `Memory record ${params.ref} is not available.` }],
111
111
  details: { ref: params.ref, found: false, unavailable: true },
@@ -168,10 +168,7 @@ export function registerTools(pi: ExtensionAPI): void {
168
168
  let scope = params.scope ?? "project";
169
169
 
170
170
  // Safety: never allow global for implementation details, paths, etc.
171
- const isSensitiveForGlobal =
172
- /\b(?:password|secret|token|key|\.env|localhost|127\.0\.0\.1|internal|private)\b/i.test(
173
- params.text,
174
- );
171
+ const isSensitiveForGlobal = isSensitiveForGlobalMemory(`${params.text}\n${params.tags ?? ""}`);
175
172
 
176
173
  const downgradedToProject = isSensitiveForGlobal && scope === "global";
177
174
  if (downgradedToProject) {
@@ -228,14 +225,22 @@ export function registerTools(pi: ExtensionAPI): void {
228
225
  };
229
226
  }
230
227
 
228
+ const currentProjectId = getProjectId(ctx.cwd);
229
+ if (record.status !== "active" || !isRecordVisibleInProject(record, currentProjectId)) {
230
+ return {
231
+ content: [{ type: "text", text: `Memory record ${params.ref} is not available.` }],
232
+ details: { ref: params.ref, found: false, unavailable: true },
233
+ };
234
+ }
235
+
231
236
  if (params.hard) {
232
237
  // For hard delete via tool, we require the user to explicitly confirm
233
- // The tool should note this requires user interaction
238
+ // The tool should note this requires user interaction without leaking record contents.
234
239
  return {
235
240
  content: [
236
241
  {
237
242
  type: "text",
238
- text: `Permanent deletion requires explicit confirmation. Please use /memory-forget ${params.ref} --hard to permanently delete this record.\n\nRecord: [${record.kind}] ${record.text.slice(0, 200)}`,
243
+ text: `Permanent deletion requires explicit confirmation. Please use /memory-forget ${params.ref} --hard to permanently delete this record.`,
239
244
  },
240
245
  ],
241
246
  details: { ref: params.ref, requiresConfirmation: true },