@notis_ai/cli 0.2.25 → 0.2.27

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 (163) hide show
  1. package/README.md +186 -5
  2. package/config/notis_app_design_rules.json +36 -14
  3. package/config/portal-route-roots.json +1 -0
  4. package/dist/agent-hooks/notis-agent-hook.mjs +2866 -553
  5. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  6. package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
  7. package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
  8. package/dist/base-skills/notis-query/SKILL.md +0 -1
  9. package/dist/base-skills/notis-query/references/documents.md +7 -0
  10. package/dist/base-skills/notis-query/references/query.md +1 -0
  11. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  12. package/dist/base-skills/notis-spaces/SKILL.md +96 -24
  13. package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
  14. package/dist/base-skills/notis-spaces/references/context.md +3 -0
  15. package/dist/base-skills/notis-spaces/references/design.md +37 -18
  16. package/dist/base-skills/notis-spaces/references/reading.md +8 -1
  17. package/dist/base-skills/notis-spaces/references/reports.md +6 -6
  18. package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
  19. package/dist/base-skills/notis-spaces/references/store.md +22 -13
  20. package/dist/base-skills/notis-spaces/references/views.md +99 -6
  21. package/dist/sdk/package.json +3 -0
  22. package/dist/sdk/src/cloudComputerWords.ts +53 -0
  23. package/dist/sdk/src/components/Audience.tsx +76 -0
  24. package/dist/sdk/src/components/DocumentPage.tsx +15 -4
  25. package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
  26. package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
  27. package/dist/sdk/src/components/NotisSelectionBoundary.tsx +79 -25
  28. package/dist/sdk/src/components/Skeleton.tsx +162 -6
  29. package/dist/sdk/src/hooks/useAction.ts +12 -2
  30. package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
  31. package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
  32. package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
  33. package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
  34. package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
  35. package/dist/sdk/src/hooks/useItemThread.ts +58 -0
  36. package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
  37. package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
  38. package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
  39. package/dist/sdk/src/hooks/useQuery.ts +67 -10
  40. package/dist/sdk/src/hooks/useViewParams.ts +47 -11
  41. package/dist/sdk/src/index.ts +31 -4
  42. package/dist/sdk/src/interactions.ts +2 -0
  43. package/dist/sdk/src/nativeData.ts +2 -0
  44. package/dist/sdk/src/optimisticRows.ts +329 -0
  45. package/dist/sdk/src/perf.ts +188 -0
  46. package/dist/sdk/src/provider.tsx +2 -1
  47. package/dist/sdk/src/queryCache.ts +366 -17
  48. package/dist/sdk/src/runtime.ts +55 -4
  49. package/dist/sdk/src/skeleton.ts +103 -0
  50. package/dist/sdk/src/space.ts +662 -28
  51. package/dist/sdk/src/spacePublicUI.ts +36 -0
  52. package/dist/sdk/src/ui/engine/step.ts +54 -0
  53. package/dist/sdk/src/ui/icons.tsx +3 -1
  54. package/dist/sdk/src/words/shell.ts +1 -0
  55. package/dist/skill-sync/index.js +88 -13
  56. package/dist/skill-sync-worker.mjs +127 -38
  57. package/dist/space-harness/host.js +272 -105
  58. package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
  59. package/dist/space-sdk/dist/index.js +9 -4
  60. package/dist/space-sdk/dist/ui.js +12 -12
  61. package/dist/space-sdk/package.json +3 -0
  62. package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
  63. package/dist/space-sdk/src/components/Audience.d.ts +46 -0
  64. package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
  65. package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
  66. package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
  67. package/dist/space-sdk/src/components/NotisSelectionBoundary.d.ts +19 -2
  68. package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
  69. package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
  70. package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
  71. package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
  72. package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
  73. package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
  74. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
  75. package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
  76. package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
  77. package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
  78. package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
  79. package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
  80. package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
  81. package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
  82. package/dist/space-sdk/src/index.d.ts +24 -4
  83. package/dist/space-sdk/src/nativeData.d.ts +6 -0
  84. package/dist/space-sdk/src/queryCache.d.ts +97 -2
  85. package/dist/space-sdk/src/runtime.d.ts +53 -4
  86. package/dist/space-sdk/src/skeleton.d.ts +42 -0
  87. package/dist/space-sdk/src/space.ts +662 -28
  88. package/dist/space-sdk/src/tailwind-candidates.d.ts +761 -6
  89. package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
  90. package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
  91. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
  92. package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
  93. package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
  94. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
  95. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
  96. package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
  97. package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
  98. package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
  99. package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
  100. package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
  101. package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
  102. package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
  103. package/dist/space-sdk/src/ui/index.d.ts +4 -0
  104. package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
  105. package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
  106. package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
  107. package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
  108. package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
  109. package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
  110. package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
  111. package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
  112. package/dist/space-sdk/src/words/shell.ts +1 -0
  113. package/dist/view-renderer/dist/host.js +355 -188
  114. package/dist/view-renderer/dist/theme.css +1 -1
  115. package/dist/view-renderer/src/dom.js +15 -2
  116. package/dist/view-renderer/src/host.tsx +4 -1
  117. package/dist/view-renderer/src/index.js +3 -0
  118. package/dist/view-renderer/src/pool.js +8 -4
  119. package/dist/view-renderer/src/renderer.js +92 -23
  120. package/dist/view-renderer/src/skeleton.js +450 -0
  121. package/package.json +4 -4
  122. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
  123. package/skills/notis-onboarding/BRIEF.md +15 -9
  124. package/skills/notis-spaces/cli.md +43 -4
  125. package/src/command-specs/auth.js +5 -3
  126. package/src/command-specs/cc.js +410 -0
  127. package/src/command-specs/computer.js +320 -0
  128. package/src/command-specs/diagnostics.js +2 -13
  129. package/src/command-specs/documents.js +22 -4
  130. package/src/command-specs/index.js +7 -0
  131. package/src/command-specs/onboarding.js +127 -7
  132. package/src/command-specs/skills.js +2 -2
  133. package/src/command-specs/spaces.js +162 -30
  134. package/src/command-specs/tools.js +26 -8
  135. package/src/command-specs/views.js +4 -1
  136. package/src/runtime/agent-setup.js +20 -2
  137. package/src/runtime/app-boundary-validator.js +2 -1
  138. package/src/runtime/app-platform.js +13 -0
  139. package/src/runtime/auth-recovery.js +5 -0
  140. package/src/runtime/channel.js +16 -2
  141. package/src/runtime/cloud-transfer.js +587 -0
  142. package/src/runtime/computer-ssh.js +127 -0
  143. package/src/runtime/oauth.js +50 -4
  144. package/src/runtime/skill-sync/cloud-client.ts +98 -15
  145. package/src/runtime/skill-sync/index.ts +42 -4
  146. package/src/runtime/skill-sync/local-scanner.ts +1 -0
  147. package/src/runtime/skill-sync/types.ts +6 -0
  148. package/src/runtime/space-audience.js +94 -0
  149. package/src/runtime/space-collection-scaffold.js +2 -1
  150. package/src/runtime/space-fixture-broker.js +2 -1
  151. package/src/runtime/space-lock.js +1 -4
  152. package/src/runtime/space-platform.js +18 -2
  153. package/src/runtime/space-source.js +105 -7
  154. package/src/runtime/space-test-server.js +13 -2
  155. package/src/runtime/space-verification.js +99 -6
  156. package/src/runtime/space-view-manifest.js +22 -4
  157. package/src/runtime/sync-skills.js +24 -20
  158. package/src/runtime/transport.js +19 -0
  159. package/src/runtime/view-render.js +2 -2
  160. package/src/skill-sync-worker.js +5 -1
  161. package/template/.harness/index.html.tmpl +1 -1
  162. package/dist/skill-sync/index.js.map +0 -7
  163. package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
@@ -123,6 +123,7 @@ When to use: Check the actual deployed view; writes are blocked and current acce
123
123
 
124
124
  Options:
125
125
  - `--width <pixels>` — 1440 (default) or 390.
126
+ - `--view-as <audience>` — public: render the view as the public sees it (no editor-only parts).
126
127
  - `--output-dir <path>` — New output directory; defaults to a unique .notis/renders directory. Existing files are never overwritten.
127
128
 
128
129
  Examples:
@@ -193,6 +194,23 @@ Options:
193
194
  Examples:
194
195
  - `npx --package @notis_ai/cli@latest -- notis spaces links remove <space-id> <binding-id> --revision 1 --request-id remove-link-1`
195
196
 
197
+ ### `npx --package @notis_ai/cli@latest -- notis spaces folder <space-id>`
198
+
199
+ Show the folder a Space works in on your Cloud Computer or this computer, or map it to a folder of your own.
200
+
201
+ When to use: Find where a Space keeps its files and builds, or point it at an existing project folder. Each person maps their own folder; clearing a mapping goes back to the Space's own folder, which is never deleted by it.
202
+
203
+ Options:
204
+ - `--map <path>` — Use this folder instead: inside /vercel/sandbox on the Cloud Computer, absolute or ~/ on this computer.
205
+ - `--unmap` — Go back to the Space's own folder.
206
+ - `--target <where>` — cloud (default) for the Cloud Computer, desktop for this computer through Notis Desktop.
207
+
208
+ Examples:
209
+ - `npx --package @notis_ai/cli@latest -- notis spaces folder <space-id>`
210
+ - `npx --package @notis_ai/cli@latest -- notis spaces folder <space-id> --map /vercel/sandbox/my-app`
211
+ - `npx --package @notis_ai/cli@latest -- notis spaces folder <space-id> --target desktop --map ~/code/my-app`
212
+ - `npx --package @notis_ai/cli@latest -- notis spaces folder <space-id> --unmap`
213
+
196
214
  ### `npx --package @notis_ai/cli@latest -- notis spaces aliases list`
197
215
 
198
216
  List the old App page links you manage and the Space each one opens.
@@ -424,14 +442,28 @@ When to use: See which installed copies have an update or conflicts to resolve.
424
442
  Examples:
425
443
  - `npx --package @notis_ai/cli@latest -- notis spaces store installs`
426
444
 
445
+ ### `npx --package @notis_ai/cli@latest -- notis spaces store check <listing-id>`
446
+
447
+ Check a Store listing, or the update of an installed copy, before installing it.
448
+
449
+ When to use: Always before store install or store update: it returns the risks in plain words, a recommendation, the trust line of a Space shared by link and a receipt valid one hour. Tell the person, wait for their yes, then install with --receipt and --confirmed.
450
+
451
+ Options:
452
+ - `--install <install-id>` — Check only what the update of this installed copy changes.
453
+ - `--locale <en|fr>` — The person's language for the risks and the trust line.
454
+
455
+ Examples:
456
+ - `npx --package @notis_ai/cli@latest -- notis spaces store check <listing-id>`
457
+ - `npx --package @notis_ai/cli@latest -- notis spaces store check <listing-id> --install <install-id> --locale fr`
458
+
427
459
  ### `npx --package @notis_ai/cli@latest -- notis spaces store publish <space-id>`
428
460
 
429
461
  Publish a Space and its sub-Spaces as the next Store version.
430
462
 
431
- When to use: Share a Space you own as an installable template: team listings publish at once, public ones wait for review. Notis runs the same safety scan and Owner check as the submission page and explains any refusal.
463
+ When to use: Share a Space you own as an installable template: link and team listings publish at once, public ones wait for review. A link listing never shows in the Store; only people with its link see it. Notis runs the same safety scan and Owner check as the submission page and explains any refusal.
432
464
 
433
465
  Options:
434
- - `--channel <team|public>` — Where to publish.
466
+ - `--channel <link|team|public>` — Where to publish: anyone with the link, your team or everyone.
435
467
  - `--metadata <json>` — Listing name, tagline, description, category, icon, accent.
436
468
  - `--starter <json>` — Starter row IDs per database ({"<database-id>":["<record-key>"]}).
437
469
  - `--notes <text>` — Release notes for this version.
@@ -440,21 +472,24 @@ Options:
440
472
 
441
473
  Examples:
442
474
  - `npx --package @notis_ai/cli@latest -- notis spaces store publish <space-id> --channel team --request-id publish-1 --dry-run`
475
+ - `npx --package @notis_ai/cli@latest -- notis spaces store publish <space-id> --channel link --request-id share-link-1`
443
476
 
444
477
  ### `npx --package @notis_ai/cli@latest -- notis spaces store install <listing-id>`
445
478
 
446
479
  Install a Store listing as your own independent copy.
447
480
 
448
- When to use: Add a published Space template to your account; your copy keeps your changes on later updates.
481
+ When to use: Add a published Space template to your account after store check and the person's yes; your copy keeps your changes on later updates and its automations arrive paused.
449
482
 
450
483
  Options:
451
484
  - `--name <name>` — Name of the installed top Space.
452
485
  - `--parent <space-id>` — Install under one of your Spaces.
486
+ - `--receipt <receipt-id>` — The receipt_id store check returned for this exact version.
487
+ - `--confirmed` — The person said yes to the risks store check reported.
453
488
  - `--request-id <key>` — Stable intent key. Reuse after timeouts or lost replies.
454
489
  - `--dry-run` — Show what the copy contains without installing.
455
490
 
456
491
  Examples:
457
- - `npx --package @notis_ai/cli@latest -- notis spaces store install <listing-id> --request-id install-1`
492
+ - `npx --package @notis_ai/cli@latest -- notis spaces store install <listing-id> --request-id install-1 --receipt <receipt-id> --confirmed`
458
493
 
459
494
  ### `npx --package @notis_ai/cli@latest -- notis spaces store update <install-id>`
460
495
 
@@ -464,11 +499,14 @@ When to use: Take a newer Store version: unchanged parts update, your edits stay
464
499
 
465
500
  Options:
466
501
  - `--resolve <json>` — Per conflict key: "keep_mine" or "take_theirs".
502
+ - `--receipt <receipt-id>` — The receipt_id store check returned for this exact version.
503
+ - `--confirmed` — The person said yes to the risks store check reported.
467
504
  - `--request-id <key>` — Stable intent key. Reuse after timeouts or lost replies.
468
505
  - `--dry-run` — Show the three-way plan without changing anything.
469
506
 
470
507
  Examples:
471
508
  - `npx --package @notis_ai/cli@latest -- notis spaces store update <install-id> --request-id update-1 --dry-run`
509
+ - `npx --package @notis_ai/cli@latest -- notis spaces store update <install-id> --request-id update-1 --receipt <receipt-id> --confirmed`
472
510
  - `npx --package @notis_ai/cli@latest -- notis spaces store update <install-id> --resolve '{"skill:<key>":"keep_mine"}' --request-id resolve-1`
473
511
 
474
512
  ### `npx --package @notis_ai/cli@latest -- notis spaces store unpublish <listing-id>`
@@ -534,6 +572,7 @@ When to use: Check the actual deployed view; writes are blocked and current acce
534
572
  Options:
535
573
  - `--outputs <kinds>` — Comma-separated markdown,screenshot (default both).
536
574
  - `--width <pixels>` — 1440 (default) or 390.
575
+ - `--view-as <audience>` — public: render the view as the public sees it (no editor-only parts).
537
576
  - `--output-dir <path>` — New output directory; defaults to a unique .notis/renders directory. Existing files are never overwritten.
538
577
 
539
578
  Examples:
@@ -56,9 +56,11 @@ export function loginAgentAuthorizationPresentation(authorization) {
56
56
  ? authorization?.confirm_command
57
57
  : authorization?.redeem_command;
58
58
  return {
59
- humanSummary: browserHandOff
60
- ? 'Give the user the authorization URL. Signing in there completes it — there is no code to ask them for.'
61
- : 'Give the user the authorization URL, then ask them for the code it shows.',
59
+ humanSummary: browserHandOff && authorization?.browser_opened
60
+ ? 'A Notis sign-in page opened in the user\'s browser. Tell them to sign in there (there is no code to copy), then run confirm_command. Give them the authorization URL only if they do not see the page.'
61
+ : browserHandOff
62
+ ? 'Give the user the authorization URL. Signing in there completes it — there is no code to ask them for.'
63
+ : 'Give the user the authorization URL, then ask them for the code it shows.',
62
64
  hints: nextCommand
63
65
  ? [{
64
66
  command: nextCommand,
@@ -0,0 +1,410 @@
1
+ /**
2
+ * `notis cc`: the user's Cloud Computer from a terminal. run and job go
3
+ * through LOCAL_NOTIS_RUN_SANDBOX_SHELL, so the server keeps its entitlement,
4
+ * Space-edit and job checks. push and pull open a direct transfer session
5
+ * (POST /portal_spaces/cloud-transfer, runtime/cloud-transfer.js): the server
6
+ * checks the same things, then the bytes go straight to the machine's gate.
7
+ */
8
+ import { randomUUID } from 'node:crypto';
9
+ import fs from 'node:fs';
10
+ import { formatBytes, pull, push } from '../runtime/cloud-transfer.js';
11
+ import { CliError, EXIT_CODES, usageError } from '../runtime/errors.js';
12
+ import { extractToolResult } from '../runtime/tool-confirmation.js';
13
+ import { findUpsell, renderUpsell } from '../runtime/upsell.js';
14
+ import { nextIdempotencyKey, runToolCommand } from './helpers.js';
15
+ import { toolCallTimeoutMs } from './tools.js';
16
+
17
+ export const SANDBOX_SHELL_TOOL = 'LOCAL_NOTIS_RUN_SANDBOX_SHELL';
18
+ const ATTACHED_MAX_TIMEOUT_MS = 720000;
19
+ const JOB_MAX_TIMEOUT_MS = 21600000;
20
+ const FOLLOW_INTERVAL_MS = 2000;
21
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
22
+ const JOB_ID = /^[A-Za-z0-9._:-]{1,200}$/;
23
+
24
+ function commandName(ctx) {
25
+ return ctx.spec.command_path.join(' ');
26
+ }
27
+
28
+ function jobId(ctx) {
29
+ const value = ctx.args.jobId;
30
+ if (typeof value !== 'string' || !JOB_ID.test(value)) throw usageError('Pass the job id that notis cc run --detach printed.');
31
+ return value;
32
+ }
33
+
34
+ function nonNegativeInteger(value, flag) {
35
+ if (value === undefined) return undefined;
36
+ const parsed = Number(value);
37
+ if (!/^\d+$/.test(String(value)) || !Number.isSafeInteger(parsed)) throw usageError(`${flag} is a whole number of bytes, 0 or more.`);
38
+ return parsed;
39
+ }
40
+
41
+ /** `--timeout-ms` is the global flag: for cc run it bounds the command (or the detached job). */
42
+ function commandTimeoutMs(ctx, detach) {
43
+ const raw = ctx.options.timeoutMs ?? ctx.globalOptions.timeoutMs;
44
+ if (raw === undefined) return undefined;
45
+ const value = Number(raw);
46
+ const max = detach ? JOB_MAX_TIMEOUT_MS : ATTACHED_MAX_TIMEOUT_MS;
47
+ if (!/^\d+$/.test(String(raw)) || !Number.isSafeInteger(value) || value < 1000 || value > max) {
48
+ throw usageError(detach
49
+ ? '--timeout-ms bounds the detached job: 1000 to 21600000 (6 hours).'
50
+ : '--timeout-ms bounds the command: 1000 to 720000 (12 minutes). Use --detach for longer work.');
51
+ }
52
+ return value;
53
+ }
54
+
55
+ /** One shell tool call; reads use a fresh key so a poll never replays an earlier answer. */
56
+ async function callShell(ctx, args, { mutating }) {
57
+ // A detached job's --timeout-ms is the job's bound, never this call's wait;
58
+ // every call still gets the long-running floor (waking the machine takes time).
59
+ const base = args.detach && ctx.globalOptions.timeoutMs !== undefined ? 0 : ctx.runtime.timeoutMs;
60
+ const timeoutMs = toolCallTimeoutMs(SANDBOX_SHELL_TOOL, args, base);
61
+ const result = await runToolCommand({
62
+ runtime: { ...ctx.runtime, timeoutMs },
63
+ toolName: SANDBOX_SHELL_TOOL,
64
+ arguments_: args,
65
+ mutating,
66
+ idempotencyKey: mutating ? nextIdempotencyKey(ctx.globalOptions) : randomUUID(),
67
+ sendIdempotencyKeyWhenReading: true,
68
+ });
69
+ return { result, payload: extractToolResult(result.payload) || {} };
70
+ }
71
+
72
+ /** Plan limits come back as an upsell prompt, never a bare refusal. */
73
+ function upsellResponse(ctx, result, payload) {
74
+ const body = findUpsell(payload);
75
+ if (!body) return null;
76
+ const rendered = renderUpsell(body, { apiBase: ctx.runtime.apiBase });
77
+ return ctx.output.emitSuccess({ command: commandName(ctx), data: payload, humanSummary: rendered.message,
78
+ requestId: result.requestId, hints: rendered.hints, meta: { mutating: false, upsell: rendered.upsell },
79
+ renderHuman: () => rendered.text });
80
+ }
81
+
82
+ /** A refusal (no command ran, unknown job, no access) is an error; a command that exited non-zero is not. */
83
+ function refusal(payload) {
84
+ if (payload.status !== 'error' || Number.isInteger(payload.exit_code)) return null;
85
+ const notFound = payload.error === 'cloud_computer_job_unknown' || payload.code === 'cloud_computer_job_unknown';
86
+ return new CliError({
87
+ code: payload.error || payload.code || payload.error_code || 'cloud_computer_error',
88
+ message: payload.message || payload.stderr || 'The Cloud Computer could not do this.',
89
+ exitCode: notFound ? EXIT_CODES.usage : EXIT_CODES.backend,
90
+ details: payload,
91
+ });
92
+ }
93
+
94
+ function jobHints(id) {
95
+ return [
96
+ { command: `notis cc job logs ${id} --follow`, reason: 'Stream its output until it ends' },
97
+ { command: `notis cc job status ${id}`, reason: 'Check whether it is still running' },
98
+ { command: `notis cc job cancel ${id}`, reason: 'Stop it' },
99
+ ];
100
+ }
101
+
102
+ function describeJob(job) {
103
+ if (!job) return '';
104
+ const exit = job.exit_code === null || job.exit_code === undefined ? '' : `, exit code ${job.exit_code}`;
105
+ return `Job ${job.job_id}: ${job.status}${exit}, ${job.log_bytes ?? 0} bytes of output.`;
106
+ }
107
+
108
+ async function runHandler(ctx) {
109
+ const command = ctx.args.command;
110
+ if (typeof command !== 'string' || !command.trim()) throw usageError('Pass the command to run, in quotes.');
111
+ if (command.includes('\0')) throw usageError('The command cannot contain a NUL character.');
112
+ const detach = Boolean(ctx.options.detach);
113
+ const space = ctx.options.space;
114
+ if (space !== undefined && (typeof space !== 'string' || !UUID.test(space))) throw usageError('--space takes the Space id (a UUID).');
115
+ const cwd = ctx.options.cwd;
116
+ if (cwd !== undefined && (typeof cwd !== 'string' || !cwd || cwd.includes('\0'))) throw usageError('--cwd takes a folder on the Cloud Computer.');
117
+ const timeoutMs = commandTimeoutMs(ctx, detach);
118
+ const args = { command, ...(detach ? { detach: true } : {}), ...(space ? { space_id: space } : {}),
119
+ ...(cwd ? { cwd } : {}), ...(timeoutMs ? { timeout_ms: timeoutMs } : {}) };
120
+ ctx.output.emitProgress({ phase: 'execute', message: detach ? 'Starting a job on your Cloud Computer' : 'Running on your Cloud Computer' });
121
+ const { result, payload } = await callShell(ctx, args, { mutating: true });
122
+ const upsell = upsellResponse(ctx, result, payload);
123
+ if (upsell !== null) return upsell;
124
+ const refused = refusal(payload);
125
+ if (refused) throw refused;
126
+ if (detach) {
127
+ const id = payload.job_id || payload.job?.job_id;
128
+ if (!id) throw new CliError({ code: 'cloud_computer_job_missing', message: 'The Cloud Computer did not return a job id.', exitCode: EXIT_CODES.backend, details: payload });
129
+ return ctx.output.emitSuccess({ command: commandName(ctx), data: payload, requestId: result.requestId,
130
+ humanSummary: `Started job ${id}.`, hints: jobHints(id), meta: { mutating: true },
131
+ renderHuman: () => `Started job ${id}.\n${describeJob(payload.job)}`.trim() });
132
+ }
133
+ const exitCode = Number.isInteger(payload.exit_code) ? payload.exit_code : null;
134
+ const code = ctx.output.emitSuccess({ command: commandName(ctx), data: payload, requestId: result.requestId,
135
+ humanSummary: `Exited with code ${exitCode ?? 'unknown'}.`, meta: { mutating: true },
136
+ renderHuman: () => {
137
+ if (payload.stderr) process.stderr.write(payload.stderr.endsWith('\n') ? payload.stderr : `${payload.stderr}\n`);
138
+ return (payload.stdout || '').replace(/\n$/, '');
139
+ } });
140
+ // In a terminal the command's own exit code comes through, like a local shell.
141
+ return !ctx.output.isMachineMode?.() && exitCode ? Math.min(exitCode, 255) : code;
142
+ }
143
+
144
+ async function jobStatusHandler(ctx) {
145
+ const id = jobId(ctx);
146
+ const { result, payload } = await callShell(ctx, { job_id: id, job_action: 'status' }, { mutating: false });
147
+ const upsell = upsellResponse(ctx, result, payload);
148
+ if (upsell !== null) return upsell;
149
+ const refused = refusal(payload);
150
+ if (refused) throw refused;
151
+ const job = payload.job || payload;
152
+ const hints = job.status === 'running'
153
+ ? jobHints(id).filter(hint => !hint.command.startsWith('notis cc job status'))
154
+ : [{ command: `notis cc job logs ${id}`, reason: 'Read what it printed' }];
155
+ return ctx.output.emitSuccess({ command: commandName(ctx), data: payload, requestId: result.requestId,
156
+ humanSummary: describeJob(job), hints, meta: { mutating: false } });
157
+ }
158
+
159
+ async function jobCancelHandler(ctx) {
160
+ const id = jobId(ctx);
161
+ const { result, payload } = await callShell(ctx, { job_id: id, job_action: 'cancel' }, { mutating: true });
162
+ const upsell = upsellResponse(ctx, result, payload);
163
+ if (upsell !== null) return upsell;
164
+ const refused = refusal(payload);
165
+ if (refused) throw refused;
166
+ return ctx.output.emitSuccess({ command: commandName(ctx), data: payload, requestId: result.requestId,
167
+ humanSummary: describeJob(payload.job || payload), meta: { mutating: true } });
168
+ }
169
+
170
+ async function jobLogsHandler(ctx) {
171
+ const id = jobId(ctx);
172
+ const follow = Boolean(ctx.options.follow);
173
+ let offset = nonNegativeInteger(ctx.options.offset, '--offset') ?? 0;
174
+ const sleep = typeof ctx.sleep === 'function' ? ctx.sleep : ms => new Promise(resolve => setTimeout(resolve, ms));
175
+ const streaming = follow && !ctx.output.isMachineMode?.();
176
+ const startOffset = offset;
177
+ let text = '', last = null, requestId = null, idleAfterEnd = 0;
178
+ for (;;) {
179
+ const { result, payload } = await callShell(ctx, { job_id: id, job_action: 'logs', log_offset: offset }, { mutating: false });
180
+ const upsell = upsellResponse(ctx, result, payload);
181
+ if (upsell !== null) return upsell;
182
+ const refused = refusal(payload);
183
+ if (refused) throw refused;
184
+ requestId = result.requestId;
185
+ last = payload;
186
+ // Only bytes past what was already printed: a repeated offset prints nothing twice.
187
+ const advanced = Number.isInteger(payload.next_offset) && payload.next_offset > offset;
188
+ if (advanced) {
189
+ const chunk = typeof payload.text === 'string' ? payload.text : '';
190
+ text += chunk;
191
+ if (streaming && chunk) process.stdout.write(chunk);
192
+ offset = payload.next_offset;
193
+ }
194
+ if (!follow || payload.eof === true) break;
195
+ if (payload.status !== 'running') {
196
+ // An ended job with bytes left is read again at once; one that stops
197
+ // advancing without eof is not polled forever.
198
+ if (advanced) continue;
199
+ if (++idleAfterEnd >= 3) break;
200
+ }
201
+ await sleep(FOLLOW_INTERVAL_MS);
202
+ }
203
+ const data = { job_id: id, status: last?.status ?? null, text, offset: startOffset, next_offset: offset, eof: last?.eof === true };
204
+ const summary = data.eof ? `Job ${id} ${data.status}; all output read.` : `Job ${id} ${data.status}; read up to byte ${offset}.`;
205
+ return ctx.output.emitSuccess({ command: commandName(ctx), data, requestId, humanSummary: summary,
206
+ hints: data.eof ? [] : [{ command: `notis cc job logs ${id} --offset ${offset}${follow ? '' : ' --follow'}`, reason: 'Read the next output' }],
207
+ meta: { mutating: false },
208
+ renderHuman: () => {
209
+ if (streaming) { ctx.output.note(summary); return ''; }
210
+ return text.replace(/\n$/, '');
211
+ } });
212
+ }
213
+
214
+ const MACHINE_ROOT = '/vercel/sandbox';
215
+
216
+ /** --space <id> [--dest files/...] (inside the Space folder) or --dest /vercel/sandbox/... (a folder on the machine). */
217
+ function transferTarget(ctx, { required }) {
218
+ const space = ctx.options.space;
219
+ const dest = ctx.options.dest;
220
+ if (space !== undefined && (typeof space !== 'string' || !UUID.test(space))) throw usageError('--space takes the Space id (a UUID).');
221
+ if (dest !== undefined && (typeof dest !== 'string' || !dest || dest.includes('\0'))) throw usageError('--dest takes a folder.');
222
+ if (space) {
223
+ if (dest && dest.startsWith('/')) throw usageError('With --space, --dest is a folder inside the Space folder, such as files/launch.');
224
+ return { spaceId: space, dest: dest || (required ? 'files' : undefined) };
225
+ }
226
+ if (!dest || !dest.startsWith(`${MACHINE_ROOT}/`)) {
227
+ throw usageError(`Pass --space <space-id> (and optionally --dest files/...), or --dest with a full folder inside ${MACHINE_ROOT}.`);
228
+ }
229
+ return { path: dest };
230
+ }
231
+
232
+ function streamsOption(ctx) {
233
+ const raw = ctx.options.streams;
234
+ if (raw === undefined) return undefined;
235
+ const value = Number(raw);
236
+ if (!/^\d+$/.test(String(raw)) || value < 1 || value > 32) throw usageError('--streams is a whole number from 1 to 32.');
237
+ return value;
238
+ }
239
+
240
+ function rate(value) {
241
+ return value ? `${formatBytes(value)}/s` : 'n/a';
242
+ }
243
+
244
+ async function pushHandler(ctx) {
245
+ const local = ctx.args.local;
246
+ if (typeof local !== 'string' || !local || !fs.existsSync(local)) throw usageError('Pass a file or folder on this computer.');
247
+ const target = transferTarget(ctx, { required: true });
248
+ ctx.output.emitProgress({ phase: 'prepare', message: 'Preparing a direct transfer to your Cloud Computer' });
249
+ const result = await push(ctx, local, target, { streams: streamsOption(ctx), followLinks: !ctx.options.skipLinks });
250
+ const summary = result.already_committed
251
+ ? `Already on your Cloud Computer in ${result.root} (${result.files} files).`
252
+ : `Sent ${result.files} files (${formatBytes(result.total_bytes)}) to ${result.root} in ${Math.round(result.seconds)} s.`;
253
+ return ctx.output.emitSuccess({ command: commandName(ctx), data: result, humanSummary: summary, meta: { mutating: true },
254
+ renderHuman: () => {
255
+ const lines = [summary];
256
+ if (!result.already_committed) {
257
+ lines.push(`Large files: ${formatBytes(result.large.bytes)} at ${rate(result.large.bytes_per_second)}. Small files: ${formatBytes(result.small.bytes)} at ${rate(result.small.bytes_per_second)}.`);
258
+ if (result.resumed_from_bytes) lines.push(`Resumed: ${formatBytes(result.resumed_from_bytes)} were already there.`);
259
+ }
260
+ if (result.skipped.length) lines.push(`Skipped ${result.skipped.length}: ${result.skipped.slice(0, 5).map(item => `${item.path} (${item.reason})`).join(', ')}`);
261
+ return lines.join('\n');
262
+ } });
263
+ }
264
+
265
+ async function pullHandler(ctx) {
266
+ const remote = ctx.args.remote;
267
+ const local = ctx.args.local;
268
+ if (typeof remote !== 'string' || !remote) throw usageError('Pass the file or folder to copy from the Cloud Computer.');
269
+ if (typeof local !== 'string' || !local) throw usageError('Pass where to put it on this computer.');
270
+ const space = ctx.options.space;
271
+ if (space !== undefined && (typeof space !== 'string' || !UUID.test(space))) throw usageError('--space takes the Space id (a UUID).');
272
+ let target;
273
+ if (space) {
274
+ if (remote.startsWith('/')) throw usageError('With --space, the remote path is inside the Space folder, such as files/render.mp4.');
275
+ target = { spaceId: space, dest: remote };
276
+ } else {
277
+ if (!remote.startsWith(`${MACHINE_ROOT}/`)) throw usageError(`Pass a full path inside ${MACHINE_ROOT}, or --space with a path inside the Space folder.`);
278
+ target = { path: remote };
279
+ }
280
+ const result = await pull(ctx, target, local, { streams: streamsOption(ctx) });
281
+ const summary = `Received ${result.files} files (${formatBytes(result.total_bytes)}) into ${result.local} in ${Math.round(result.seconds)} s`
282
+ + (result.unchanged_files ? `; ${result.unchanged_files} were already identical.` : '.');
283
+ return ctx.output.emitSuccess({ command: commandName(ctx), data: result, humanSummary: summary, meta: { mutating: false } });
284
+ }
285
+
286
+ const jobArgument = { token: '<job-id>', key: 'jobId', description: 'Job id printed by notis cc run --detach.' };
287
+
288
+ export const ccCommandSpecs = [
289
+ {
290
+ command_path: ['cc', 'run'],
291
+ summary: 'Run a shell command on your Cloud Computer, or start it as a background job.',
292
+ when_to_use: 'Use this for builds, installs, scripts and servers on the Cloud Computer. Add --detach for work longer than 12 minutes, then follow it with notis cc job logs. Add --space to run in a Space folder (you must be able to edit that Space).',
293
+ args_schema: {
294
+ arguments: [{ token: '<command>', description: 'Shell command, run with bash -lc. Quote it.' }],
295
+ options: [
296
+ { flags: '--detach', description: 'Start it as a background job and print its job id at once.' },
297
+ { flags: '--space <space-id>', description: 'Run in this Space folder: NOTIS_SPACE_DIR is set, and without --cwd the command starts there.' },
298
+ { flags: '--cwd <dir>', description: 'Folder to start in, inside /vercel/sandbox.' },
299
+ { flags: '--timeout-ms <n>', description: 'Time limit of the command (1000 to 720000), or of the detached job (up to 21600000, 6 hours).' },
300
+ ],
301
+ },
302
+ examples: [
303
+ 'notis cc run "npm test" --cwd /vercel/sandbox/app',
304
+ 'notis cc run "npm run build" --space <space-id> --detach --timeout-ms 3600000',
305
+ ],
306
+ output_schema: 'Attached: { status, stdout, stderr, exit_code, timeout_ms }. Detached: { status, job_id, job: { job_id, status, exit_code, started_at, ended_at, log_bytes } }.',
307
+ mutates: true,
308
+ idempotent: true,
309
+ require_auth: true,
310
+ related_commands: ['notis cc job logs <job-id>', 'notis cc job status <job-id>', 'notis cc job cancel <job-id>', 'notis spaces folder <space-id>'],
311
+ backend_call: { type: 'tool', name: SANDBOX_SHELL_TOOL },
312
+ handler: runHandler,
313
+ },
314
+ {
315
+ command_path: ['cc', 'push'],
316
+ summary: 'Copy a file or folder from this computer to your Cloud Computer, straight to the machine.',
317
+ when_to_use: 'Use this for big files and whole project folders (videos, datasets, builds). Small files travel in batches, big ones in 32 MB parts over parallel streams; the bytes never pass through Notis servers. If the link drops or you stop it, run the same command again: it sends only what is missing. Links are followed like scp unless --skip-links is set.',
318
+ args_schema: {
319
+ arguments: [{ token: '<local>', key: 'local', description: 'File or folder on this computer.' }],
320
+ options: [
321
+ { flags: '--space <space-id>', description: 'Put it in this Space folder (you must be able to edit the Space).' },
322
+ { flags: '--dest <folder>', description: 'With --space: a folder inside the Space folder (default files). Without: a full folder inside /vercel/sandbox.' },
323
+ { flags: '--streams <n>', description: 'Parallel streams (default 8).' },
324
+ { flags: '--skip-links', description: 'Do not follow symbolic links.' },
325
+ ],
326
+ },
327
+ examples: [
328
+ 'notis cc push ./launch-video --space <space-id> --dest files/launch',
329
+ 'notis cc push dataset.parquet --dest /vercel/sandbox/data',
330
+ ],
331
+ output_schema: 'Returns { status, session_id, root, files, total_bytes, committed_bytes, sent_bytes, seconds, resumed_from_bytes, large: { bytes, bytes_per_second }, small: { bytes, bytes_per_second }, skipped }.',
332
+ mutates: true,
333
+ idempotent: true,
334
+ require_auth: true,
335
+ related_commands: ['notis cc pull <remote> <local>', 'notis spaces folder <space-id>'],
336
+ backend_call: { type: 'http', path: '/portal_spaces/cloud-transfer' },
337
+ handler: pushHandler,
338
+ },
339
+ {
340
+ command_path: ['cc', 'pull'],
341
+ summary: 'Copy a file or folder from your Cloud Computer to this computer, straight from the machine.',
342
+ when_to_use: 'Use this to bring renders, exports or results back. Downloads resume where they stopped when you run the same command again, and every file is checked against its sha256.',
343
+ args_schema: {
344
+ arguments: [
345
+ { token: '<remote>', key: 'remote', description: 'With --space: a path inside the Space folder. Without: a full path inside /vercel/sandbox.' },
346
+ { token: '<local>', key: 'local', description: 'Where to put it on this computer.' },
347
+ ],
348
+ options: [
349
+ { flags: '--space <space-id>', description: 'Read from this Space folder.' },
350
+ { flags: '--streams <n>', description: 'Parallel streams (default 8).' },
351
+ ],
352
+ },
353
+ examples: ['notis cc pull files/render.mp4 ./ --space <space-id>', 'notis cc pull /vercel/sandbox/app/dist ./dist'],
354
+ output_schema: 'Returns { status, session_id, root, local, files, total_bytes, unchanged_files, seconds, skipped }.',
355
+ mutates: false,
356
+ idempotent: true,
357
+ require_auth: true,
358
+ related_commands: ['notis cc push <local>'],
359
+ backend_call: { type: 'http', path: '/portal_spaces/cloud-transfer' },
360
+ handler: pullHandler,
361
+ },
362
+ {
363
+ command_path: ['cc', 'job', 'status'],
364
+ summary: 'Show whether a Cloud Computer job is running, and how it ended.',
365
+ when_to_use: 'Use this after notis cc run --detach to check a background job.',
366
+ args_schema: { arguments: [jobArgument], options: [] },
367
+ examples: ['notis cc job status <job-id>'],
368
+ output_schema: 'Returns { job_id, status (running, succeeded, failed, cancelled, timed_out or lost), exit_code, started_at, ended_at, log_bytes }.',
369
+ mutates: false,
370
+ idempotent: true,
371
+ require_auth: true,
372
+ related_commands: ['notis cc job logs <job-id>', 'notis cc job cancel <job-id>'],
373
+ backend_call: { type: 'tool', name: SANDBOX_SHELL_TOOL },
374
+ handler: jobStatusHandler,
375
+ },
376
+ {
377
+ command_path: ['cc', 'job', 'logs'],
378
+ summary: 'Read the output of a Cloud Computer job, or follow it until the job ends.',
379
+ when_to_use: 'Use this to see what a background job printed. --follow checks every 2 seconds and prints only new output; pass --offset to continue from an earlier next_offset.',
380
+ args_schema: {
381
+ arguments: [jobArgument],
382
+ options: [
383
+ { flags: '--offset <n>', description: 'Byte to start reading from (default 0).' },
384
+ { flags: '--follow', description: 'Keep reading every 2 seconds until the job ends and all output is read.' },
385
+ ],
386
+ },
387
+ examples: ['notis cc job logs <job-id>', 'notis cc job logs <job-id> --follow', 'notis cc job logs <job-id> --offset 65536'],
388
+ output_schema: 'Returns { job_id, status, text, offset, next_offset, eof }; eof is true once the job ended and every byte was read.',
389
+ mutates: false,
390
+ idempotent: true,
391
+ require_auth: true,
392
+ related_commands: ['notis cc job status <job-id>', 'notis cc job cancel <job-id>'],
393
+ backend_call: { type: 'tool', name: SANDBOX_SHELL_TOOL },
394
+ handler: jobLogsHandler,
395
+ },
396
+ {
397
+ command_path: ['cc', 'job', 'cancel'],
398
+ summary: 'Stop a running Cloud Computer job.',
399
+ when_to_use: 'Use this to stop a background job started with notis cc run --detach.',
400
+ args_schema: { arguments: [jobArgument], options: [] },
401
+ examples: ['notis cc job cancel <job-id>'],
402
+ output_schema: 'Returns the job status after the cancel.',
403
+ mutates: true,
404
+ idempotent: true,
405
+ require_auth: true,
406
+ related_commands: ['notis cc job status <job-id>'],
407
+ backend_call: { type: 'tool', name: SANDBOX_SHELL_TOOL },
408
+ handler: jobCancelHandler,
409
+ },
410
+ ];