@lorekit/cli 1.22.0 → 1.24.0

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/README.md CHANGED
@@ -116,7 +116,7 @@ and `global`) — split into two clearly-labelled sections so you can see where
116
116
  each lesson lives:
117
117
 
118
118
  - **Offline** — the local two-tier store (`.lorekit/` in the repo + `~/.lorekit/`).
119
- - **Remote** — the hosted MCP store. When no token/endpoint is configured this
119
+ - **Remote** — the hosted LoreKit store, reached over the REST API. When no token/endpoint is configured this
120
120
  section is a short note on how to set it up; it is **never an error** (the
121
121
  command still exits 0 and shows your offline lessons). A network/server error
122
122
  is likewise a per-scope warning, not a crash.
@@ -192,7 +192,7 @@ which is the point of an overview). An unconfigured remote degrades to a short
192
192
  note — never an error, always exit 0. `--endpoint` / `--token` / `--store`
193
193
  behave as in `list`. Remote counts reflect what the hosted `memory.list` returns
194
194
  per scope (the server's default page size); there is no cap-usage `N / limit`
195
- figure because the MCP surface exposes no total-count or cap tool.
195
+ figure because the REST API exposes no total-count or cap endpoint.
196
196
 
197
197
  ### `lorekit scopes`
198
198
 
@@ -367,7 +367,7 @@ Memory has a controllable backend. Three **modes**:
367
367
  |------|--------------------|-------|
368
368
  | `off` | nowhere | Memory is disabled — every hook event and store op is a silent no-op. |
369
369
  | `local` | markdown files in two tiers (see below) | **Local means _not_ on the hosted website** — local lessons never sync to the LoreKit dashboard. That is the point of local: private-by-default, greppable, git-native. |
370
- | `remote` | the LoreKit MCP server (hosted) | The shared, cross-machine backend. Reads stay silent until an endpoint + token are configured. This is the default. |
370
+ | `remote` | the hosted LoreKit API (REST) | The shared, cross-machine backend. Reads stay silent until an endpoint + token are configured. This is the default. |
371
371
 
372
372
  ### Local store layout — two tiers
373
373
 
package/bin/lorekit.mjs CHANGED
@@ -45,10 +45,10 @@ ${c.bold('Commands')}
45
45
  the MCP server entry, and the lifecycle hooks for the chosen scope. Surgical —
46
46
  other servers, hooks, and settings are left untouched. Prompts
47
47
  project vs global; --project / --global choose non-interactively.
48
- doctor Verify the skill install, MCP connectivity, token, and scope.
48
+ doctor Verify the skill install, remote connectivity, token, and scope.
49
49
  list (ls) List the memories that apply to the current directory, split into
50
50
  an Offline section (local .lorekit/ + ~/.lorekit/) and a Remote
51
- section (hosted MCP). Groups by scope (project/branch/repo/global).
51
+ section (the hosted LoreKit API). Groups by scope (project/branch/repo/global).
52
52
  --json for scripting, --scope <s> to narrow.
53
53
  search Full-text search the applicable memories across both stores and all
54
54
  (grep) scopes (case-insensitive, literal substring over key + value),
@@ -194,7 +194,7 @@ ${c.bold('Examples')}
194
194
  ${c.bold('Usage')}
195
195
  npx @lorekit/cli doctor [options]
196
196
 
197
- Checks the node runtime, skill install, resolved memory mode, MCP connectivity,
197
+ Checks the node runtime, skill install, resolved memory mode, remote connectivity,
198
198
  token, and scope.
199
199
 
200
200
  ${c.bold('Options')}
@@ -217,8 +217,8 @@ ${c.bold('Usage')}
217
217
 
218
218
  Shows the memories for the scopes that resolve for the current directory
219
219
  (project/branch/repo/global), split into an Offline section (the local
220
- .lorekit/ + ~/.lorekit/ two-tier store) and a Remote section (the hosted MCP
221
- server). When no remote token/endpoint is configured the Remote section is a
220
+ .lorekit/ + ~/.lorekit/ two-tier store) and a Remote section (the hosted LoreKit
221
+ API). When no remote token/endpoint is configured the Remote section is a
222
222
  short note on how to set it up — never an error.
223
223
 
224
224
  ${c.bold('Options')}
@@ -320,7 +320,7 @@ ${c.bold('Usage')}
320
320
 
321
321
  Shows how many memories apply to the current directory's scopes (project/branch/
322
322
  repo/global), broken down per scope and per store (Offline = the local .lorekit/
323
- + ~/.lorekit/ two-tier store; Remote = the hosted MCP server), with per-store and
323
+ + ~/.lorekit/ two-tier store; Remote = the hosted LoreKit API), with per-store and
324
324
  grand totals. An unconfigured remote degrades to a short note, never an error.
325
325
 
326
326
  ${c.bold('Options')}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorekit/cli",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "description": "Install the LoreKit shared-memory skill and run health checks for the LoreKit MCP server.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,10 +11,12 @@
11
11
  // off → advertise no tools; a call reports "disabled"
12
12
  //
13
13
  // org.* tools are always advertised regardless of memory mode. They proxy to
14
- // the remote endpoint because org management requires a server-side session
15
- // (JWT auth, SECURITY DEFINER RPCs). In local/off mode a transient RemoteStore
16
- // is built from the configured endpoint + token. If no remote is configured,
17
- // a clear error is returned.
14
+ // the remote endpoint because orgs are server-side state — there is no local
15
+ // equivalent to serve them from. (They no longer require a Supabase JWT: the
16
+ // store calls the REST `/orgs` routes, which accept `lk_*` API tokens as of
17
+ // 00041_org_actor_override.sql.) In local/off mode a transient RemoteStore is
18
+ // built from the configured endpoint + token. If no remote is configured, a
19
+ // clear error is returned.
18
20
  //
19
21
  // Machine-facing: ONLY JSON-RPC frames go to stdout — any diagnostics go to
20
22
  // stderr. The server never throws on malformed or partial input; a bad frame
@@ -1,13 +1,24 @@
1
- // Remote store: wraps the LoreKit REST API `memory.*` endpoints behind the
2
- // common store contract. EVERY memory operation goes over REST — list, search,
3
- // read, write, delete (soft-archive AND `?force=true` hard-delete) and the
4
- // store-wide `listScopes()` enumeration for lower overhead and W3C
5
- // traceparent propagation. MCP remains ONLY for the four `org.*` calls and the
6
- // `ping` fallback: org RPCs require a Supabase JWT session (they resolve the
7
- // actor via auth.uid() inside SECURITY DEFINER functions), which is
8
- // incompatible with the lk_* api_key tokens that CLI users have.
1
+ // Remote store: wraps the LoreKit REST API behind the common store contract.
2
+ // EVERY operation this store performs goes over REST — memory list, search,
3
+ // read, write, delete (soft-archive AND `?force=true` hard-delete), the
4
+ // store-wide `listScopes()` enumeration, all four `org.*` operations, and the
5
+ // `ping` connectivity probe. There is NO MCP transport left here: the store
6
+ // imports `restFetch`/`mcpToRestBase` and nothing else.
7
+ //
8
+ // Org ops used to be the one holdout. The org RPCs resolved their actor from
9
+ // `auth.uid()`, which is NULL on the service-role connection an `lk_*` api_key
10
+ // token gets, so `/orgs` 403'd every CLI caller and the store had to keep a
11
+ // JSON-RPC transport alive purely for `org.create`/`org.list`/`org.rename`/
12
+ // `org.delete`. `00041_org_actor_override.sql` added a `p_actor_user_id`
13
+ // override that the RPCs honour only on a verified service_role connection,
14
+ // and the `orgs` edge function now passes it plus its own tenant filters — so
15
+ // every `/orgs*` route serves api_key tokens and the holdout is gone.
16
+ //
17
+ // `packages/cli/src/mcp.mjs` still exists and is still used: it backs the
18
+ // `lorekit mcp` stdio server command and provides `mcpToRestBase`. It is just
19
+ // no longer a transport for this store.
9
20
  // Zero-dependency.
10
- import { mcpCall, restFetch, mcpToRestBase } from '../mcp.mjs';
21
+ import { restFetch, mcpToRestBase } from '../mcp.mjs';
11
22
  import { getActiveTraceparent } from '../telemetry.mjs';
12
23
 
13
24
  // Drop undefined/null args so JSON payloads stay tidy.
@@ -23,7 +34,12 @@ export function createRemoteStore({ endpoint, token } = {}) {
23
34
 
24
35
  class RemoteStore {
25
36
  constructor(endpoint, token) {
26
- this.endpoint = endpoint; // MCP URL (kept for org ops)
37
+ // The configured endpoint is still spelled as the `/mcp` URL (that is what
38
+ // `.mcp.json` / LOREKIT_MCP_URL hold, and changing that config key is a
39
+ // separate migration). Nothing here speaks MCP: it exists only so
40
+ // `usable()` can judge the configuration and `mcpToRestBase` can derive the
41
+ // REST base from it.
42
+ this.endpoint = endpoint;
27
43
  this.token = token;
28
44
  this.restBase = mcpToRestBase(endpoint); // REST base URL for memory ops
29
45
  this.mode = 'remote';
@@ -40,22 +56,6 @@ class RemoteStore {
40
56
  return restFetch(this.restBase, this.token, path, { ...opts, traceparent: this._tp() });
41
57
  }
42
58
 
43
- async _mcp(name, args) {
44
- if (!this.usable()) return { ok: false, unusable: true };
45
- return mcpCall(this.endpoint, this.token, 'tools/call', { name, arguments: args }, { traceparent: this._tp() });
46
- }
47
-
48
- _mcpEntries(res) {
49
- if (!res.ok) return { ok: false, error: res.error, networkError: res.networkError };
50
- // MCP wraps results in { content: [{ type: 'text', text: '<json>' }] }
51
- let payload = null;
52
- if (Array.isArray(res.result?.content)) {
53
- const text = res.result.content.map((c) => c?.text ?? '').join('');
54
- try { payload = JSON.parse(text); } catch { /* ignore */ }
55
- } else { payload = res.result; }
56
- return { ok: true, entries: Array.isArray(payload?.entries) ? payload.entries : [] };
57
- }
58
-
59
59
  // ── Memory operations → REST ──────────────────────────────────────────────
60
60
 
61
61
  async list({ scope, tags, limit } = {}) {
@@ -119,43 +119,54 @@ class RemoteStore {
119
119
  return this.delete({ scope, key, force: false });
120
120
  }
121
121
 
122
- // ── Org operations ─────────────────────────────────────────────────────────
123
- // Org RPCs (lorekit_org_*) use auth.uid() server-side via SECURITY DEFINER
124
- // functions, which only works with a Supabase JWT session. CLI uses lk_*
125
- // api_key tokens which provide no JWT context, so the REST /orgs endpoint
126
- // returns 403 for api_key callers. Org ops stay on the MCP endpoint which
127
- // handles this correctly (the Deno edge function has its own auth path).
128
- // TODO: if org RPCs ever gain api_key support, switch these to REST too.
129
-
122
+ // ── Org operations → REST ─────────────────────────────────────────────────
123
+ // `supabase/functions/orgs/` serves `lk_*` tokens on every route as of
124
+ // 00041_org_actor_override.sql (see the file header). Each method's RETURN
125
+ // SHAPE is unchanged from the MCP era `packages/cli/src/mcp-server.mjs`
126
+ // serialises these objects straight into a `tools/call` result, so the shape
127
+ // is a published contract, not an internal detail.
128
+ //
129
+ // Slugs are interpolated into the PATH, so they must be encodeURIComponent'd.
130
+ // A slug is server-side constrained to `[a-z0-9-]`, but the CLI passes
131
+ // whatever the user typed and an un-encoded `../` or `?` would retarget the
132
+ // request at a different route entirely.
133
+
134
+ // POST /orgs → 201 with the created org object, `{ id, slug, name, created_at }`.
135
+ // The handler reads the row back after the RPC (`orgs/handlers/orgs/create.ts`);
136
+ // `created_at` is absent only on the read-back miss, where it falls back to
137
+ // `{ id, slug, name }`. A bare JSON id string is the LEGACY shape an older
138
+ // deployed backend can still return — that is what the string branch below is
139
+ // for, not the normal case. Either way this method reassembles the
140
+ // `{ id, slug, name }` triple, because `packages/cli/src/mcp-server.mjs`
141
+ // serialises it straight into a `tools/call` result and that shape is a
142
+ // published contract.
130
143
  async orgCreate({ slug, name } = {}) {
131
- const res = await this._mcp('org.create', { slug, name });
144
+ const res = await this._rest('/orgs', { method: 'POST', body: { slug, name } });
132
145
  if (!res.ok) return { ok: false, error: res.error, networkError: res.networkError };
133
- let payload = null;
134
- if (Array.isArray(res.result?.content)) {
135
- try { payload = JSON.parse(res.result.content.map((c) => c?.text ?? '').join('')); } catch {}
136
- } else { payload = res.result; }
137
- return { ok: true, org: payload };
146
+ const id = typeof res.data === 'string' ? res.data : (res.data?.id ?? null);
147
+ return { ok: true, org: { id, slug, name } };
138
148
  }
139
149
 
150
+ // GET /orgs → { entries: [{ id, slug, name, role, created_at }] }
140
151
  async orgList() {
141
- const res = await this._mcp('org.list', {});
142
- return this._mcpEntries(res);
152
+ const res = await this._rest('/orgs');
153
+ if (!res.ok) return { ok: false, error: res.error, networkError: res.networkError };
154
+ return { ok: true, entries: Array.isArray(res.data?.entries) ? res.data.entries : [] };
143
155
  }
144
156
 
157
+ // PATCH /orgs/:slug → 200 { slug, name }
145
158
  async orgRename({ slug, name } = {}) {
146
- const res = await this._mcp('org.rename', { slug, name });
159
+ const res = await this._rest(`/orgs/${encodeURIComponent(slug)}`, { method: 'PATCH', body: { name } });
147
160
  if (!res.ok) return { ok: false, error: res.error, networkError: res.networkError };
148
- let payload = null;
149
- try { payload = Array.isArray(res.result?.content) ? JSON.parse(res.result.content.map((c) => c?.text ?? '').join('')) : res.result; } catch {}
150
- return { ok: true, ...(payload ?? {}) };
161
+ return { ok: true, ...(res.data ?? { slug, name }) };
151
162
  }
152
163
 
164
+ // DELETE /orgs/:slug → 204 with no body, so `deleted: true` is synthesised to
165
+ // preserve the `{ ok, deleted, slug }` shape the MCP tool returned.
153
166
  async orgDelete({ slug } = {}) {
154
- const res = await this._mcp('org.delete', { slug });
167
+ const res = await this._rest(`/orgs/${encodeURIComponent(slug)}`, { method: 'DELETE' });
155
168
  if (!res.ok) return { ok: false, error: res.error, networkError: res.networkError };
156
- let payload = null;
157
- try { payload = Array.isArray(res.result?.content) ? JSON.parse(res.result.content.map((c) => c?.text ?? '').join('')) : res.result; } catch {}
158
- return { ok: true, ...(payload ?? {}) };
169
+ return { ok: true, deleted: true, slug };
159
170
  }
160
171
 
161
172
  // Store-wide scope enumeration — every distinct scope the caller can see with
@@ -177,22 +188,25 @@ class RemoteStore {
177
188
  }
178
189
 
179
190
  // Connectivity probe for doctor — a transport check, not a memory op.
191
+ //
192
+ // There is no MCP fallback: a `restBase` we could not derive means the
193
+ // configured endpoint is not a URL, and a JSON-RPC POST to that same
194
+ // unparseable string could only fail in a less legible way. Report the
195
+ // configuration problem instead.
180
196
  async ping() {
181
197
  if (!this.usable()) return { ok: false, unusable: true };
182
198
  // Use the /health function as a connectivity probe (public, no auth)
183
- const healthUrl = this.restBase
184
- ? `${this.restBase.replace(/\/functions\/v1$/, '')}/functions/v1/health`
185
- : null;
186
- if (healthUrl) {
187
- const tp = this._tp();
188
- try {
189
- const res = await fetch(healthUrl, {
190
- signal: AbortSignal.timeout(5000),
191
- ...(tp ? { headers: { traceparent: tp } } : {}),
192
- });
193
- return { ok: res.ok, httpStatus: res.status };
194
- } catch (e) { return { ok: false, networkError: String(e?.message ?? e) }; }
199
+ if (!this.restBase) {
200
+ return { ok: false, error: { message: `Endpoint is not a valid URL: ${this.endpoint}` } };
195
201
  }
196
- return mcpCall(this.endpoint, this.token, 'tools/list', {}, { traceparent: this._tp() });
202
+ const healthUrl = `${this.restBase.replace(/\/functions\/v1$/, '')}/functions/v1/health`;
203
+ const tp = this._tp();
204
+ try {
205
+ const res = await fetch(healthUrl, {
206
+ signal: AbortSignal.timeout(5000),
207
+ ...(tp ? { headers: { traceparent: tp } } : {}),
208
+ });
209
+ return { ok: res.ok, httpStatus: res.status };
210
+ } catch (e) { return { ok: false, networkError: String(e?.message ?? e) }; }
197
211
  }
198
212
  }
package/src/telemetry.mjs CHANGED
@@ -32,7 +32,9 @@ import { readLorekitJson } from './config.mjs';
32
32
  // (empty in the source tree, so default export stays off until built/injected).
33
33
  const DEFAULT_ENDPOINT = 'https://ingress.europe-west4.gcp.dash0-dev.com';
34
34
  const DEFAULT_TOKEN = TELEMETRY_TOKEN; // injected from LOREKIT_TELEMETRY_TOKEN at publish
35
- const DEFAULT_DATASET = '';
35
+ // Ship to the `default` Dash0 dataset unless `DASH0_DATASET` overrides it, so
36
+ // CLI telemetry lands alongside every other LoreKit component (all `default`).
37
+ const DEFAULT_DATASET = 'default';
36
38
 
37
39
  // Flags worth counting (e.g. how many installs are --global). Bounded on
38
40
  // purpose: only these booleans are ever attached, never free-form values.
@@ -125,8 +127,17 @@ export function resolveTelemetryConfig(env = process.env, repoConfig) {
125
127
  return { enabled: false };
126
128
  }
127
129
 
128
- const dataset = env.DASH0_DATASET || DEFAULT_DATASET;
129
- if (dataset) headers['Dash0-Dataset'] = dataset;
130
+ // Dataset routing, highest precedence first: an explicit `Dash0-Dataset`
131
+ // already parsed from OTEL_EXPORTER_OTLP_HEADERS wins and is never clobbered;
132
+ // otherwise DASH0_DATASET; otherwise the baked-in DEFAULT_DATASET (`default`).
133
+ // HTTP header names are case-insensitive, so match any casing the caller used
134
+ // (e.g. `dash0-dataset`) rather than only the canonical spelling — otherwise a
135
+ // second, conflicting header would be appended.
136
+ const hasDataset = Object.keys(headers).some((k) => k.toLowerCase() === 'dash0-dataset');
137
+ if (!hasDataset) {
138
+ const dataset = env.DASH0_DATASET || DEFAULT_DATASET;
139
+ if (dataset) headers['Dash0-Dataset'] = dataset;
140
+ }
130
141
 
131
142
  return { enabled: true, endpoint, headers };
132
143
  }
@@ -156,7 +167,7 @@ function toOtlpAttributes(attributes) {
156
167
 
157
168
  function resourceAttributes(version) {
158
169
  return [
159
- { key: 'service.name', value: { stringValue: 'lorekit-cli' } },
170
+ { key: 'service.name', value: { stringValue: 'cli' } },
160
171
  { key: 'service.namespace', value: { stringValue: 'lorekit' } },
161
172
  { key: 'service.version', value: { stringValue: String(version) } },
162
173
  { key: 'process.runtime.name', value: { stringValue: 'nodejs' } },