@lorekit/cli 1.22.0 → 1.23.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 +3 -3
- package/bin/lorekit.mjs +6 -6
- package/package.json +1 -1
- package/src/mcp-server.mjs +6 -4
- package/src/store/remote.mjs +77 -63
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
221
|
-
|
|
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
|
|
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
package/src/mcp-server.mjs
CHANGED
|
@@ -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
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// a
|
|
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
|
package/src/store/remote.mjs
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
// Remote store: wraps the LoreKit REST API
|
|
2
|
-
//
|
|
3
|
-
// read, write, delete (soft-archive AND `?force=true` hard-delete)
|
|
4
|
-
// store-wide `listScopes()` enumeration
|
|
5
|
-
//
|
|
6
|
-
// `
|
|
7
|
-
//
|
|
8
|
-
//
|
|
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 {
|
|
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
|
-
|
|
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
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
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.
|
|
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
|
-
|
|
134
|
-
|
|
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.
|
|
142
|
-
return
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
184
|
-
|
|
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
|
-
|
|
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
|
}
|