@remnic/core 9.3.614 → 9.3.615

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.
Files changed (46) hide show
  1. package/dist/access-cli.js +3 -3
  2. package/dist/access-http.d.ts +1 -1
  3. package/dist/access-http.js +5 -5
  4. package/dist/access-mcp.d.ts +1 -1
  5. package/dist/access-mcp.js +4 -4
  6. package/dist/access-schema.d.ts +14 -2
  7. package/dist/access-schema.js +1 -1
  8. package/dist/{access-service-DGG_2xPK.d.ts → access-service-CBNEKjzN.d.ts} +70 -5
  9. package/dist/access-service.d.ts +1 -1
  10. package/dist/access-service.js +2 -2
  11. package/dist/{chunk-B6FDZPCF.js → chunk-5OHHEORR.js} +50 -15
  12. package/dist/chunk-5OHHEORR.js.map +1 -0
  13. package/dist/{chunk-T5XWMMU2.js → chunk-EXUAP5LH.js} +2 -2
  14. package/dist/{chunk-EUML3N6B.js → chunk-IMA6GU4Y.js} +3 -3
  15. package/dist/chunk-IMA6GU4Y.js.map +1 -0
  16. package/dist/{chunk-7YQFWOF7.js → chunk-KGLPJROV.js} +4 -4
  17. package/dist/{chunk-VPGUMLBA.js → chunk-NM5NQYJE.js} +16 -16
  18. package/dist/chunk-NM5NQYJE.js.map +1 -0
  19. package/dist/{chunk-QEMCQFDW.js → chunk-WD2W4234.js} +8 -2
  20. package/dist/chunk-WD2W4234.js.map +1 -0
  21. package/dist/{chunk-ADNZVFXG.js → chunk-ZK32E74R.js} +142 -31
  22. package/dist/chunk-ZK32E74R.js.map +1 -0
  23. package/dist/{cli-DWeu7eTY.d.ts → cli-Cw729yLf.d.ts} +1 -1
  24. package/dist/cli.d.ts +2 -2
  25. package/dist/cli.js +6 -6
  26. package/dist/explicit-capture.d.ts +10 -0
  27. package/dist/explicit-capture.js +1 -1
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +7 -7
  30. package/dist/mcp-memory-inspector-app.d.ts +1 -1
  31. package/dist/orchestrator.js +2 -2
  32. package/package.json +1 -1
  33. package/src/access-http.ts +21 -10
  34. package/src/access-mcp.test.ts +109 -0
  35. package/src/access-mcp.ts +46 -2
  36. package/src/access-schema.ts +11 -0
  37. package/src/access-service-coding-write.test.ts +478 -0
  38. package/src/access-service.ts +237 -32
  39. package/src/explicit-capture.ts +19 -2
  40. package/dist/chunk-ADNZVFXG.js.map +0 -1
  41. package/dist/chunk-B6FDZPCF.js.map +0 -1
  42. package/dist/chunk-EUML3N6B.js.map +0 -1
  43. package/dist/chunk-QEMCQFDW.js.map +0 -1
  44. package/dist/chunk-VPGUMLBA.js.map +0 -1
  45. /package/dist/{chunk-T5XWMMU2.js.map → chunk-EXUAP5LH.js.map} +0 -0
  46. /package/dist/{chunk-7YQFWOF7.js.map → chunk-KGLPJROV.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/access-schema.ts"],"sourcesContent":["// Request/response schema validation for the Remnic HTTP API.\n// Uses zod for runtime validation — returns structured 400 errors with\n// field-level detail so consumers get clear feedback on malformed requests.\n\nimport { z } from \"zod\";\nimport {\n ACTION_CONFIDENCE_CONTEXT_READINESS,\n ACTION_CONFIDENCE_RISK_CATEGORIES,\n ACTION_CONFIDENCE_RULE_KINDS,\n} from \"./action-confidence.js\";\nimport { isValidCapsuleSince } from \"./transfer/capsule-export.js\";\nimport { validateArchiveRelativePath } from \"./transfer/fs-utils.js\";\nimport { CAPSULE_ID_PATTERN } from \"./transfer/types.js\";\nimport {\n OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,\n OFFLINE_SYNC_MAX_MTIME_MS,\n} from \"./offline-sync.js\";\n\n// ---------------------------------------------------------------------------\n// Error formatting\n// ---------------------------------------------------------------------------\n\nexport interface SchemaValidationError {\n error: string;\n code: \"validation_error\";\n details: Array<{ field: string; message: string }>;\n}\n\nexport function formatZodError(error: z.ZodError): SchemaValidationError {\n return {\n error: \"request validation failed\",\n code: \"validation_error\",\n details: error.issues.map((issue) => ({\n field: issue.path.join(\".\") || \"(root)\",\n message: issue.message,\n })),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Shared fields\n// ---------------------------------------------------------------------------\n\nconst namespaceSchema = z.string().trim().max(256).optional();\nconst sessionKeySchema = z.string().trim().min(1).max(512).optional();\nconst idempotencyKeySchema = z.string().trim().min(1).max(256).optional();\nconst dryRunSchema = z.boolean().optional();\nconst schemaVersionSchema = z.number().int().optional();\n\n// ---------------------------------------------------------------------------\n// Recall\n// ---------------------------------------------------------------------------\n\n/**\n * Coding-agent context (issue #569). Optional payload that connectors may\n * ship with a recall request so the project/branch namespace overlay\n * applies to that recall. All fields are validated per CLAUDE.md #51 —\n * empty-string projectId / rootPath is rejected, not silently accepted.\n */\nexport const codingContextSchema = z\n .object({\n projectId: z.string().trim().min(1, \"codingContext.projectId is required\").max(128),\n branch: z.string().trim().max(256).nullable(),\n rootPath: z.string().trim().min(1, \"codingContext.rootPath is required\").max(1024),\n defaultBranch: z.string().trim().max(256).nullable(),\n })\n .nullable();\n\n/**\n * Recall disclosure depth (issue #677). Mirrors the `RecallDisclosure`\n * type in `types.ts` — keep these in sync. Default-application happens\n * inside `EngramAccessService.recall()`; the schema only accepts/rejects.\n * Invalid values throw a structured 400 instead of silently defaulting,\n * per CLAUDE.md rule 51.\n */\nexport const recallDisclosureSchema = z.enum([\"chunk\", \"section\", \"raw\"]);\n\n/**\n * Tag-match semantics (issue #689). `any` (default when `tags` is provided\n * and `tagMatch` is omitted) admits a result when it carries at least one\n * of the filter tags. `all` requires every filter tag to be present.\n * Schema rejects unknown values up front — never silently defaults\n * (CLAUDE.md rule 51).\n */\nexport const tagMatchSchema = z.enum([\"any\", \"all\"]);\n\nexport const recallRequestSchema = z.object({\n query: z.string().min(1, \"query is required\"),\n sessionKey: sessionKeySchema,\n namespace: namespaceSchema,\n topK: z.number().int().min(0).max(200).optional(),\n mode: z.enum([\"auto\", \"no_recall\", \"minimal\", \"full\", \"graph_mode\"]).optional(),\n includeDebug: z.boolean().optional(),\n idempotencyKey: idempotencyKeySchema,\n disclosure: recallDisclosureSchema.optional(),\n codingContext: codingContextSchema.optional(),\n /** Working directory for auto git-context resolution (issue #569). */\n cwd: z.string().trim().min(1, \"cwd must be non-empty when provided\").max(2048).optional(),\n /**\n * Arbitrary project tag for non-git-based project scoping (issue #569).\n * Creates a coding context with `projectId: \"tag:<projectTag>\"`.\n */\n projectTag: z.string().trim().min(1, \"projectTag must be non-empty when provided\").max(256).optional(),\n /**\n * Historical recall pin (issue #680). ISO 8601 timestamp. The\n * schema only enforces the basic shape; the access service runs\n * `Date.parse` and emits a structured 400 on malformed input\n * (CLAUDE.md rule 51).\n */\n asOf: z.string().trim().min(1, \"asOf must be a non-empty ISO 8601 timestamp\").max(64).optional(),\n /**\n * Free-form recall tag filter (issue #689). When provided, recall results\n * whose frontmatter `tags` do not match the filter are removed before the\n * response is returned. Comparison is case-sensitive exact match.\n */\n tags: z.array(z.string().trim().min(1).max(256)).max(50).optional(),\n /**\n * Match mode for `tags` (issue #689). Defaults to `\"any\"` when `tags` is\n * provided and `tagMatch` is omitted. Ignored when `tags` is absent.\n */\n tagMatch: tagMatchSchema.optional(),\n /**\n * Include graph edges below `graphTraversalConfidenceFloor` for diagnostic\n * recall traversal (issue #681). Defaults to false.\n */\n includeLowConfidence: z.boolean().optional(),\n});\n\nexport const recallExplainRequestSchema = z.object({\n sessionKey: sessionKeySchema,\n namespace: namespaceSchema,\n});\n\n/**\n * Standalone \"set coding context\" request. Used by the HTTP endpoint\n * `POST /engram/v1/coding-context` and the MCP `remnic.set_coding_context`\n * tool (PR 7). `codingContext: null` clears the attached context.\n */\nexport const setCodingContextRequestSchema = z\n .object({\n sessionKey: z.string().trim().min(1, \"sessionKey is required\").max(512),\n codingContext: codingContextSchema.optional(),\n /**\n * Project tag shorthand for non-git-based project scoping. When\n * `codingContext` is omitted, this becomes\n * `{ projectId: \"tag:<projectTag>\", branch: null, rootPath: \"tag:<projectTag>\", defaultBranch: null }`.\n */\n projectTag: z.string().trim().min(1, \"projectTag must be non-empty when provided\").max(256).optional(),\n })\n .superRefine((value, ctx) => {\n if (value.codingContext === undefined && value.projectTag === undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"codingContext or projectTag is required\",\n path: [\"codingContext\"],\n });\n }\n });\n\n// ---------------------------------------------------------------------------\n// Observe\n// ---------------------------------------------------------------------------\n\nconst messageSchema = z.object({\n role: z.enum([\"user\", \"assistant\"]),\n content: z.string().min(1, \"message content must be non-empty\"),\n sourceFormat: z\n .enum([\"openai\", \"anthropic\", \"openclaw\", \"pi\", \"lossless-claw\", \"remnic\"])\n .nullable()\n .optional(),\n rawContent: z.unknown().nullable().optional(),\n parts: z\n .array(\n z.object({\n ordinal: z.number().int().min(0).nullable().optional(),\n kind: z.enum([\n \"text\",\n \"tool_call\",\n \"tool_result\",\n \"patch\",\n \"file_read\",\n \"file_write\",\n \"step_start\",\n \"step_finish\",\n \"snapshot\",\n \"retry\",\n ]),\n payload: z.record(z.string(), z.unknown()),\n toolName: z.string().nullable().optional(),\n tool_name: z.string().nullable().optional(),\n filePath: z.string().nullable().optional(),\n file_path: z.string().nullable().optional(),\n createdAt: z.string().nullable().optional(),\n created_at: z.string().nullable().optional(),\n }),\n )\n .nullable()\n .optional(),\n});\n\nexport const observeRequestSchema = z.object({\n sessionKey: z.string().trim().min(1, \"sessionKey is required\").max(512),\n messages: z.array(messageSchema).min(1, \"messages must be a non-empty array\"),\n namespace: namespaceSchema,\n skipExtraction: z.boolean().optional(),\n /** Working directory for auto git-context resolution (issue #569). */\n cwd: z.string().trim().min(1, \"cwd must be non-empty when provided\").max(2048).optional(),\n /**\n * Arbitrary project tag for non-git-based project scoping (issue #569).\n * Creates a coding context with `projectId: \"tag:<projectTag>\"`.\n */\n projectTag: z.string().trim().min(1, \"projectTag must be non-empty when provided\").max(256).optional(),\n});\n\n// ---------------------------------------------------------------------------\n// Memory store / suggestion submit\n// ---------------------------------------------------------------------------\n\nconst writeContentSchema = z.string().min(1, \"content is required\").max(50000);\nconst categorySchema = z\n .enum([\n \"fact\", \"preference\", \"correction\", \"entity\", \"decision\",\n \"relationship\", \"principle\", \"commitment\", \"moment\", \"skill\", \"rule\", \"procedure\",\n \"reasoning_trace\",\n ])\n .optional();\nconst confidenceSchema = z.number().min(0).max(1).optional();\nconst tagsSchema = z.array(z.string().max(256)).max(50).optional();\nconst entityRefSchema = z.string().trim().max(512).optional();\nconst ttlSchema = z.string().trim().max(128).optional();\nconst sourceReasonSchema = z.string().trim().max(2000).optional();\n\nexport const memoryStoreRequestSchema = z.object({\n schemaVersion: schemaVersionSchema,\n idempotencyKey: idempotencyKeySchema,\n dryRun: dryRunSchema,\n sessionKey: sessionKeySchema,\n content: writeContentSchema,\n category: categorySchema,\n confidence: confidenceSchema,\n namespace: namespaceSchema,\n tags: tagsSchema,\n entityRef: entityRefSchema,\n ttl: ttlSchema,\n sourceReason: sourceReasonSchema,\n // Git/project context for project-scoped writes (#1434). When no explicit\n // `namespace` is given, these route the write to the same project namespace\n // recall/observe resolve from `cwd`/`projectTag` (issue #569, rule 42). Also\n // lets MCP clients that auto-inject `cwd` (e.g. Pi MCPorter) call write tools.\n cwd: z.string().trim().min(1, \"cwd must be non-empty when provided\").max(2048).optional(),\n projectTag: z\n .string()\n .trim()\n .min(1, \"projectTag must be non-empty when provided\")\n .max(256)\n .optional(),\n});\n\nexport const suggestionSubmitRequestSchema = memoryStoreRequestSchema;\n\n// ---------------------------------------------------------------------------\n// Review disposition\n// ---------------------------------------------------------------------------\n\nexport const reviewDispositionRequestSchema = z.object({\n memoryId: z.string().trim().min(1, \"memoryId is required\"),\n status: z.enum([\n \"active\", \"pending_review\", \"quarantined\", \"rejected\", \"superseded\", \"archived\",\n ]),\n reasonCode: z.string().trim().min(1, \"reasonCode is required\"),\n namespace: namespaceSchema,\n});\n\n// ---------------------------------------------------------------------------\n// Trust-zone promote\n// ---------------------------------------------------------------------------\n\nexport const trustZonePromoteRequestSchema = z.object({\n recordId: z.string().trim().min(1, \"recordId is required\"),\n targetZone: z.enum([\"working\", \"trusted\"], {\n errorMap: () => ({ message: \"targetZone must be 'working' or 'trusted'\" }),\n }),\n promotionReason: z.string().trim().min(1, \"promotionReason is required\"),\n recordedAt: z.string().trim().optional(),\n summary: z.string().trim().max(5000).optional(),\n dryRun: dryRunSchema,\n namespace: namespaceSchema,\n});\n\n// ---------------------------------------------------------------------------\n// Trust-zone demo-seed\n// ---------------------------------------------------------------------------\n\nexport const trustZoneDemoSeedRequestSchema = z.object({\n scenario: z.string().trim().max(256).optional(),\n recordedAt: z.string().trim().optional(),\n dryRun: dryRunSchema,\n namespace: namespaceSchema,\n});\n\n// ---------------------------------------------------------------------------\n// LCM search\n// ---------------------------------------------------------------------------\n\nexport const lcmSearchRequestSchema = z.object({\n query: z.string().min(1, \"query is required\"),\n sessionKey: sessionKeySchema,\n sessionPrefix: z.string().trim().min(1).max(512).optional(),\n namespace: namespaceSchema,\n limit: z.number().int().min(1).max(100).optional(),\n});\n\nexport const lcmCompactionFlushRequestSchema = z.object({\n sessionKey: z.string().trim().min(1, \"sessionKey is required\").max(512),\n namespace: namespaceSchema,\n});\n\nexport const lcmCompactionRecordRequestSchema = z.object({\n sessionKey: z.string().trim().min(1, \"sessionKey is required\").max(512),\n namespace: namespaceSchema,\n tokensBefore: z.number().int().min(0, \"tokensBefore must be a non-negative integer\"),\n tokensAfter: z.number().int().min(0, \"tokensAfter must be a non-negative integer\"),\n});\n\n// ---------------------------------------------------------------------------\n// Day summary\n// ---------------------------------------------------------------------------\n\nexport const daySummaryRequestSchema = z.object({\n memories: z.string().max(100000).optional(),\n sessionKey: sessionKeySchema,\n namespace: namespaceSchema,\n});\n\n// ---------------------------------------------------------------------------\n// Capsule export\n// ---------------------------------------------------------------------------\n\nconst capsuleTopLevelSegmentSchema = z\n .string()\n .trim()\n .min(1)\n .max(128)\n .refine(\n (value) => !value.includes(\"/\") && !value.includes(\"\\\\\"),\n \"must be a top-level directory name without path separators\",\n );\n\nconst capsulePeerIdSchema = z\n .string()\n .trim()\n .min(1)\n .max(256)\n .refine(\n (value) => value !== \".\" && value !== \"..\" && !value.includes(\"/\") && !value.includes(\"\\\\\"),\n \"must be a plain peer id without path separators\",\n );\n\nconst capsuleIsoSinceSchema = z\n .string()\n .trim()\n .min(1, \"since must be a non-empty ISO 8601 timestamp\")\n .max(128)\n .refine(\n isValidCapsuleSince,\n \"since must be a valid ISO 8601 timestamp with no calendar overflow\",\n );\n\nexport const capsuleExportRequestSchema = z\n .object({\n name: z\n .string()\n .trim()\n .min(1, \"name is required\")\n .max(64, \"name must be 64 characters or fewer\")\n .regex(\n CAPSULE_ID_PATTERN,\n \"name must be alphanumeric with single dashes (no spaces, no leading/trailing dashes)\",\n ),\n namespace: namespaceSchema,\n since: capsuleIsoSinceSchema.optional(),\n includeKinds: z.array(capsuleTopLevelSegmentSchema).max(50).optional(),\n peerIds: z.array(capsulePeerIdSchema).max(100).optional(),\n includeTranscripts: z.boolean().optional(),\n encrypt: z.boolean().optional(),\n });\n\nexport const capsuleImportRequestSchema = z\n .object({\n archivePath: z.string().trim().min(1, \"archivePath is required\").max(4096),\n namespace: namespaceSchema,\n mode: z.enum([\"skip\", \"overwrite\", \"fork\"]).optional(),\n passphrase: z.string().min(1, \"passphrase must not be empty\").max(4096).optional(),\n });\n\nexport const capsuleListRequestSchema = z\n .object({\n namespace: namespaceSchema,\n });\n\n// ---------------------------------------------------------------------------\n// Offline sync\n// ---------------------------------------------------------------------------\n\nfunction isValidOfflineSyncPath(value: string): boolean {\n try {\n validateArchiveRelativePath(value, \"path\");\n return true;\n } catch {\n return false;\n }\n}\n\nconst offlineSyncPathSchema = z\n .string()\n .trim()\n .min(1, \"path must be non-empty\")\n .max(4096)\n .refine(\n isValidOfflineSyncPath,\n \"path must be a POSIX relative path without unsafe segments\",\n );\n\nconst offlineSyncFileStateSchema = z.object({\n path: offlineSyncPathSchema,\n sha256: z.string().regex(/^[a-f0-9]{64}$/i, \"sha256 must be a 64-character hex digest\"),\n bytes: z.number().int().min(0),\n mtimeMs: z.number().finite().min(0).max(OFFLINE_SYNC_MAX_MTIME_MS),\n});\n\nconst offlineSyncBaseCapturedAtSchema = z\n .string()\n .trim()\n .min(1, \"baseCapturedAt must be non-empty when provided\")\n .max(64)\n .refine((value) => Number.isFinite(Date.parse(value)), {\n message: \"baseCapturedAt must be a valid ISO 8601 timestamp\",\n });\n\nexport const offlineSyncSnapshotRequestSchema = z.object({\n namespace: namespaceSchema,\n includeTranscripts: z.boolean().optional(),\n includeContent: z.boolean().optional(),\n baseCapturedAt: offlineSyncBaseCapturedAtSchema.optional(),\n baseFiles: z\n .array(offlineSyncFileStateSchema)\n .max(300_000, \"baseFiles must contain 300000 or fewer entries\")\n .optional(),\n});\n\nexport const offlineSyncApplyRequestSchema = z\n .object({\n namespace: namespaceSchema,\n changeset: z.unknown(),\n returnCurrentFiles: z.boolean().optional(),\n })\n .refine((value) => value.changeset !== undefined && value.changeset !== null, {\n message: \"changeset is required\",\n path: [\"changeset\"],\n });\n\nexport const offlineSyncFilesRequestSchema = z.object({\n namespace: namespaceSchema,\n includeTranscripts: z.boolean().optional(),\n paths: z\n .array(offlineSyncPathSchema)\n .max(5000, \"paths must contain 5000 or fewer entries\"),\n});\n\nexport const offlineSyncFileContentRequestSchema = z.object({\n namespace: namespaceSchema,\n includeTranscripts: z.boolean().optional(),\n path: offlineSyncPathSchema,\n offset: z.number().int().min(0).optional(),\n length: z.number().int().min(1).max(OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES).optional(),\n});\n\n// ---------------------------------------------------------------------------\n// Action confidence\n// ---------------------------------------------------------------------------\n\nconst nullableOptional = <T extends z.ZodTypeAny>(schema: T) =>\n schema.optional().nullable().transform((value) => value ?? undefined);\n\nconst actionConfidenceRuleSchema = z\n .object({\n kind: z.enum(ACTION_CONFIDENCE_RULE_KINDS),\n description: nullableOptional(z.string().trim().min(1).max(2000)),\n matched: nullableOptional(z.boolean()),\n })\n .strict();\n\nconst actionConfidenceMemorySchema = z\n .object({\n source: nullableOptional(z.string().trim().min(1).max(256)),\n created: nullableOptional(z.string().trim().min(1).max(128)),\n updated: nullableOptional(z.string().trim().min(1).max(128)),\n scope: nullableOptional(z.string().trim().min(1).max(512)),\n userContextScopes: nullableOptional(z.array(z.string().trim().min(1).max(128)).max(50)),\n retrievalReason: nullableOptional(z.string().trim().min(1).max(2000)),\n confidence: nullableOptional(z.number().min(0).max(1)),\n stale: nullableOptional(z.boolean()),\n corrected: nullableOptional(z.boolean()),\n correctionState: nullableOptional(z.enum([\"none\", \"correction\", \"superseded\", \"disputed\", \"forgotten\"])),\n safeToUse: nullableOptional(z.boolean()),\n safety: nullableOptional(z.enum([\"safe\", \"requires-review\", \"blocked\"])),\n safetyReasons: nullableOptional(z.array(z.string().trim().min(1).max(1000)).max(50)),\n })\n .strict();\n\nexport const actionConfidenceRequestSchema = z\n .object({\n intendedAction: nullableOptional(z.string().trim().min(1).max(1000)),\n confidence: nullableOptional(z.number().min(0).max(1)),\n risk: nullableOptional(z.enum(ACTION_CONFIDENCE_RISK_CATEGORIES)),\n contextReadiness: nullableOptional(z.enum(ACTION_CONFIDENCE_CONTEXT_READINESS)),\n currentContextScopes: nullableOptional(z.array(z.string().trim().min(1).max(128)).max(50)),\n userRules: nullableOptional(z.array(actionConfidenceRuleSchema).max(100)),\n retrievedMemories: nullableOptional(z.array(actionConfidenceMemorySchema).max(200)),\n })\n .strict();\n\n// ---------------------------------------------------------------------------\n// Inferred types\n// ---------------------------------------------------------------------------\n\nexport type RecallRequest = z.infer<typeof recallRequestSchema>;\nexport type RecallExplainRequest = z.infer<typeof recallExplainRequestSchema>;\nexport type SetCodingContextRequest = z.infer<typeof setCodingContextRequestSchema>;\nexport type ObserveRequest = z.infer<typeof observeRequestSchema>;\nexport type MemoryStoreRequest = z.infer<typeof memoryStoreRequestSchema>;\nexport type SuggestionSubmitRequest = z.infer<typeof suggestionSubmitRequestSchema>;\nexport type ReviewDispositionRequest = z.infer<typeof reviewDispositionRequestSchema>;\nexport type TrustZonePromoteRequest = z.infer<typeof trustZonePromoteRequestSchema>;\nexport type TrustZoneDemoSeedRequest = z.infer<typeof trustZoneDemoSeedRequestSchema>;\nexport type LcmSearchRequest = z.infer<typeof lcmSearchRequestSchema>;\nexport type LcmCompactionFlushRequest = z.infer<typeof lcmCompactionFlushRequestSchema>;\nexport type LcmCompactionRecordRequest = z.infer<typeof lcmCompactionRecordRequestSchema>;\nexport type DaySummaryRequest = z.infer<typeof daySummaryRequestSchema>;\nexport type CapsuleExportRequest = z.infer<typeof capsuleExportRequestSchema>;\nexport type CapsuleImportRequest = z.infer<typeof capsuleImportRequestSchema>;\nexport type CapsuleListRequest = z.infer<typeof capsuleListRequestSchema>;\nexport type OfflineSyncApplyRequest = z.infer<typeof offlineSyncApplyRequestSchema>;\nexport type OfflineSyncSnapshotRequest = z.infer<typeof offlineSyncSnapshotRequestSchema>;\nexport type OfflineSyncFilesRequest = z.infer<typeof offlineSyncFilesRequestSchema>;\nexport type OfflineSyncFileContentRequest = z.infer<typeof offlineSyncFileContentRequestSchema>;\nexport type ActionConfidenceRequest = z.infer<typeof actionConfidenceRequestSchema>;\n\n// ---------------------------------------------------------------------------\n// Validation helper\n// ---------------------------------------------------------------------------\n\nexport type SchemaName =\n | \"recall\"\n | \"recallExplain\"\n | \"setCodingContext\"\n | \"observe\"\n | \"memoryStore\"\n | \"suggestionSubmit\"\n | \"reviewDisposition\"\n | \"trustZonePromote\"\n | \"trustZoneDemoSeed\"\n | \"lcmSearch\"\n | \"lcmCompactionFlush\"\n | \"lcmCompactionRecord\"\n | \"daySummary\"\n | \"capsuleExport\"\n | \"capsuleImport\"\n | \"capsuleList\"\n | \"offlineSyncSnapshot\"\n | \"offlineSyncFiles\"\n | \"offlineSyncFileContent\"\n | \"offlineSyncApply\"\n | \"actionConfidence\";\n\nexport type SchemaTypeFor<N extends SchemaName> =\n N extends \"recall\" ? RecallRequest\n : N extends \"recallExplain\" ? RecallExplainRequest\n : N extends \"setCodingContext\" ? SetCodingContextRequest\n : N extends \"observe\" ? ObserveRequest\n : N extends \"memoryStore\" ? MemoryStoreRequest\n : N extends \"suggestionSubmit\" ? SuggestionSubmitRequest\n : N extends \"reviewDisposition\" ? ReviewDispositionRequest\n : N extends \"trustZonePromote\" ? TrustZonePromoteRequest\n : N extends \"trustZoneDemoSeed\" ? TrustZoneDemoSeedRequest\n : N extends \"lcmSearch\" ? LcmSearchRequest\n : N extends \"lcmCompactionFlush\" ? LcmCompactionFlushRequest\n : N extends \"lcmCompactionRecord\" ? LcmCompactionRecordRequest\n : N extends \"daySummary\" ? DaySummaryRequest\n : N extends \"capsuleExport\" ? CapsuleExportRequest\n : N extends \"capsuleImport\" ? CapsuleImportRequest\n : N extends \"capsuleList\" ? CapsuleListRequest\n : N extends \"offlineSyncSnapshot\" ? OfflineSyncSnapshotRequest\n : N extends \"offlineSyncFiles\" ? OfflineSyncFilesRequest\n : N extends \"offlineSyncFileContent\" ? OfflineSyncFileContentRequest\n : N extends \"offlineSyncApply\" ? OfflineSyncApplyRequest\n : N extends \"actionConfidence\" ? ActionConfidenceRequest\n : never;\n\nconst schemas: Record<SchemaName, z.ZodTypeAny> = {\n recall: recallRequestSchema,\n recallExplain: recallExplainRequestSchema,\n setCodingContext: setCodingContextRequestSchema,\n observe: observeRequestSchema,\n memoryStore: memoryStoreRequestSchema,\n suggestionSubmit: suggestionSubmitRequestSchema,\n reviewDisposition: reviewDispositionRequestSchema,\n trustZonePromote: trustZonePromoteRequestSchema,\n trustZoneDemoSeed: trustZoneDemoSeedRequestSchema,\n lcmSearch: lcmSearchRequestSchema,\n lcmCompactionFlush: lcmCompactionFlushRequestSchema,\n lcmCompactionRecord: lcmCompactionRecordRequestSchema,\n daySummary: daySummaryRequestSchema,\n capsuleExport: capsuleExportRequestSchema,\n capsuleImport: capsuleImportRequestSchema,\n capsuleList: capsuleListRequestSchema,\n offlineSyncSnapshot: offlineSyncSnapshotRequestSchema,\n offlineSyncFiles: offlineSyncFilesRequestSchema,\n offlineSyncFileContent: offlineSyncFileContentRequestSchema,\n offlineSyncApply: offlineSyncApplyRequestSchema,\n actionConfidence: actionConfidenceRequestSchema,\n};\n\n/**\n * Validate a request body against the named schema.\n * Returns `{ success: true, data }` on pass or\n * `{ success: false, error }` on failure with field-level detail.\n */\nexport function validateRequest<T = unknown>(\n schemaName: SchemaName,\n body: unknown,\n): { success: true; data: T } | { success: false; error: SchemaValidationError } {\n const schema = schemas[schemaName];\n if (!schema) {\n return {\n success: false,\n error: {\n error: `unknown schema: ${schemaName}`,\n code: \"validation_error\",\n details: [],\n },\n };\n }\n const result = schema.safeParse(body);\n if (result.success) {\n return { success: true, data: result.data as T };\n }\n return { success: false, error: formatZodError(result.error) };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,SAAS,SAAS;AAwBX,SAAS,eAAe,OAA0C;AACvE,SAAO;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,IACN,SAAS,MAAM,OAAO,IAAI,CAAC,WAAW;AAAA,MACpC,OAAO,MAAM,KAAK,KAAK,GAAG,KAAK;AAAA,MAC/B,SAAS,MAAM;AAAA,IACjB,EAAE;AAAA,EACJ;AACF;AAMA,IAAM,kBAAkB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,SAAS;AAC5D,IAAM,mBAAmB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,SAAS;AACpE,IAAM,uBAAuB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,SAAS;AACxE,IAAM,eAAe,EAAE,QAAQ,EAAE,SAAS;AAC1C,IAAM,sBAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAY/C,IAAM,sBAAsB,EAChC,OAAO;AAAA,EACN,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,qCAAqC,EAAE,IAAI,GAAG;AA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T,OAAO;AAAA,QACL,OAAO,mBAAmB,UAAU;AAAA,QACpC,MAAM;AAAA,QACN,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAS,OAAO,UAAU,IAAI;AACpC,MAAI,OAAO,SAAS;AAClB,WAAO,EAAE,SAAS,MAAM,MAAM,OAAO,KAAU;AAAA,EACjD;AACA,SAAO,EAAE,SAAS,OAAO,OAAO,eAAe,OAAO,KAAK,EAAE;AAC/D;","names":[]}
@@ -30,7 +30,9 @@ import {
30
30
  } from "./chunk-5BTCT236.js";
31
31
  import {
32
32
  clusterByKey,
33
+ combineNamespaces,
33
34
  projectTagProjectId,
35
+ resolveCodingNamespaceOverlay,
34
36
  resolveGitContext
35
37
  } from "./chunk-EDQVAMQI.js";
36
38
  import {
@@ -71,7 +73,7 @@ import {
71
73
  persistExplicitCapture,
72
74
  queueExplicitCaptureForReview,
73
75
  validateExplicitCaptureInput
74
- } from "./chunk-EUML3N6B.js";
76
+ } from "./chunk-IMA6GU4Y.js";
75
77
  import {
76
78
  CrossNamespaceBudget
77
79
  } from "./chunk-ODPLEWB6.js";
@@ -664,6 +666,99 @@ var EngramAccessService = class {
664
666
  }
665
667
  return resolved;
666
668
  }
669
+ /**
670
+ * Resolve a coding context from `cwd`/`projectTag` WITHOUT persisting it to
671
+ * any session — the read-only half of `maybeAttachCodingContext`. Returns
672
+ * null when project scoping is off or nothing resolves. `projectTag` takes
673
+ * priority over `cwd` (matching `maybeAttachCodingContext`).
674
+ */
675
+ async resolveCodingContextFromOptions(options) {
676
+ if (!this.orchestrator.config.codingMode?.projectScope) return null;
677
+ if (typeof options.projectTag === "string" && options.projectTag.trim().length > 0) {
678
+ const projectId = projectTagProjectId(options.projectTag);
679
+ return { projectId, branch: null, rootPath: projectId, defaultBranch: null };
680
+ }
681
+ if (typeof options.cwd === "string" && options.cwd.trim().length > 0) {
682
+ try {
683
+ const gitCtx = await resolveGitContext(options.cwd);
684
+ if (gitCtx) {
685
+ return {
686
+ projectId: gitCtx.projectId,
687
+ branch: gitCtx.branch,
688
+ rootPath: gitCtx.rootPath,
689
+ defaultBranch: gitCtx.defaultBranch
690
+ };
691
+ }
692
+ } catch {
693
+ }
694
+ }
695
+ return null;
696
+ }
697
+ /**
698
+ * Resolve the write namespace for explicit-write tools (memory_store /
699
+ * suggestion_submit), project-scoping the write the same way recall does so a
700
+ * memory stored with a client-injected `cwd`/`projectTag` is discoverable by
701
+ * project-scoped recall (#1434, rule 42).
702
+ *
703
+ * Precedence:
704
+ * - An explicit `namespace` always wins and is authorized strictly via
705
+ * `resolveWritableNamespace` → `canWriteNamespace`. A coding-overlay
706
+ * namespace string (`<base>-project-*`) is NOT a writable target via the
707
+ * explicit field — project scoping is requested with `cwd`/`projectTag`,
708
+ * never by naming the derived namespace — so there is no way to bypass the
709
+ * policy allow-list by guessing/forging an overlay name (Codex review).
710
+ * - With NO coding overlay, the write stays on `config.defaultNamespace` —
711
+ * exactly the pre-#1434 behavior, so an unqualified write is NOT silently
712
+ * moved to a principal self namespace (Codex review).
713
+ * - WITH a coding overlay, the base is the principal self namespace
714
+ * (`defaultNamespaceForPrincipal`, write-checked) — the SAME base recall,
715
+ * observe, and the orchestrator buffer-flush write path overlay onto
716
+ * (rule 42 / Cursor) — so a project-scoped store lands exactly where
717
+ * project-scoped recall searches. The overlay namespace is always REBUILT
718
+ * from the authenticated principal's base, never accepted as a caller
719
+ * string, so a caller can never reach another principal's subtree.
720
+ *
721
+ * Read-only: this NEVER mutates session coding context, so the idempotency
722
+ * peeks and dryRun preflights that call it stay side-effect free (Codex
723
+ * review). It prefers the per-call `cwd`/`projectTag` (the project explicitly
724
+ * identified for this write), else the session's existing context. The HTTP
725
+ * surface lets the peek and the write each resolve independently; the peek's
726
+ * namespace only gates rate-limiting (memory_store/suggestion_submit run their
727
+ * own idempotency check), so a benign session-context change between the two
728
+ * never fails a write — there is no namespace to "pin".
729
+ */
730
+ async resolveCodingScopedWriteNamespace(request) {
731
+ const hasExplicitNamespace = typeof request.namespace === "string" && request.namespace.trim().length > 0;
732
+ if (hasExplicitNamespace) {
733
+ return this.resolveWritableNamespace(
734
+ request.namespace,
735
+ request.sessionKey,
736
+ request.authenticatedPrincipal
737
+ );
738
+ }
739
+ const hasSession = typeof request.sessionKey === "string" && request.sessionKey.length > 0;
740
+ const overlay = hasSession && this.orchestrator.config.namespacesEnabled && this.orchestrator.config.codingMode?.projectScope ? resolveCodingNamespaceOverlay(
741
+ this.orchestrator.getCodingContextForSession(request.sessionKey) ?? await this.resolveCodingContextFromOptions(request),
742
+ this.orchestrator.config.codingMode,
743
+ this.orchestrator.config.defaultNamespace
744
+ ) : null;
745
+ if (!overlay) {
746
+ return this.resolveWritableNamespace(
747
+ void 0,
748
+ request.sessionKey,
749
+ request.authenticatedPrincipal
750
+ );
751
+ }
752
+ const principal = this.resolveRequestPrincipal(
753
+ request.sessionKey,
754
+ request.authenticatedPrincipal
755
+ );
756
+ const base = defaultNamespaceForPrincipal(principal, this.orchestrator.config);
757
+ if (!canWriteNamespace(principal, base, this.orchestrator.config)) {
758
+ throw new EngramAccessInputError(`namespace is not writable: ${base}`);
759
+ }
760
+ return combineNamespaces(base, overlay.namespace);
761
+ }
667
762
  async objectiveStateStoreLocationForNamespace(namespace) {
668
763
  if (!this.orchestrator.config.namespacesEnabled) {
669
764
  return {
@@ -858,6 +953,7 @@ var EngramAccessService = class {
858
953
  }
859
954
  const key = options.idempotencyKey?.trim();
860
955
  if (!key) {
956
+ if (options.beforeExecute) await options.beforeExecute();
861
957
  return options.execute();
862
958
  }
863
959
  return this.withIdempotencyLock(key, async () => {
@@ -876,6 +972,7 @@ var EngramAccessService = class {
876
972
  idempotencyReplay: true
877
973
  };
878
974
  }
975
+ if (options.beforeExecute) await options.beforeExecute();
879
976
  const response = await options.execute();
880
977
  await this.idempotency.put(key, requestHash, response);
881
978
  return response;
@@ -1148,6 +1245,24 @@ var EngramAccessService = class {
1148
1245
  }
1149
1246
  }
1150
1247
  }
1248
+ /**
1249
+ * Seed the session's coding binding AFTER a committed, project-scoped explicit
1250
+ * write (memory_store / suggestion_submit), mirroring the recall path's
1251
+ * `maybeAttachCodingContext` so a later bare recall/write on the same session
1252
+ * is scoped to the same project. Called only from the post-persist path, so it
1253
+ * never fires on dryRun, replay/conflict, or quota-rejected requests. Skips
1254
+ * when an explicit `namespace` was supplied — that write bypassed the coding
1255
+ * overlay, so binding the session to a project it never wrote to would make
1256
+ * later bare recalls miss (Codex review).
1257
+ */
1258
+ async attachCodingContextAfterScopedWrite(request) {
1259
+ const hasExplicitNamespace = typeof request.namespace === "string" && request.namespace.trim().length > 0;
1260
+ if (hasExplicitNamespace) return;
1261
+ await this.maybeAttachCodingContext(request.sessionKey, {
1262
+ cwd: request.cwd,
1263
+ projectTag: request.projectTag
1264
+ });
1265
+ }
1151
1266
  async recall(request) {
1152
1267
  const query = request.query.trim();
1153
1268
  if (query.length === 0) {
@@ -1696,12 +1811,8 @@ var EngramAccessService = class {
1696
1811
  // shares it, and so separate services in the same process (e.g.
1697
1812
  // per-tenant) do not block each other.
1698
1813
  xrayQueue = Promise.resolve();
1699
- async memoryStore(request) {
1700
- const namespace = this.resolveWritableNamespace(
1701
- request.namespace,
1702
- request.sessionKey,
1703
- request.authenticatedPrincipal
1704
- );
1814
+ async memoryStore(request, hooks) {
1815
+ const namespace = await this.resolveCodingScopedWriteNamespace(request);
1705
1816
  const schemaVersion = request.schemaVersion ?? ENGRAM_ACCESS_WRITE_SCHEMA_VERSION;
1706
1817
  if (schemaVersion !== ENGRAM_ACCESS_WRITE_SCHEMA_VERSION) {
1707
1818
  throw new EngramAccessInputError(`unsupported schemaVersion: ${schemaVersion}`);
@@ -1721,6 +1832,7 @@ var EngramAccessService = class {
1721
1832
  };
1722
1833
  }
1723
1834
  const result = await persistExplicitCapture(this.orchestrator, candidate, "memory_store");
1835
+ await this.attachCodingContextAfterScopedWrite(request);
1724
1836
  const response = {
1725
1837
  schemaVersion: ENGRAM_ACCESS_WRITE_SCHEMA_VERSION,
1726
1838
  operation: "memory_store",
@@ -1753,15 +1865,12 @@ var EngramAccessService = class {
1753
1865
  sourceReason: request.sourceReason
1754
1866
  },
1755
1867
  skip: request.dryRun === true,
1868
+ beforeExecute: hooks?.enforceWriteQuota,
1756
1869
  execute
1757
1870
  });
1758
1871
  }
1759
1872
  async peekMemoryStoreIdempotency(request) {
1760
- const namespace = this.resolveWritableNamespace(
1761
- request.namespace,
1762
- request.sessionKey,
1763
- request.authenticatedPrincipal
1764
- );
1873
+ const namespace = await this.resolveCodingScopedWriteNamespace(request);
1765
1874
  const schemaVersion = request.schemaVersion ?? ENGRAM_ACCESS_WRITE_SCHEMA_VERSION;
1766
1875
  if (schemaVersion !== ENGRAM_ACCESS_WRITE_SCHEMA_VERSION) {
1767
1876
  throw new EngramAccessInputError(`unsupported schemaVersion: ${schemaVersion}`);
@@ -1783,12 +1892,8 @@ var EngramAccessService = class {
1783
1892
  skip: request.dryRun === true
1784
1893
  });
1785
1894
  }
1786
- async suggestionSubmit(request) {
1787
- const namespace = this.resolveWritableNamespace(
1788
- request.namespace,
1789
- request.sessionKey,
1790
- request.authenticatedPrincipal
1791
- );
1895
+ async suggestionSubmit(request, hooks) {
1896
+ const namespace = await this.resolveCodingScopedWriteNamespace(request);
1792
1897
  const schemaVersion = request.schemaVersion ?? ENGRAM_ACCESS_WRITE_SCHEMA_VERSION;
1793
1898
  if (schemaVersion !== ENGRAM_ACCESS_WRITE_SCHEMA_VERSION) {
1794
1899
  throw new EngramAccessInputError(`unsupported schemaVersion: ${schemaVersion}`);
@@ -1813,6 +1918,7 @@ var EngramAccessService = class {
1813
1918
  "suggestion_submit",
1814
1919
  new Error(request.sourceReason?.trim() || "submitted via engram suggestion_submit")
1815
1920
  );
1921
+ await this.attachCodingContextAfterScopedWrite(request);
1816
1922
  const response = {
1817
1923
  schemaVersion: ENGRAM_ACCESS_WRITE_SCHEMA_VERSION,
1818
1924
  operation: "suggestion_submit",
@@ -1845,15 +1951,12 @@ var EngramAccessService = class {
1845
1951
  sourceReason: request.sourceReason
1846
1952
  },
1847
1953
  skip: request.dryRun === true,
1954
+ beforeExecute: hooks?.enforceWriteQuota,
1848
1955
  execute
1849
1956
  });
1850
1957
  }
1851
1958
  async peekSuggestionSubmitIdempotency(request) {
1852
- const namespace = this.resolveWritableNamespace(
1853
- request.namespace,
1854
- request.sessionKey,
1855
- request.authenticatedPrincipal
1856
- );
1959
+ const namespace = await this.resolveCodingScopedWriteNamespace(request);
1857
1960
  const schemaVersion = request.schemaVersion ?? ENGRAM_ACCESS_WRITE_SCHEMA_VERSION;
1858
1961
  if (schemaVersion !== ENGRAM_ACCESS_WRITE_SCHEMA_VERSION) {
1859
1962
  throw new EngramAccessInputError(`unsupported schemaVersion: ${schemaVersion}`);
@@ -1877,13 +1980,21 @@ var EngramAccessService = class {
1877
1980
  }
1878
1981
  validateWriteCandidate(request, namespace) {
1879
1982
  try {
1880
- return validateExplicitCaptureInput(
1881
- {
1882
- ...request,
1883
- namespace
1884
- },
1885
- "legacy_tool"
1886
- );
1983
+ return {
1984
+ ...validateExplicitCaptureInput(
1985
+ {
1986
+ ...request,
1987
+ namespace
1988
+ },
1989
+ "legacy_tool"
1990
+ ),
1991
+ // The namespace was resolved AND authorized by
1992
+ // resolveCodingScopedWriteNamespace (explicit namespaces via
1993
+ // resolveWritableNamespace; otherwise an auth-checked base + a
1994
+ // session-owned project overlay), so the persist/queue layer must not
1995
+ // re-reject a legitimately-derived dynamic project namespace (#1434).
1996
+ namespacePreResolved: true
1997
+ };
1887
1998
  } catch (error) {
1888
1999
  const message = error instanceof Error ? error.message : String(error);
1889
2000
  throw new EngramAccessInputError(message);
@@ -4238,4 +4349,4 @@ export {
4238
4349
  shapeMemorySummary,
4239
4350
  EngramAccessService
4240
4351
  };
4241
- //# sourceMappingURL=chunk-ADNZVFXG.js.map
4352
+ //# sourceMappingURL=chunk-ZK32E74R.js.map