@hasna/mementos 0.14.87 → 0.15.2

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 (88) hide show
  1. package/README.md +44 -9
  2. package/bun.lock +4 -62
  3. package/dist/cli/commands/info-history.d.ts.map +1 -1
  4. package/dist/cli/commands/info-stale.d.ts.map +1 -1
  5. package/dist/cli/commands/io-backup.d.ts.map +1 -1
  6. package/dist/cli/commands/io-export.d.ts.map +1 -1
  7. package/dist/cli/commands/io-restore.d.ts.map +1 -1
  8. package/dist/cli/commands/memory-cmd-chain.d.ts.map +1 -1
  9. package/dist/cli/commands/memory-cmd-crud.d.ts.map +1 -1
  10. package/dist/cli/commands/memory-cmd-recall.d.ts.map +1 -1
  11. package/dist/cli/commands/memory-cmd-search.d.ts.map +1 -1
  12. package/dist/cli/commands/memory-cmd-tail.d.ts.map +1 -1
  13. package/dist/cli/commands/memory-cmd-view.d.ts.map +1 -1
  14. package/dist/cli/commands/memory-cmd-when-to-use.d.ts.map +1 -1
  15. package/dist/cli/commands/storage.d.ts.map +1 -1
  16. package/dist/cli/commands/system-doctor.d.ts.map +1 -1
  17. package/dist/cli/commands/system-profile.d.ts.map +1 -1
  18. package/dist/cli/commands/system-status.d.ts +43 -0
  19. package/dist/cli/commands/system-status.d.ts.map +1 -0
  20. package/dist/cli/commands/system.d.ts.map +1 -1
  21. package/dist/cli/helpers.d.ts.map +1 -1
  22. package/dist/cli/index.js +3735 -2021
  23. package/dist/cli/register-all.d.ts +1 -1
  24. package/dist/cli/register-all.d.ts.map +1 -1
  25. package/dist/db/api-mode.d.ts +135 -37
  26. package/dist/db/api-mode.d.ts.map +1 -1
  27. package/dist/db/database.d.ts.map +1 -1
  28. package/dist/db/memories.d.ts.map +1 -1
  29. package/dist/db/pg-migrate.d.ts.map +1 -1
  30. package/dist/db/store-backend.d.ts +8 -2
  31. package/dist/db/store-backend.d.ts.map +1 -1
  32. package/dist/diagnostics/historical-project-registration-receipt.js +152 -11
  33. package/dist/generated/storage-kit/backend.d.ts +12 -2
  34. package/dist/generated/storage-kit/backend.d.ts.map +1 -1
  35. package/dist/generated/storage-kit/index.d.ts +1 -1
  36. package/dist/generated/storage-kit/index.d.ts.map +1 -1
  37. package/dist/generated/storage-kit/migrations.d.ts +21 -0
  38. package/dist/generated/storage-kit/migrations.d.ts.map +1 -1
  39. package/dist/generated/storage-kit/pool.d.ts +2 -5
  40. package/dist/generated/storage-kit/pool.d.ts.map +1 -1
  41. package/dist/generated/storage-kit/query.d.ts +1 -1
  42. package/dist/generated/storage-kit/query.d.ts.map +1 -1
  43. package/dist/index.d.ts +1 -2
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3057 -1266
  46. package/dist/lib/config.d.ts.map +1 -1
  47. package/dist/lib/env.d.ts +10 -0
  48. package/dist/lib/env.d.ts.map +1 -0
  49. package/dist/lib/gatherer.d.ts.map +1 -1
  50. package/dist/lib/local-opt-in.d.ts +114 -0
  51. package/dist/lib/local-opt-in.d.ts.map +1 -0
  52. package/dist/lib/model-config.d.ts +1 -1
  53. package/dist/lib/paths.d.ts +60 -0
  54. package/dist/lib/paths.d.ts.map +1 -0
  55. package/dist/lib/profile-sync.d.ts.map +1 -1
  56. package/dist/lib/redact.d.ts +70 -10
  57. package/dist/lib/redact.d.ts.map +1 -1
  58. package/dist/lib/reflection.d.ts.map +1 -1
  59. package/dist/lib/search.d.ts.map +1 -1
  60. package/dist/lib/storage-sync.d.ts.map +1 -1
  61. package/dist/lib/sync.d.ts.map +1 -1
  62. package/dist/mcp/index.d.ts.map +1 -1
  63. package/dist/mcp/index.js +3108 -1276
  64. package/dist/project-registration.js +378 -153
  65. package/dist/sdk/index.d.ts +173 -8
  66. package/dist/sdk/index.d.ts.map +1 -1
  67. package/dist/sdk/index.js +953 -12
  68. package/dist/server/auth.d.ts +2 -0
  69. package/dist/server/auth.d.ts.map +1 -1
  70. package/dist/server/helpers.d.ts +48 -3
  71. package/dist/server/helpers.d.ts.map +1 -1
  72. package/dist/server/index.d.ts.map +1 -1
  73. package/dist/server/index.js +3146 -1324
  74. package/dist/server/routes/system-synthesis.d.ts.map +1 -1
  75. package/dist/storage.d.ts +18 -0
  76. package/dist/storage.d.ts.map +1 -1
  77. package/dist/storage.js +149 -83
  78. package/dist/test-support/store-isolation.d.ts +50 -11
  79. package/dist/test-support/store-isolation.d.ts.map +1 -1
  80. package/docker-entrypoint.sh +7 -0
  81. package/hasna.contract.json +17 -5
  82. package/package.json +8 -8
  83. package/postinstall.mjs +85 -0
  84. package/dashboard/bun.lock +0 -519
  85. package/dist/cli/brains.d.ts +0 -3
  86. package/dist/cli/brains.d.ts.map +0 -1
  87. package/dist/lib/retired-storage-mode.d.ts +0 -11
  88. package/dist/lib/retired-storage-mode.d.ts.map +0 -1
@@ -1,4 +1,6 @@
1
1
  import { type ApiKeyVerifier } from "@hasna/contracts/auth";
2
+ /** True when {@link checkApiKey} verified an explicit API key on this request. */
3
+ export declare function isAuthenticated(req: Request): boolean;
2
4
  /** Lazily build the contracts verifier. Returns null when auth is disabled. */
3
5
  export declare function getApiKeyVerifier(): ApiKeyVerifier | null;
4
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAkBA,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAC;AA0C/B,+EAA+E;AAC/E,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAgCzD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,GACjC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAU1B;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAqBA,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAC;AAwB/B,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAErD;AAkCD,+EAA+E;AAC/E,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAuCzD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,GACjC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CA6B1B;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C"}
@@ -1,5 +1,52 @@
1
1
  export declare const CORS_HEADERS: Record<string, string>;
2
- export declare const MIME_TYPES: Record<string, string>;
2
+ /** True for methods that mutate state — the CSRF-relevant request surface. */
3
+ export declare function isStateChangingMethod(method: string): boolean;
4
+ /**
5
+ * The configured allowlist of origins permitted to mutate state.
6
+ *
7
+ * `MEMENTOS_CORS_ORIGIN` accepts a comma-separated list; each entry may be a
8
+ * full origin (`http://localhost:19428`) or a bare `host[:port]`. The default
9
+ * is the mementos server's own origin. An empty value yields an empty
10
+ * allowlist, which fails closed (no origin or host is allowed to mutate
11
+ * state).
12
+ */
13
+ export declare function getAllowedOrigins(): string[];
14
+ /**
15
+ * Reject state-changing requests whose Origin (when present) or Host (when no
16
+ * Origin is present) is not on the configured allowlist. Read-only methods
17
+ * pass through untouched. Returns an error `Response` to reject, or `null`.
18
+ *
19
+ * This is the non-OPTIONS sibling of the preflight gate: a hostile page can
20
+ * forge a POST/PATCH/DELETE with any Origin it likes, so those methods must
21
+ * be allowlisted on every request, not only at preflight time.
22
+ *
23
+ * `authenticated` marks a request whose API key was already verified (see
24
+ * auth.ts `checkApiKey`): such a request is not CSRF, so the ambient-credential
25
+ * gate is skipped for it when it carries no Origin header (the CLI/MCP/SDK
26
+ * client shape). See `checkWriteOriginOrHost`.
27
+ */
28
+ export declare function checkOriginOrHost(req: Request, method: string, authenticated?: boolean): Response | null;
29
+ /**
30
+ * The allowlist check itself: reject a request whose Origin (when present) or
31
+ * Host (when no Origin is present) is not on the configured allowlist.
32
+ *
33
+ * GET requests are CORS "simple requests" — a hostile cross-origin page can
34
+ * trigger one with no preflight — so a GET route whose handler writes state
35
+ * (a touch/recency update, a cache write, an LLM call) must be gated exactly
36
+ * like a state-changing method, even though its HTTP method is not one.
37
+ *
38
+ * `authenticated` exempts requests that carry a VERIFIED explicit API key and
39
+ * no Origin header. The allowlist is an ambient-credential (CSRF) defense: a
40
+ * hostile page cannot attach the Authorization header without CORS preflight
41
+ * (which is separately allowlisted) and cannot read the key, so a keyed
42
+ * request with no Origin is not CSRF and must be served regardless of
43
+ * MEMENTOS_CORS_ORIGIN — a deployment that omits the env var (or a client
44
+ * reaching the server through a Host the allowlist does not name) must not
45
+ * take down every CLI/MCP/SDK client with 403 'Host is not allowed'.
46
+ * Browser-context requests — any request WITH an Origin header — keep the
47
+ * full Origin allowlist even when keyed, as defense in depth.
48
+ */
49
+ export declare function checkWriteOriginOrHost(req: Request, authenticated?: boolean): Response | null;
3
50
  export declare function json(data: unknown, status?: number): Response;
4
51
  export declare function errorResponse(message: string, status: number, details?: unknown): Response;
5
52
  /**
@@ -17,6 +64,4 @@ export declare function readJson(req: Request): Promise<unknown>;
17
64
  export declare function getCorsHeaders(req?: Request): Record<string, string>;
18
65
  export declare function authenticateRequest(req: Request): Response | null;
19
66
  export declare function getSearchParams(url: URL): Record<string, string>;
20
- export declare function resolveDashboardDir(): string;
21
- export declare function serveStaticFile(filePath: string): Response | null;
22
67
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/server/helpers.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,EAAE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,CA4L9C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AA6CH,OAAO,sBAAsB,CAAC;AAC9B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,sBAAsB,CAAC;AAC9B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,oBAAoB,CAAC;AA8F5B,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAqM9C"}