@knolo/cli 6.2.8 → 6.2.10

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
@@ -19,9 +19,9 @@ reader.
19
19
 
20
20
  `knolo compose`, `knolo attest`, and `knolo verify-attestation` cite local
21
21
  Knowledge Images and write an attestation sidecar. This tree's `@knolo/cli`
22
- package file is `6.2.7` and depends on `@knolo/core` `^6.2.3` and
23
- `@knolo/exchange` `^0.1.0`. npm `latest` is `6.2.7`. `knolo kite` is in this
24
- package and in that release. It is not in published `@knolo/cli@6.2.5`. `knolo exchange` hands
22
+ package file is `6.2.10` and depends on `@knolo/core` `^6.2.3` and
23
+ `@knolo/exchange` `^0.1.1`. npm `latest` is `6.2.9` and includes `knolo ask` and `--category`. `@knolo/cli@6.2.8` has no `ask.mjs` and no `--category`. `knolo kite`, `knolo research verify`, and `knolo exchange relay` are in this
24
+ package and in `@knolo/cli@6.2.8`. `knolo kite` is not in published `@knolo/cli@6.2.5`. `knolo exchange` hands
25
25
  a verified V5 image to another agent. Shipped configs keep `adopt: deny`.
26
26
  Discover reads a public advertisement and does not download a pack. They do
27
27
  not fetch Hub for that handoff. Verification
@@ -49,6 +49,13 @@ a model. A receipt is an integrity check. It does not mean a claim is proven.
49
49
  `SATISFIED` means the evidence requirements were met. See
50
50
  [Skills](../../docs/skills/README.md).
51
51
 
52
+ `knolo persona` builds a signed persona pack from style exemplars, a profile,
53
+ a disclosure line, and KITE boundary obligations. The creator signs the consent
54
+ manifest. The private key stays out of the image. `npm latest` `6.2.9` does
55
+ not include `knolo persona`. A receipt is an integrity check. A KITE verdict
56
+ describes the contract. It does not mean the claim is true. The host owns the
57
+ model. See [Persona packs](../../docs/guides/persona-packs.md).
58
+
52
59
  `knolo research package` writes one V5 image from local files. `--agent` is
53
60
  the host-supplied caller. An optional Cortex trace is verified against
54
61
  `--cite` before the write. A cited pack stores a digest-bound composition
@@ -91,8 +98,28 @@ changing the local pack workflow:
91
98
  knolo search "refund policy"
92
99
  knolo search "refund policy" --research
93
100
  knolo info acme/refund-policy
101
+ knolo ask "what is the refund window?" --category business --model llama3.2
102
+ knolo ask "how does rust ownership work" --category coding --category math --evidence
103
+ knolo ask "what changed overnight" --all --model llama3.2
94
104
  ```
95
105
 
106
+ `knolo ask` posts the question to `POST /api/v1/knowledge/query`, checks each
107
+ excerpt sha256, and sends the verified excerpts and skill instructions to an
108
+ OpenAI-compatible chat endpoint. The default is Ollama at
109
+ `http://127.0.0.1:11434/v1`. Set `KNOLO_MODEL_BASE_URL` and `KNOLO_MODEL` for
110
+ another local server or a cloud gateway such as `https://api.x.ai/v1`.
111
+ `KNOLO_MODEL_API_KEY` is sent only to that endpoint. Hub does not receive the
112
+ key or the answer, and it does not install a matched skill. Pass `--category`
113
+ one or more times, or pass `--all` to search the entire hub. With neither,
114
+ the command exits before the network call. `--evidence` prints skills first,
115
+ then excerpts, and does not call a model. A `402` plan limit does not call
116
+ the model. With no remaining evidence the command exits 1 and does not call
117
+ the model. If only a skill remains, the model still runs with that skill text.
118
+
119
+ `knolo publish` and `knolo skill publish` take the same repeatable
120
+ `--category`. A new pack and every skill publish use 1 to 3 of `coding`,
121
+ `math`, `science`, `news`, `business`, `security`, `writing`, `general`.
122
+
96
123
  `--research` asks for packs whose image metadata role is `research-pack`.
97
124
  `--agents` remains the agent-definition namespace.
98
125
 
@@ -390,7 +417,7 @@ This ensures:
390
417
  ## 🗺 Roadmap
391
418
 
392
419
  The active roadmap is maintained in [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
393
- The published npm release is `6.2.7`. This tree's package file is `6.2.7` and adds `knolo kite`. `@knolo/cli@6.2.5` does not include that command. The published release preserves the V4 CLI, keeps V5 verification,
420
+ The published npm release is `6.2.9`. This tree's package file is `6.2.10` and adds `knolo persona`. `knolo persona` is not in the published release. The published release includes `knolo ask` and `--category`. `@knolo/cli@6.2.8` has no `ask.mjs` and no `--category`. `@knolo/cli@6.2.7` does not include `knolo research verify` or `knolo exchange relay`. `@knolo/cli@6.2.5` does not include `knolo kite`. The published release preserves the V4 CLI, keeps V5 verification,
394
421
  migration, diagnostics, and read-only Studio management, and adds offline
395
422
  composition, attestation, and `knolo cortex`. Cortex verification does not
396
423
  mean an answer is true.
package/bin/compose.mjs CHANGED
@@ -9,7 +9,8 @@ import { createHash } from 'node:crypto';
9
9
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
10
10
  import { homedir, tmpdir } from 'node:os';
11
11
  import path from 'node:path';
12
- import { fileURLToPath, pathToFileURL } from 'node:url';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { loadCoreModule } from './load-core.mjs';
13
14
  import { KAR_CLI_MAX_IMAGE_BYTES, readBounded, readBoundedJson } from './kar-limits.mjs';
14
15
 
15
16
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -688,52 +689,55 @@ function resolve(file) {
688
689
  }
689
690
 
690
691
  async function loadAuthorityRoot() {
691
- const candidates = [
692
- path.resolve(__dirname, '../../core/dist/knowledge_key_rotation_v5.js'),
693
- '@knolo/core',
694
- ];
695
- for (const candidate of candidates) {
696
- try {
697
- const href = candidate.startsWith('@') ? candidate : pathToFileURL(candidate).href;
698
- const loaded = await import(href);
699
- if (loaded.authorityKeyringRootV1) return loaded.authorityKeyringRootV1;
700
- } catch {
701
- // Try the next candidate.
702
- }
692
+ try {
693
+ const loaded = await loadCoreModule(
694
+ [
695
+ path.resolve(__dirname, '../../core/dist/knowledge_key_rotation_v5.js'),
696
+ '@knolo/core',
697
+ ],
698
+ (mod) => Boolean(mod?.authorityKeyringRootV1)
699
+ );
700
+ return loaded.authorityKeyringRootV1;
701
+ } catch (error) {
702
+ const detail = error instanceof Error ? error.message : String(error);
703
+ throw new Error(`Could not load authorityKeyringRootV1. Build packages/core first. (${detail})`);
703
704
  }
704
- throw new Error('Could not load authorityKeyringRootV1. Build packages/core first.');
705
705
  }
706
706
 
707
707
  async function loadComposition() {
708
- const candidates = [
709
- path.resolve(__dirname, '../../core/dist/composition/index.js'),
710
- '@knolo/core/composition',
711
- ];
712
- for (const candidate of candidates) {
713
- try {
714
- const href = candidate.startsWith('@') ? candidate : pathToFileURL(candidate).href;
715
- const loaded = await import(href);
716
- if (loaded.createCompositionRecord && loaded.verifyCompositionRecord && loaded.karCompositionBinder) return loaded;
717
- } catch {
718
- // Try the next candidate.
719
- }
708
+ try {
709
+ return await loadCoreModule(
710
+ [
711
+ path.resolve(__dirname, '../../core/dist/composition/index.js'),
712
+ '@knolo/core/composition',
713
+ ],
714
+ (loaded) =>
715
+ Boolean(
716
+ loaded?.createCompositionRecord &&
717
+ loaded?.verifyCompositionRecord &&
718
+ loaded?.karCompositionBinder
719
+ )
720
+ );
721
+ } catch (error) {
722
+ const detail = error instanceof Error ? error.message : String(error);
723
+ throw new Error(`Could not load @knolo/core/composition. Build packages/core first. (${detail})`);
720
724
  }
721
- throw new Error('Could not load @knolo/core/composition. Build packages/core first.');
722
725
  }
723
726
 
724
727
  async function loadAuthoring() {
725
- const candidates = [
726
- path.resolve(__dirname, '../../core/dist/experimental/kar/authoring/index.js'),
727
- '@knolo/core/experimental/kar/authoring',
728
- ];
729
- for (const candidate of candidates) {
730
- try {
731
- const href = candidate.startsWith('@') ? candidate : pathToFileURL(candidate).href;
732
- const loaded = await import(href);
733
- if (loaded.domainPackRoot && loaded.parseAuthoringDocument && loaded.interpretDomainPack) return loaded;
734
- } catch {
735
- // Try the next candidate.
736
- }
728
+ try {
729
+ return await loadCoreModule(
730
+ [
731
+ path.resolve(__dirname, '../../core/dist/experimental/kar/authoring/index.js'),
732
+ '@knolo/core/experimental/kar/authoring',
733
+ ],
734
+ (loaded) =>
735
+ Boolean(
736
+ loaded?.domainPackRoot && loaded?.parseAuthoringDocument && loaded?.interpretDomainPack
737
+ )
738
+ );
739
+ } catch (error) {
740
+ const detail = error instanceof Error ? error.message : String(error);
741
+ throw new Error(`Could not load @knolo/core/kar/authoring. Build packages/core first. (${detail})`);
737
742
  }
738
- throw new Error('Could not load @knolo/core/kar/authoring. Build packages/core first.');
739
743
  }
@@ -0,0 +1,33 @@
1
+ // A failed ESM graph stays cached for the exact URLs that failed. Retrying
2
+ // only the entry file links it against those failed dependencies and reports
3
+ // a missing export that the built file has. Copy the entry's knolo-epoch
4
+ // query onto every other file in that dist tree so the retry is a new graph.
5
+
6
+ export async function resolve(specifier, context, nextResolve) {
7
+ const next = await nextResolve(specifier, context);
8
+ const parent = context.parentURL;
9
+ if (!parent) return next;
10
+ let epoch;
11
+ try {
12
+ epoch = new URL(parent).searchParams.get('knolo-epoch');
13
+ } catch {
14
+ return next;
15
+ }
16
+ if (!epoch) return next;
17
+ let nextUrl;
18
+ let parentUrl;
19
+ try {
20
+ nextUrl = new URL(next.url);
21
+ parentUrl = new URL(parent);
22
+ } catch {
23
+ return next;
24
+ }
25
+ if (nextUrl.protocol !== 'file:') return next;
26
+ const distAt = parentUrl.pathname.lastIndexOf('/dist/');
27
+ if (distAt < 0) return next;
28
+ const distRoot = parentUrl.pathname.slice(0, distAt + '/dist/'.length);
29
+ if (!nextUrl.pathname.startsWith(distRoot)) return next;
30
+ if (nextUrl.searchParams.get('knolo-epoch') === epoch) return next;
31
+ nextUrl.searchParams.set('knolo-epoch', epoch);
32
+ return { format: next.format, shortCircuit: true, url: nextUrl.href };
33
+ }
package/bin/flight.mjs CHANGED
@@ -8,7 +8,8 @@
8
8
  import { createHash } from 'node:crypto';
9
9
  import { createReadStream, existsSync, statSync, writeFileSync } from 'node:fs';
10
10
  import path from 'node:path';
11
- import { fileURLToPath, pathToFileURL } from 'node:url';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { loadCoreModule } from './load-core.mjs';
12
13
  import { KAR_CLI_MAX_IMAGE_BYTES, readBounded } from './kar-limits.mjs';
13
14
 
14
15
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -384,20 +385,15 @@ async function inspectLog(file) {
384
385
  }
385
386
 
386
387
  async function loadImageApi() {
387
- const candidates = [
388
- path.resolve(__dirname, '../../core/dist/index.js'),
389
- '@knolo/core',
390
- ];
391
- for (const candidate of candidates) {
392
- try {
393
- const href = candidate.startsWith('@') ? candidate : pathToFileURL(candidate).href;
394
- const loaded = await import(href);
395
- if (loaded.createKnowledgeImageV5) return loaded;
396
- } catch {
397
- // Try the next candidate.
398
- }
388
+ try {
389
+ return await loadCoreModule(
390
+ [path.resolve(__dirname, '../../core/dist/index.js'), '@knolo/core'],
391
+ (loaded) => Boolean(loaded?.createKnowledgeImageV5)
392
+ );
393
+ } catch (error) {
394
+ const detail = error instanceof Error ? error.message : String(error);
395
+ throw new Error(`Could not load @knolo/core. Build packages/core first. (${detail})`);
399
396
  }
400
- throw new Error('Could not load @knolo/core. Build packages/core first.');
401
397
  }
402
398
 
403
399
  function parseArgs(argv) {
package/bin/knolo.mjs CHANGED
@@ -19,6 +19,7 @@ import { tmpdir } from 'node:os';
19
19
  import path from 'node:path';
20
20
  import process from 'node:process';
21
21
  import { fileURLToPath, pathToFileURL } from 'node:url';
22
+ import { loadCoreModule } from './load-core.mjs';
22
23
  import { createRequire } from 'node:module';
23
24
  import {
24
25
  isHubAddInvocation,
@@ -31,6 +32,7 @@ import {
31
32
  runHubWhoami,
32
33
  runHubYank,
33
34
  } from './registry/commands.mjs';
35
+ import { runHubAsk } from './registry/ask.mjs';
34
36
 
35
37
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
36
38
  const require = createRequire(import.meta.url);
@@ -63,6 +65,7 @@ const SUBCOMMANDS = new Set([
63
65
  'dev',
64
66
  'v5',
65
67
  'search',
68
+ 'ask',
66
69
  'info',
67
70
  'login',
68
71
  'whoami',
@@ -80,6 +83,7 @@ const SUBCOMMANDS = new Set([
80
83
  'kite',
81
84
  'flight',
82
85
  'skill',
86
+ 'persona',
83
87
  'setup',
84
88
  'exchange',
85
89
  'research',
@@ -119,24 +123,28 @@ async function tryImport(filePath) {
119
123
  return null;
120
124
  }
121
125
 
126
+ function coreNamespaceReady(mod) {
127
+ return Boolean(
128
+ (mod?.buildPack && mod?.mountPack && mod?.query) ||
129
+ (mod?.default?.buildPack && mod?.default?.mountPack && mod?.default?.query)
130
+ );
131
+ }
132
+
122
133
  async function loadCore() {
123
- const candidates = [
124
- path.resolve(__dirname, '../../core/dist/index.js'),
125
- '@knolo/core',
126
- ];
127
- for (const candidate of candidates) {
128
- const mod = await tryImport(candidate);
129
- if (mod?.buildPack && mod?.mountPack && mod?.query) return mod;
130
- if (
131
- mod?.default?.buildPack &&
132
- mod?.default?.mountPack &&
133
- mod?.default?.query
134
- )
135
- return mod.default;
134
+ let mod;
135
+ try {
136
+ mod = await loadCoreModule(
137
+ [path.resolve(__dirname, '../../core/dist/index.js'), '@knolo/core'],
138
+ coreNamespaceReady
139
+ );
140
+ } catch (error) {
141
+ const detail = error instanceof Error ? error.message : String(error);
142
+ throw createError(
143
+ `Could not load @knolo/core. Build packages/core first (npm run build --workspace @knolo/core). (${detail})`
144
+ );
136
145
  }
137
- throw createError(
138
- 'Could not load @knolo/core. Build packages/core first (npm run build --workspace @knolo/core).'
139
- );
146
+ if (mod?.buildPack && mod?.mountPack && mod?.query) return mod;
147
+ return mod.default;
140
148
  }
141
149
 
142
150
  function printVersion() {
@@ -162,6 +170,7 @@ Commands:
162
170
  init Initialize knolo.config.json and starter docs
163
171
  add <name> <path> Add or update a local source entry, or install a Hub pack
164
172
  search <query> Search the Knolo Hub registry
173
+ ask "<question>" Answer from Hub excerpts with your model
165
174
  info <publisher>/<slug> Show a Hub registry pack
166
175
  login Store a Hub token locally
167
176
  whoami Show the stored Hub token prefix
@@ -184,6 +193,7 @@ Commands:
184
193
  kite Check a typed contract and replay its certificate
185
194
  flight Pack a flight-events-1 document into a V5 Knowledge Image
186
195
  skill Create and share a Knolo skill pack
196
+ persona Build a signed persona pack and check its boundaries
187
197
  research Package local research files into a V5 Knowledge Image
188
198
  setup Prepare a local index and print the hub next steps
189
199
  exchange Offer or pull a verified Knowledge Image from a peer or relay
@@ -203,13 +213,15 @@ function printCommandHelp(command) {
203
213
  add: 'Usage: knolo add <name> <path> | <publisher>/<slug>[@<version>] [--out <path>] [--force] [--json] [--registry <url>]',
204
214
  search:
205
215
  'Usage: knolo search <query> [--format V4|V5] [--license <id>] [--official] [--agents] [--research] [--json] [--registry <url>]',
216
+ ask:
217
+ 'Usage: knolo ask "<question>" [--category <id>] [--all] [--model <name>] [--base-url <url>] [--limit <n>] [--evidence] [--hub <url>]\n\nPosts the question to Hub and sends the verified excerpts and skill instructions to an OpenAI-compatible chat endpoint. The default base URL is http://127.0.0.1:11434/v1 (Ollama). Set KNOLO_MODEL_BASE_URL and KNOLO_MODEL for another engine, including a cloud gateway such as https://api.x.ai/v1. KNOLO_MODEL_API_KEY is sent only to that endpoint.\nPass --category one or more times, or pass --all to search the entire hub. With neither, ask exits before the network call. --evidence prints skills first, then excerpts, and does not call a model. A plan limit does not call a model. --hub is the same registry override as --registry.',
206
218
  info: 'Usage: knolo info <publisher>/<slug> [--json] [--registry <url>]',
207
219
  login:
208
220
  'Usage: knolo login [--token kno_…] [--stdin] [--registry <url>]\n\nStores the raw token locally. Hub write calls send Authorization: Bearer kno_….\nMint tokens at https://hub.knolo.dev/dashboard/tokens; login does not call POST /api/v1/tokens.',
209
221
  whoami: 'Usage: knolo whoami',
210
222
  logout: 'Usage: knolo logout',
211
223
  publish:
212
- 'Usage: knolo publish <pack.knolo> --slug <slug> --version <version> --license <SPDX> [--publisher <handle>] [--readme <text>] [--sources <text>] [--intended-use <text>] [--private] [--json] [--registry <url>]\n\nUses the stored dashboard token as Authorization: Bearer kno_…. Hub issues a public Blob PUT grant; the CLI never needs PACKS_READ_WRITE_TOKEN.\nUploads go to the grant URL without the kno_ token. Complete sends the public Blob URL, then Hub verifies before release.\n--private releases an owner-only pack on a Business or Enterprise plan. The success text omits the Blob URL.',
224
+ 'Usage: knolo publish <pack.knolo> --slug <slug> --version <version> --license <SPDX> [--publisher <handle>] [--readme <text>] [--sources <text>] [--intended-use <text>] [--category <id>] [--private] [--json] [--registry <url>]\n\nUses the stored dashboard token as Authorization: Bearer kno_…. Hub issues a public Blob PUT grant; the CLI never needs PACKS_READ_WRITE_TOKEN.\nUploads go to the grant URL without the kno_ token. Complete sends the public Blob URL, then Hub verifies before release.\n--category is repeatable, from 1 to 3 of coding, math, science, news, business, security, writing, general. A new pack needs at least one. --private releases an owner-only pack on a Business or Enterprise plan. The success text omits the Blob URL.',
213
225
  yank: 'Usage: knolo yank <publisher>/<slug>@<version> [--json] [--registry <url>]\n\nUses the stored token as Authorization: Bearer kno_…. Yank is owner-only and leaves the public Blob in place.',
214
226
  build: 'Usage: knolo build',
215
227
  query:
@@ -269,7 +281,7 @@ and it is not Knolo Hub. offer --via uploads to that relay instead of serve.`,
269
281
  knolo skill init <name> [--dir <parent>]
270
282
  knolo skill check [<dir>] [--query <text>] [--json]
271
283
  knolo skill pack [<dir>] [--out <dir>] [--json]
272
- knolo skill publish <pack> [--registry <url>] [--json]
284
+ knolo skill publish <pack> [--category <id>] [--registry <url>] [--json]
273
285
  knolo skill publish <pack> --hub <dir> [--json]
274
286
  knolo skill install <publisher>/<name> [--dir <path>] [--registry <url>] [--json]
275
287
  knolo skill install <name> --hub <dir> [--dir <path>] [--json]
@@ -286,6 +298,21 @@ local directory. install checks the pin before it writes. It writes into
286
298
  --dir, or into ~/.knolo/skills when --dir is omitted. A pin mismatch
287
299
  writes nothing. list prints every publisher/name from the public catalog.
288
300
  The hub stores packs and does not answer questions.`,
301
+ persona: `Usage: knolo persona <init|build|verify|eval>
302
+
303
+ knolo persona init <name> [--dir <parent>]
304
+ knolo persona build <dir> [--out <file>] [--json]
305
+ knolo persona verify <image> [--withdrawn <id>] [--json]
306
+ knolo persona eval <image> --fixtures <file> [--json]
307
+
308
+ Builds a persona pack on the current V5 image.
309
+ Knolo core does not call a model. The host owns the model.
310
+ A receipt is an integrity check. It does not mean a claim is proven.
311
+ SATISFIED means the evidence requirements were met.
312
+ A KITE verdict describes the contract. It does not mean the claim is true.
313
+ verify fails when a withdrawn source id is still in the image.
314
+ An opt-out rebuild drops that file and produces a new pin.
315
+ The example adapter is examples/persona-chat.`,
289
316
  'verify-attestation': 'Usage: knolo verify-attestation <attestation.json> [--composition composition.json] [--public-key key.json] [--keyring keyring.json] [--now <ms>] [--content-only]\n\nSame check as knolo attest verify. A bad signature exits 1 even when the content root matches. --content-only checks the content root and ignores the envelope. statement used is not a truth verdict. Hub attested: true is unrelated.',
290
317
  icp: 'Usage: knolo icp <command> [options]',
291
318
  'semantic:index':
@@ -1960,6 +1987,10 @@ async function main() {
1960
1987
  const { runSkillCli } = await import('./skill.mjs');
1961
1988
  return await runSkillCli(commandArgs);
1962
1989
  }
1990
+ if (command === 'persona') {
1991
+ const { runPersonaCli } = await import('./persona.mjs');
1992
+ return await runPersonaCli(commandArgs);
1993
+ }
1963
1994
  if (command === 'exchange') {
1964
1995
  const { runExchangeCli } = await import('./exchange.mjs');
1965
1996
  return await runExchangeCli(commandArgs);
@@ -1971,6 +2002,11 @@ async function main() {
1971
2002
  if (command === 'init') return await cmdInit();
1972
2003
  if (command === 'add') return await cmdAdd(commandArgs);
1973
2004
  if (command === 'search') return await runHubSearch(commandArgs);
2005
+ if (command === 'ask') {
2006
+ const result = await runHubAsk(commandArgs);
2007
+ if (result.exitCode) process.exit(result.exitCode);
2008
+ return;
2009
+ }
1974
2010
  if (command === 'info') return await runHubInfo(commandArgs);
1975
2011
  if (command === 'login') return await runHubLogin(commandArgs);
1976
2012
  if (command === 'whoami') return await runHubWhoami(commandArgs);
@@ -0,0 +1,76 @@
1
+ import { register } from 'node:module';
2
+ import { pathToFileURL } from 'node:url';
3
+
4
+ const RETRIES = 2;
5
+
6
+ let hookRegistration;
7
+
8
+ function ensureHook() {
9
+ hookRegistration ??= register(
10
+ new URL('./core-load-hook.mjs', import.meta.url).href,
11
+ import.meta.url
12
+ );
13
+ return hookRegistration;
14
+ }
15
+
16
+ function specifierFor(candidate) {
17
+ if (
18
+ candidate.startsWith('file:') ||
19
+ candidate.startsWith('node:') ||
20
+ candidate.startsWith('data:')
21
+ ) {
22
+ return candidate;
23
+ }
24
+ if (
25
+ candidate.startsWith('/') ||
26
+ candidate.startsWith('.') ||
27
+ /^[A-Za-z]:[\\/]/.test(candidate)
28
+ ) {
29
+ return pathToFileURL(candidate).href;
30
+ }
31
+ return candidate;
32
+ }
33
+
34
+ function isNotFound(error) {
35
+ return error?.code === 'ERR_MODULE_NOT_FOUND' || error?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED';
36
+ }
37
+
38
+ async function withEpoch(specifier, epoch) {
39
+ await ensureHook();
40
+ const href = specifier.startsWith('file:') ? specifier : import.meta.resolve(specifier);
41
+ const url = new URL(href);
42
+ url.searchParams.set('knolo-epoch', String(epoch));
43
+ return url.href;
44
+ }
45
+
46
+ function delay(ms) {
47
+ return new Promise((resolve) => {
48
+ setTimeout(resolve, ms);
49
+ });
50
+ }
51
+
52
+ export async function loadCoreModule(candidates, ready) {
53
+ let lastError = null;
54
+ for (const candidate of candidates) {
55
+ const specifier = specifierFor(candidate);
56
+ let missing = false;
57
+ for (let epoch = 0; epoch <= RETRIES; epoch += 1) {
58
+ try {
59
+ const href = epoch === 0 ? specifier : await withEpoch(specifier, epoch);
60
+ const loaded = await import(href);
61
+ if (ready(loaded)) return loaded;
62
+ lastError = new Error('module did not export the expected API');
63
+ } catch (error) {
64
+ lastError = error;
65
+ if (isNotFound(error)) {
66
+ missing = true;
67
+ break;
68
+ }
69
+ }
70
+ if (epoch < RETRIES) await delay(25 * (epoch + 1));
71
+ }
72
+ if (missing) continue;
73
+ break;
74
+ }
75
+ throw lastError ?? new Error('module did not export the expected API');
76
+ }