@knolo/cli 6.2.6 → 6.2.7

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
@@ -20,8 +20,8 @@ reader.
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
22
  package file is `6.2.6` and depends on `@knolo/core` `^6.2.3` and
23
- `@knolo/exchange` `^0.1.0`. npm `latest` is `6.2.5`. `knolo kite` is in this
24
- package file. It is not in published `@knolo/cli@6.2.5`. `knolo exchange` hands
23
+ `@knolo/exchange` `^0.1.0`. npm `latest` is `6.2.6`. `knolo kite` is in this
24
+ package and in that release. It 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
@@ -387,7 +387,7 @@ This ensures:
387
387
  ## 🗺 Roadmap
388
388
 
389
389
  The active roadmap is maintained in [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
390
- The published npm release is `6.2.5`. This tree's package file is `6.2.6` and adds `knolo kite`. The published release preserves the V4 CLI, keeps V5 verification,
390
+ The published npm release is `6.2.6`. This tree's package file is `6.2.6` and adds `knolo kite`. `@knolo/cli@6.2.5` does not include that command. The published release preserves the V4 CLI, keeps V5 verification,
391
391
  migration, diagnostics, and read-only Studio management, and adds offline
392
392
  composition, attestation, and `knolo cortex`. Cortex verification does not
393
393
  mean an answer is true.
package/bin/knolo.mjs CHANGED
@@ -209,7 +209,7 @@ function printCommandHelp(command) {
209
209
  whoami: 'Usage: knolo whoami',
210
210
  logout: 'Usage: knolo logout',
211
211
  publish:
212
- 'Usage: knolo publish <pack.knolo> --slug <slug> --version <version> --license <SPDX> [--publisher <handle>] [--readme <text>] [--sources <text>] [--intended-use <text>] [--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.',
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.',
213
213
  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
214
  build: 'Usage: knolo build',
215
215
  query:
@@ -75,13 +75,19 @@ export async function runHubSearch(
75
75
 
76
76
  export async function runHubInfo(
77
77
  args,
78
- { env = process.env, fetchImpl = globalThis.fetch, print = console.log } = {}
78
+ {
79
+ env = process.env,
80
+ fetchImpl = globalThis.fetch,
81
+ homeDir,
82
+ print = console.log,
83
+ } = {}
79
84
  ) {
80
85
  const { positional, flags } = parseInfoArgs(args);
81
86
  const pack = parsePackName(positional[0]);
82
87
  const registry = resolveRegistryUrl({ value: flags.registry, env });
83
88
  const url = registryApiUrl(registry, ['packs', pack.publisher, pack.slug]);
84
- const body = await getJson(url, { fetchImpl });
89
+ const headers = await optionalPublishHeaders(registry, { env, homeDir });
90
+ const body = await getHubJson(url, { fetchImpl, headers });
85
91
  validatePackInfoResponse(body);
86
92
 
87
93
  if (flags.json) print(JSON.stringify(body, null, 2));
@@ -115,12 +121,17 @@ export async function runHubAdd(
115
121
 
116
122
  let manifest;
117
123
  let yanked = false;
124
+ let rawBody;
125
+ const manifestHeaders = await optionalPublishHeaders(registry, {
126
+ env,
127
+ homeDir,
128
+ });
118
129
  try {
119
- const body = await getJson(manifestUrl, { fetchImpl });
120
- manifest = validatePackManifest(body, {
121
- expectedName: spec.name,
122
- requestedVersion: spec.version,
130
+ rawBody = await getHubJson(manifestUrl, {
131
+ fetchImpl,
132
+ headers: manifestHeaders,
123
133
  });
134
+ manifest = packManifestFromBody(rawBody, spec);
124
135
  } catch (error) {
125
136
  if (
126
137
  error instanceof RegistryError &&
@@ -132,10 +143,8 @@ export async function runHubAdd(
132
143
  error instanceof RegistryError &&
133
144
  (error.status === 410 || error.code === 'yanked')
134
145
  ) {
135
- manifest = validatePackManifest(error.body, {
136
- expectedName: spec.name,
137
- requestedVersion: spec.version,
138
- });
146
+ rawBody = error.body;
147
+ manifest = packManifestFromBody(error.body, spec);
139
148
  yanked = true;
140
149
  } else {
141
150
  throw error;
@@ -149,6 +158,26 @@ export async function runHubAdd(
149
158
  warn(
150
159
  `warning: downloading yanked version ${manifest.name}@${manifest.version}`
151
160
  );
161
+ if (manifest.visibility === 'private') {
162
+ const credentials = await requirePrivateCredentials(registry, {
163
+ env,
164
+ homeDir,
165
+ });
166
+ const signed = await getHubJson(
167
+ registryApiUrl(registry, [
168
+ 'packs',
169
+ spec.publisher,
170
+ spec.slug,
171
+ spec.version,
172
+ 'download',
173
+ ]),
174
+ { fetchImpl, headers: authorizationHeaders(credentials.token) }
175
+ );
176
+ manifest.url = assertSignedDownloadUrl(
177
+ signed?.url,
178
+ typeof rawBody?.url === 'string' ? rawBody.url : ''
179
+ );
180
+ }
152
181
  if (!manifest.url) throw new Error('artifact bytes are not stored yet');
153
182
  if (!PACK_SHA256_PATTERN.test(manifest.sha256))
154
183
  throw new Error('manifest sha256 is invalid');
@@ -218,8 +247,14 @@ export async function runHubAdd(
218
247
  await commitStagedFiles(stagedFiles);
219
248
  const lock = { path: stagedLock.path, entry: stagedLock.entry };
220
249
  const result = { ...manifest, path: outputPath, lockfile: lock.path };
250
+ if (result.visibility === 'private') delete result.url;
221
251
  if (flags.json) print(JSON.stringify(result, null, 2));
222
- else {
252
+ else if (manifest.visibility === 'private') {
253
+ print(`added ${manifest.name}@${manifest.version}`);
254
+ print(`sha256 ${manifest.sha256}`);
255
+ print('visibility private');
256
+ print(`path ${outputPath}`);
257
+ } else {
223
258
  print(`added ${manifest.name}@${manifest.version}`);
224
259
  print(`sha256 ${manifest.sha256}`);
225
260
  print(`url ${manifest.url}`);
@@ -328,17 +363,26 @@ export async function runHubPublish(
328
363
  const sha256 = createSha256(bytes);
329
364
  const pathname = `sha256/${sha256}.knolo`;
330
365
 
331
- const grant = await postJson(
366
+ const grant = await postHubJson(
332
367
  hubApiUrl(registry, ['upload', 'token']),
333
- { sha256, contentLength: bytes.length },
368
+ {
369
+ sha256,
370
+ contentLength: bytes.length,
371
+ ...(flags.private ? { visibility: 'private' } : {}),
372
+ },
334
373
  { fetchImpl, headers: authHeaders }
335
374
  );
336
- const upload = resolveUploadGrant(grant, sha256);
375
+ const upload = resolveUploadGrant(grant, sha256, { privatePack: Boolean(flags.private) });
337
376
  let blobUrl;
338
- if (upload.reused) {
339
- blobUrl = assertPublicPackBlobUrl(upload.url, 'reused artifact').toString();
377
+ if (upload.reused && !upload.url && flags.private) {
378
+ blobUrl = undefined;
379
+ } else if (upload.reused) {
380
+ blobUrl = (flags.private ? assertPrivatePackBlobUrl : assertPublicPackBlobUrl)(
381
+ upload.url,
382
+ 'reused artifact'
383
+ ).toString();
340
384
  } else {
341
- assertGrantPutUrl(upload.putUrl, 'upload grant');
385
+ assertGrantPutUrl(upload.putUrl, 'upload grant', { allowPrivate: Boolean(flags.private) });
342
386
  const uploaded = await putBytes(upload.putUrl, bytes, {
343
387
  fetchImpl,
344
388
  headers: {
@@ -349,27 +393,28 @@ export async function runHubPublish(
349
393
  });
350
394
  if (uploaded.pathname !== undefined && uploaded.pathname !== pathname) {
351
395
  throw new Error(
352
- `Public Blob upload pathname is not locked to ${pathname}.`
396
+ `${flags.private ? 'Private' : 'Public'} Blob upload pathname is not locked to ${pathname}.`
353
397
  );
354
398
  }
355
- blobUrl = assertPublicPackBlobUrl(
399
+ blobUrl = (flags.private ? assertPrivatePackBlobUrl : assertPublicPackBlobUrl)(
356
400
  uploaded.url,
357
401
  'uploaded artifact'
358
402
  ).toString();
359
403
  }
360
404
 
361
- await postJson(
405
+ await postHubJson(
362
406
  hubApiUrl(registry, ['upload', 'complete']),
363
407
  {
364
408
  sha256,
365
- url: blobUrl,
409
+ ...(blobUrl ? { url: blobUrl } : {}),
366
410
  sizeBytes: bytes.length,
367
411
  pathname,
412
+ ...(flags.private ? { visibility: 'private' } : {}),
368
413
  },
369
414
  { fetchImpl, headers: authHeaders }
370
415
  );
371
416
 
372
- const verifyResponse = await postJson(
417
+ const verifyResponse = await postHubJson(
373
418
  registryApiUrl(registry, ['publish', 'verify']),
374
419
  { sha256 },
375
420
  {
@@ -394,13 +439,14 @@ export async function runHubPublish(
394
439
  version: flags.version,
395
440
  license: flags.license,
396
441
  attested: true,
442
+ ...(flags.private ? { visibility: 'private' } : {}),
397
443
  ...(flags.readme !== undefined ? { readme: flags.readme } : {}),
398
444
  ...(flags.sources !== undefined ? { sources: flags.sources } : {}),
399
445
  ...(flags.intendedUse !== undefined
400
446
  ? { intendedUse: flags.intendedUse }
401
447
  : {}),
402
448
  };
403
- const draftResponse = await postJson(
449
+ const draftResponse = await postHubJson(
404
450
  registryApiUrl(registry, ['publish', 'drafts']),
405
451
  draftPayload,
406
452
  {
@@ -412,7 +458,7 @@ export async function runHubPublish(
412
458
  if (!draftId)
413
459
  throw new Error('Hub draft response did not include a draft id.');
414
460
 
415
- const releaseResponse = await postJson(
461
+ const releaseResponse = await postHubJson(
416
462
  registryApiUrl(registry, ['publish', 'drafts', draftId, 'release']),
417
463
  undefined,
418
464
  {
@@ -430,7 +476,7 @@ export async function runHubPublish(
430
476
  sha256,
431
477
  sizeBytes: bytes.length,
432
478
  pathname,
433
- url: blobUrl,
479
+ ...(flags.private ? { visibility: 'private' } : { url: blobUrl }),
434
480
  jobId: String(jobId),
435
481
  draftId: String(draftId),
436
482
  verification: job,
@@ -438,7 +484,12 @@ export async function runHubPublish(
438
484
  };
439
485
 
440
486
  if (flags.json) print(JSON.stringify(result, null, 2));
441
- else {
487
+ else if (flags.private) {
488
+ print(`published ${name}@${flags.version}`);
489
+ print(`sha256 ${sha256}`);
490
+ print('visibility private');
491
+ print(`job ${jobId}`);
492
+ } else {
442
493
  print(`published ${name}@${flags.version}`);
443
494
  print(`sha256 ${sha256}`);
444
495
  print(`url ${blobUrl}`);
@@ -506,6 +557,10 @@ export function parsePublishArgs(args) {
506
557
  flags.json = true;
507
558
  continue;
508
559
  }
560
+ if (arg === '--private') {
561
+ flags.private = true;
562
+ continue;
563
+ }
509
564
  if (valueFlags.has(arg)) {
510
565
  const value = args[++i];
511
566
  if (value === undefined || value.startsWith('--'))
@@ -525,7 +580,7 @@ export function parsePublishArgs(args) {
525
580
  !flags.license
526
581
  ) {
527
582
  throw new Error(
528
- 'Usage: knolo publish <pack.knolo> --slug <slug> --version <version> --license <SPDX> [--publisher <handle>] [--readme <text>] [--sources <text>] [--intended-use <text>] [--json] [--registry <url>]'
583
+ 'Usage: knolo publish <pack.knolo> --slug <slug> --version <version> --license <SPDX> [--publisher <handle>] [--readme <text>] [--sources <text>] [--intended-use <text>] [--private] [--json] [--registry <url>]'
529
584
  );
530
585
  }
531
586
  if (!/^[a-z0-9-]+$/.test(flags.slug))
@@ -577,6 +632,87 @@ function authorizationHeaders(token) {
577
632
  return { Authorization: `Bearer ${token}` };
578
633
  }
579
634
 
635
+ function planLimitError(error) {
636
+ if (
637
+ !(error instanceof RegistryError) ||
638
+ error.status !== 402 ||
639
+ error.code !== 'plan_limit'
640
+ ) {
641
+ return error;
642
+ }
643
+ const message =
644
+ typeof error.body?.error === 'string' && error.body.error.trim()
645
+ ? error.body.error.trim()
646
+ : error.message;
647
+ const upgrade =
648
+ typeof error.body?.upgradeUrl === 'string'
649
+ ? error.body.upgradeUrl.trim()
650
+ : '';
651
+ return new Error(upgrade ? `${message}\n${upgrade}` : message);
652
+ }
653
+
654
+ async function postHubJson(url, body, options) {
655
+ try {
656
+ return await postJson(url, body, options);
657
+ } catch (error) {
658
+ throw planLimitError(error);
659
+ }
660
+ }
661
+
662
+ async function getHubJson(url, options) {
663
+ try {
664
+ return await getJson(url, options);
665
+ } catch (error) {
666
+ throw planLimitError(error);
667
+ }
668
+ }
669
+
670
+ async function optionalPublishHeaders(registry, { env, homeDir } = {}) {
671
+ const credentials = await readMatchingCredentials(registry, { env, homeDir });
672
+ return credentials ? authorizationHeaders(credentials.token) : {};
673
+ }
674
+
675
+ async function readMatchingCredentials(registry, { env, homeDir } = {}) {
676
+ try {
677
+ const credentials = await loadCredentials({ env, homeDir });
678
+ if (
679
+ normalizeRegistryUrl(credentials.registry) !==
680
+ normalizeRegistryUrl(registry)
681
+ ) {
682
+ return undefined;
683
+ }
684
+ return credentials;
685
+ } catch (error) {
686
+ if (error instanceof Error && error.message.startsWith('Not logged in')) {
687
+ return undefined;
688
+ }
689
+ throw error;
690
+ }
691
+ }
692
+
693
+ async function requirePrivateCredentials(registry, { env, homeDir } = {}) {
694
+ let credentials;
695
+ try {
696
+ credentials = await loadCredentials({ env, homeDir });
697
+ } catch (error) {
698
+ if (error instanceof Error && error.message.startsWith('Not logged in')) {
699
+ throw new Error('Private packs require a Hub token. Run knolo login.');
700
+ }
701
+ throw error;
702
+ }
703
+ resolveCredentialRegistry(registry, credentials.registry);
704
+ return credentials;
705
+ }
706
+
707
+ function packManifestFromBody(body, spec) {
708
+ const manifest = validatePackManifest(body, {
709
+ expectedName: spec.name,
710
+ requestedVersion: spec.version,
711
+ });
712
+ if (body?.visibility === 'private') manifest.visibility = 'private';
713
+ return manifest;
714
+ }
715
+
580
716
  function resolveCredentialRegistry(requestedRegistry, storedRegistry) {
581
717
  const stored = normalizeRegistryUrl(storedRegistry);
582
718
  if (!requestedRegistry) return stored;
@@ -599,7 +735,7 @@ function createSha256(bytes) {
599
735
  return createHash('sha256').update(bytes).digest('hex');
600
736
  }
601
737
 
602
- function resolveUploadGrant(body, sha256) {
738
+ function resolveUploadGrant(body, sha256, { privatePack = false } = {}) {
603
739
  const pathname = body?.pathname || body?.upload?.pathname;
604
740
  const expectedPathname = `sha256/${sha256}.knolo`;
605
741
  if (typeof pathname !== 'string' || pathname !== expectedPathname) {
@@ -612,6 +748,9 @@ function resolveUploadGrant(body, sha256) {
612
748
  if (typeof reusedUrl === 'string' && reusedUrl) {
613
749
  return { reused: true, pathname, url: reusedUrl };
614
750
  }
751
+ if (body?.reused === true && privatePack) {
752
+ return { reused: true, pathname };
753
+ }
615
754
 
616
755
  const upload = body?.upload && typeof body.upload === 'object' ? body.upload : body;
617
756
  if (!upload || typeof upload.url !== 'string' || !upload.url) {
@@ -631,7 +770,7 @@ function resolveUploadGrant(body, sha256) {
631
770
  };
632
771
  }
633
772
 
634
- function assertGrantPutUrl(value, label) {
773
+ function assertGrantPutUrl(value, label, { allowPrivate = false } = {}) {
635
774
  let url;
636
775
  try {
637
776
  url = new URL(value);
@@ -642,8 +781,8 @@ function assertGrantPutUrl(value, label) {
642
781
  throw new Error(`Hub ${label} URL must use HTTPS.`);
643
782
  const hostname = url.hostname.toLowerCase();
644
783
  if (
645
- hostname.includes('.private.') ||
646
- hostname.startsWith('private.') ||
784
+ (!allowPrivate &&
785
+ (hostname.includes('.private.') || hostname.startsWith('private.'))) ||
647
786
  isPrivateOrLocalIp(hostname) ||
648
787
  isLocalOnlyHostname(hostname)
649
788
  ) {
@@ -654,6 +793,34 @@ function assertGrantPutUrl(value, label) {
654
793
  return url;
655
794
  }
656
795
 
796
+ function assertSignedDownloadUrl(value, storedUrl) {
797
+ if (typeof value !== 'string' || !value) {
798
+ throw new Error('Hub did not return a signed download URL.');
799
+ }
800
+ let url;
801
+ try {
802
+ url = new URL(value);
803
+ } catch {
804
+ throw new Error('Hub signed download URL is invalid.');
805
+ }
806
+ if (url.protocol !== 'https:')
807
+ throw new Error('Hub signed download URL must use HTTPS.');
808
+ const hostname = url.hostname.toLowerCase();
809
+ if (isPrivateOrLocalIp(hostname) || isLocalOnlyHostname(hostname)) {
810
+ throw new Error('Hub signed download URL must not be local.');
811
+ }
812
+ if (storedUrl && value === storedUrl) {
813
+ throw new Error('Refusing the stored private Blob URL.');
814
+ }
815
+ if (
816
+ (hostname.includes('.private.') || hostname.startsWith('private.')) &&
817
+ !url.search
818
+ ) {
819
+ throw new Error('Refusing the stored private Blob URL.');
820
+ }
821
+ return url.toString();
822
+ }
823
+
657
824
  function extractPublisherHandle(account) {
658
825
  const candidates = [
659
826
  account?.publisherHandle,
@@ -720,6 +887,32 @@ function assertPublicPackBlobUrl(value, label) {
720
887
  return url;
721
888
  }
722
889
 
890
+ function assertPrivatePackBlobUrl(value, label) {
891
+ let url;
892
+ try {
893
+ url = new URL(value);
894
+ } catch {
895
+ throw new Error(`Hub ${label} URL is invalid.`);
896
+ }
897
+ if (url.protocol !== 'https:')
898
+ throw new Error(`Hub ${label} URL must use HTTPS.`);
899
+ const hostname = url.hostname.toLowerCase();
900
+ if (isPrivateOrLocalIp(hostname) || isLocalOnlyHostname(hostname)) {
901
+ throw new Error(
902
+ `Refusing local-only Blob URL for ${label}; a private pack uses a private Blob host.`
903
+ );
904
+ }
905
+ const blobHost =
906
+ hostname === 'blob.vercel-storage.com' ||
907
+ hostname.endsWith('.blob.vercel-storage.com');
908
+ const privateHost =
909
+ hostname.includes('.private.') || hostname.startsWith('private.');
910
+ if (!blobHost || !privateHost) {
911
+ throw new Error(`Hub ${label} URL must be a private Vercel Blob pack URL.`);
912
+ }
913
+ return url;
914
+ }
915
+
723
916
  function isLocalOnlyHostname(hostname) {
724
917
  const normalized = hostname.replace(/^\[|\]$/g, '').replace(/\.$/, '');
725
918
  return (
@@ -852,7 +1045,7 @@ async function waitForPublishJob(
852
1045
 
853
1046
  for (let attempt = 0; attempt < maxPollAttempts; attempt++) {
854
1047
  if (attempt > 0 && pollIntervalMs > 0) await sleepImpl(pollIntervalMs);
855
- const body = await getJson(
1048
+ const body = await getHubJson(
856
1049
  registryApiUrl(registry, ['publish', 'jobs', jobId]),
857
1050
  { fetchImpl, headers }
858
1051
  );
@@ -1204,8 +1397,16 @@ export function renderPackInfo(body) {
1204
1397
  `topics ${Array.isArray(pack.topics) ? pack.topics.join(', ') : ''}`,
1205
1398
  `latest ${latest.version || ''}`,
1206
1399
  `sha256 ${latest.sha256 || pack.sha256 || ''}`,
1207
- `url ${latest.url || pack.blobUrl || ''}`,
1208
1400
  ];
1401
+ const privatePack =
1402
+ body.visibility === 'private' ||
1403
+ pack.visibility === 'private' ||
1404
+ latest.visibility === 'private';
1405
+ lines.push(
1406
+ privatePack
1407
+ ? 'visibility private'
1408
+ : `url ${latest.url || pack.blobUrl || ''}`
1409
+ );
1209
1410
  return lines.join('\n');
1210
1411
  }
1211
1412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/cli",
3
- "version": "6.2.6",
3
+ "version": "6.2.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "knolo": "bin/knolo.mjs"