@notis_ai/cli 0.2.32 → 0.2.34

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 (95) hide show
  1. package/README.md +75 -11
  2. package/dist/agent-hooks/notis-agent-hook.mjs +4407 -905
  3. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  4. package/dist/base-skills/notis-cli/SKILL.md +7 -3
  5. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  6. package/dist/base-skills/notis-spaces/SKILL.md +5 -3
  7. package/dist/base-skills/notis-spaces/references/comments.md +102 -0
  8. package/dist/base-skills/notis-spaces/references/context.md +20 -19
  9. package/dist/base-skills/notis-spaces/references/design.md +3 -2
  10. package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
  11. package/dist/base-skills/notis-spaces/references/store.md +24 -1
  12. package/dist/sdk/src/components/NotisSelectionBoundary.tsx +13 -5
  13. package/dist/sdk/src/components/SelectionActionBar.tsx +45 -8
  14. package/dist/sdk/src/components/SpaceTextComments.tsx +293 -0
  15. package/dist/sdk/src/components/selectionRange.ts +65 -0
  16. package/dist/sdk/src/config.ts +3 -1
  17. package/dist/sdk/src/functions.ts +218 -0
  18. package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
  19. package/dist/sdk/src/hooks/useCollectionInteractions.ts +66 -9
  20. package/dist/sdk/src/hooks/useConnection.ts +102 -0
  21. package/dist/sdk/src/hooks/useFunction.ts +42 -0
  22. package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
  23. package/dist/sdk/src/index.ts +16 -4
  24. package/dist/sdk/src/interactions/shortcuts.tsx +6 -1
  25. package/dist/sdk/src/interactions/swipeDownToDismiss.ts +158 -0
  26. package/dist/sdk/src/interactions/textBoxTwoState.ts +174 -0
  27. package/dist/sdk/src/interactions.ts +17 -0
  28. package/dist/sdk/src/runtime.ts +16 -1
  29. package/dist/sdk/src/space.ts +401 -33
  30. package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
  31. package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
  32. package/dist/skill-sync/index.js +262 -31
  33. package/dist/skill-sync-worker.mjs +515 -127
  34. package/dist/space-harness/host.js +389 -154
  35. package/dist/space-sdk/dist/chunk-3NPBCE6E.js +3 -0
  36. package/dist/space-sdk/dist/index.js +3 -3
  37. package/dist/space-sdk/dist/ui.js +16 -11
  38. package/dist/space-sdk/src/config.ts +3 -1
  39. package/dist/space-sdk/src/functions.ts +218 -0
  40. package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
  41. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +7 -0
  42. package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
  43. package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
  44. package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
  45. package/dist/space-sdk/src/index.d.ts +10 -4
  46. package/dist/space-sdk/src/interactions/shortcuts.d.ts +5 -0
  47. package/dist/space-sdk/src/runtime.d.ts +14 -1
  48. package/dist/space-sdk/src/space.ts +401 -33
  49. package/dist/space-sdk/src/tailwind-candidates.d.ts +400 -204
  50. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +90 -15
  51. package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +4 -1
  52. package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +4 -2
  53. package/dist/space-sdk/src/ui/comments/commentDrafts.d.ts +63 -0
  54. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +59 -88
  55. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +32 -1
  56. package/dist/space-sdk/src/ui/comments/handover.d.ts +34 -0
  57. package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
  58. package/dist/space-sdk/src/ui/comments/hostPanel.d.ts +113 -0
  59. package/dist/space-sdk/src/ui/comments/index.d.ts +7 -2
  60. package/dist/space-sdk/src/ui/comments/paneOutlet.d.ts +33 -0
  61. package/dist/space-sdk/src/ui/comments/paneParts.d.ts +71 -27
  62. package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
  63. package/dist/space-sdk/src/ui/comments/reviewRun.d.ts +190 -0
  64. package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
  65. package/dist/space-sdk/src/ui/comments/useComments.d.ts +116 -77
  66. package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
  67. package/dist/space-sdk/src/ui/index.d.ts +1 -1
  68. package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
  69. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
  70. package/dist/view-renderer/dist/host.js +450 -215
  71. package/package.json +3 -3
  72. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
  73. package/skills/notis-spaces/cli.md +3 -3
  74. package/src/cli.js +2 -1
  75. package/src/command-specs/index.js +3 -0
  76. package/src/command-specs/repository-secrets.js +171 -0
  77. package/src/command-specs/spaces.js +3 -3
  78. package/src/runtime/agent-credential.js +175 -0
  79. package/src/runtime/agent-identity.js +95 -19
  80. package/src/runtime/app-platform.js +8 -0
  81. package/src/runtime/auth-recovery.js +14 -0
  82. package/src/runtime/profiles.js +74 -2
  83. package/src/runtime/skill-sync/cloud-client.ts +33 -3
  84. package/src/runtime/skill-sync/index.ts +4 -3
  85. package/src/runtime/skill-sync/symlink-manager.ts +354 -35
  86. package/src/runtime/skill-sync/types.ts +14 -2
  87. package/src/runtime/space-functions.js +213 -0
  88. package/src/runtime/space-platform.js +12 -3
  89. package/src/runtime/space-source.js +116 -13
  90. package/src/runtime/space-test-server.js +22 -4
  91. package/src/runtime/space-verification.js +3 -1
  92. package/src/runtime/transport.js +15 -0
  93. package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
  94. package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
  95. package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
@@ -34,19 +34,25 @@ export const SPACE_VIEWER_READ_OPERATIONS: Readonly<Record<SpaceViewerReadOperat
34
34
  export type SpaceCloudComputerLevel = 'read' | 'shell';
35
35
 
36
36
  /**
37
- * One agent a Space's database changes wake, declared in `defineSpace({ agents })`.
37
+ * One agent a Space wakes, declared in `defineSpace({ agents })`.
38
+ * `on: 'comments'`: the comments of this Space (a person's new comment, reply, answer or edit). `on: { database }`:
39
+ * changes to one of its databases. `event` narrows to new items (`created`) or changes (`changed`).
38
40
  * `thread`: `best_match` (the person's thread linked to the item, else a new one linked to it) or `space`
39
41
  * (one thread per Space and person). `runtime`: hosted (`notis`) or a coding agent on the person's Cloud
40
42
  * Computer. `wake: 'sent'` wakes only for replies to and answers on the agent's own comments.
41
- * `columns` renames the comment columns read (defaults: Thread, Deck, Answer, Author).
42
43
  */
43
44
  export interface SpaceAgentDeclaration {
44
45
  id: string;
45
- on: { database: string; event?: 'created' | 'changed' };
46
+ on: 'comments' | { database: string; event?: 'created' | 'changed' };
47
+ event?: 'created' | 'changed';
46
48
  thread?: 'best_match' | 'space';
47
49
  runtime?: 'notis' | 'cloud_computer';
48
50
  skill?: string;
49
51
  wake?: 'all' | 'sent';
52
+ /**
53
+ * @deprecated Comments live in the Space's comment store, not in a database: comment agents (`on: 'comments'`) read
54
+ * no columns. Kept for database agents of older Spaces.
55
+ */
50
56
  columns?: { thread?: string; scope?: string; answer?: string; author?: string };
51
57
  }
52
58
  /** The thread an item (a record, or the Space itself) continues, from the Space's thread rule. */
@@ -59,17 +65,14 @@ export interface SpaceItemThread {
59
65
  }
60
66
  /** One Space agent's latest wake-up for the viewer (`useAgentQueue`). */
61
67
  export interface SpaceAgentQueue {
62
- status: 'idle' | 'queued' | 'working' | 'waiting' | 'failed' | 'done';
68
+ status: 'idle' | 'queued' | 'working' | 'failed' | 'done';
63
69
  thread_id: string | null;
64
- /** Items waiting in the quiet window or held for approval. */
70
+ /** Items waiting in the quiet window. */
65
71
  pending: number;
66
- /** True until the viewer allows this exact version's agents to wake their threads. */
67
- approval_required: boolean;
68
72
  updated_at: string | null;
69
73
  }
70
74
  export interface SpaceAgentsStatus {
71
75
  declared: string[];
72
- approved: boolean;
73
76
  queue?: SpaceAgentQueue;
74
77
  }
75
78
  /** Space-only transport of the thread resolver and the agents' queue. */
@@ -78,7 +81,6 @@ export interface SpaceThreadsTransport {
78
81
  /** Open a thread in the host's side chat, optionally with an unsent draft. */
79
82
  open(threadId: string, options?: { draft?: string }): Promise<boolean>;
80
83
  agentStatus(agentId: string, scope?: string): Promise<SpaceAgentsStatus>;
81
- approveAgents(): Promise<{ approved: boolean; released: number }>;
82
84
  }
83
85
 
84
86
  /** Words shown to people: one string, or one per language (`en` required). */
@@ -116,8 +118,13 @@ export type SpaceThreadItemConfirm = string
116
118
  /** A button on the item, run with the person's own connection to the tool's app. */
117
119
  export interface SpaceThreadItemAction {
118
120
  label: SpaceThreadItemText;
119
- /** A connected app tool, such as `GITHUB_MERGE_A_PULL_REQUEST`. */
120
- tool: string;
121
+ /** A connected app tool, such as `GITHUB_MERGE_A_PULL_REQUEST`. Give `tool` or `function`, not both. */
122
+ tool?: string;
123
+ /**
124
+ * One of this Space's `functions`, run for the person who clicked, with `ctx.item` set to the item. Its
125
+ * `arguments` are the function's input.
126
+ */
127
+ function?: string;
121
128
  /** Templated arguments: a whole-string placeholder such as `'{item.number}'` keeps its type. */
122
129
  arguments?: Record<string, unknown>;
123
130
  confirm?: SpaceThreadItemConfirm;
@@ -164,6 +171,12 @@ export interface SpaceThreadItemKind {
164
171
  actions?: Record<string, SpaceThreadItemAction>;
165
172
  /** This view draws the item in the thread's panel; it receives these params plus the item through `useThreadItem`. */
166
173
  page?: { params?: Record<string, string> };
174
+ /**
175
+ * One of this Space's functions, whose `input` is `threadSettleInput`: Notis runs it once per item and Space
176
+ * revision, as the thread's owner, when a read first lands in a `final` state. It may archive the thread
177
+ * (`ctx.threads.archive`). A function that uses the Cloud Computer waits on the item until its owner allows.
178
+ */
179
+ settle?: { function: string };
167
180
  }
168
181
  /** An attached item as Notis last read it. */
169
182
  export interface SpaceThreadItem {
@@ -195,6 +208,18 @@ export interface SpaceThreadItem {
195
208
  refreshed_at: string | null;
196
209
  /** The code of the last failed read, kept until a read succeeds. */
197
210
  error: string | null;
211
+ /**
212
+ * Set while a hook or a settle of the item's Space waits for its owner to allow the Space's use of their Cloud
213
+ * Computer: the item needs them, and the host's Allow opens the approval for this `revision`.
214
+ */
215
+ approval?: { space_id: string; revision: number; level: 'read' | 'shell' | null; reason: string | null;
216
+ since: string | null; functions: string[] } | null;
217
+ /**
218
+ * The settle Notis started for the item: the Space revision, the function, the state it settled in and how it
219
+ * ended (`pending` while it runs, then `ran`, `waiting`, `failed` or `dropped`; `abandoned` after three tries).
220
+ */
221
+ settled?: { revision: number; function: string; state: string | null; at: string;
222
+ status?: 'pending' | 'ran' | 'waiting' | 'failed' | 'dropped' | 'abandoned' } | null;
198
223
  }
199
224
  export interface SpaceThreadItemRun {
200
225
  /** False when the person cancelled the confirmation or the host cannot run actions. */
@@ -229,25 +254,257 @@ export interface SpaceCommentSource {
229
254
  * the toolkit styles), or null when the panel is closed, shows Chat or shows another source.
230
255
  */
231
256
  show(target: HTMLElement | null): void;
257
+ /**
258
+ * Starts a new comment on `anchor` in this source's own new comment box (a text selection's Comment, through
259
+ * `startComment`). True when the source took it; false leaves it to the host's own composer.
260
+ */
261
+ start?(anchor: SpaceCommentAnchor): boolean;
262
+ }
263
+
264
+ /** What a comment points at (SPC-118): words of the text, a point or a box, items, a moment, or the whole page. */
265
+ export type SpaceCommentMode = 'text' | 'point' | 'box' | 'items' | 'time' | 'page';
266
+ /** A comment's state in the store: `archived` is shown as Done; `deleted` keeps the row for its "Comment deleted" line. */
267
+ export type SpaceCommentStatus = 'open' | 'archived' | 'deleted';
268
+ /** What an agent's comment asks of the reader. */
269
+ export type SpaceCommentNeeds = 'none' | 'check' | 'choice' | 'input';
270
+ /** The last change made to a comment, for Copy changes. */
271
+ export type SpaceCommentChange = 'created' | 'replied' | 'answered' | 'resolved' | 'reopened' | 'deleted' | 'edited';
272
+
273
+ /**
274
+ * Where a comment sits, in the store's own words (snake_case, as `portal_comments` takes it). `anchor_keys`: the
275
+ * record keys the comment is on (one for a point, a box or a whole anchor; 1..n for items). `x`, `y`, `w`, `h`: 0 to
276
+ * 1 of the anchor's size (a point has no `w`/`h`). `time_start`/`time_end`: seconds into a recording. Text mode keeps
277
+ * the quoted words (`quote`, at most 1000 characters, white space collapsed) with up to 40 characters before
278
+ * (`prefix`) and after (`suffix`) to find them again, and `field` when the words are in one named field of the page.
279
+ */
280
+ export interface SpaceCommentAnchor {
281
+ mode: SpaceCommentMode;
282
+ anchor_keys?: readonly string[];
283
+ x?: number | null; y?: number | null; w?: number | null; h?: number | null;
284
+ time_start?: number | null; time_end?: number | null;
285
+ field?: string | null; quote?: string | null; prefix?: string | null; suffix?: string | null;
286
+ }
287
+
288
+ /**
289
+ * A file shown with a comment. `url` is signed on each read (it expires: read the comments again for a new one); null
290
+ * when the server could not sign it (the file is not shown until a later read signs it).
291
+ */
292
+ export interface SpaceCommentAttachment { name: string; url: string | null; type?: string | null; size?: number | null; path?: string | null }
293
+
294
+ /**
295
+ * A file uploaded for a comment not sent yet: pass it in `attachments` of an insert or a reply (the store keeps
296
+ * `path`, `name`, `type` and `size`). `url` is null when the server could not sign it.
297
+ */
298
+ export interface SpaceCommentFile { path: string; name: string; type: string; size: number; url: string | null; previewUrl?: string | null }
299
+
300
+ /**
301
+ * One comment as the store returns it (the `portal_comments` wire row). `thread_root_id` is null on a thread's first
302
+ * comment. `page_key` is the page (record) it belongs to; null: the Space home. A deleted comment has an empty `body`
303
+ * and no attachments. `author.you` is true for the signed-in viewer's own comments; `agent` is the stamp of the agent
304
+ * that wrote it (its `thread_id` only for the agent's owner), null for a person's comment.
305
+ */
306
+ export interface SpaceCommentRow {
307
+ id: string;
308
+ space_id: string;
309
+ view: string | null;
310
+ page_key: string | null;
311
+ thread_root_id: string | null;
312
+ mode: SpaceCommentMode;
313
+ anchor_keys: string[];
314
+ x: number | null; y: number | null; w: number | null; h: number | null;
315
+ time_start: number | null; time_end: number | null;
316
+ field: string | null; quote: string | null; prefix: string | null; suffix: string | null;
317
+ body: string;
318
+ status: SpaceCommentStatus;
319
+ needs: SpaceCommentNeeds;
320
+ options: string[];
321
+ /** A choice question's option its asker recommends (one of `options`). Absent or null: none. */
322
+ recommended?: string | null;
323
+ /** A choice question's line under an option, by option. Absent: none. */
324
+ option_details?: Readonly<Record<string, string>>;
325
+ answer: string | null;
326
+ answered_at: string | null;
327
+ answer_to: string | null;
328
+ change: SpaceCommentChange | null;
329
+ attachments: SpaceCommentAttachment[];
330
+ author: { user_id: string; name: string; you: boolean };
331
+ agent: { name: string; id?: string | null; thread_id?: string | null; row_id?: string | null;
332
+ runtime?: Record<string, string | null> | null;
333
+ /** An agent outside Notis: the thread it works in, the harness running it, and that it is outside (SPC-535). */
334
+ thread_name?: string | null; harness?: string | null; outside?: boolean } | null;
335
+ example: boolean;
336
+ revision: number;
337
+ created_at: string;
338
+ changed_at: string;
339
+ edited_at: string | null;
340
+ deleted_at: string | null;
232
341
  }
342
+
233
343
  /**
234
- * Space-only host Comments panel: the comment threads of the page sit in the host's right panel, beside the chat,
235
- * instead of a pane inside the Space. Absent while comments are off for the viewer, on Sites, links, previews and
236
- * older hosts: a Space then shows no comments at all (no pane, no pins, no highlights).
344
+ * Which comments a read covers: one page by its record key, `null` for the Space home (comments on no page), or
345
+ * `'all'` for every comment of the Space.
346
+ */
347
+ export type SpaceCommentPageKey = string | null | 'all';
348
+
349
+ /**
350
+ * Which comment threads of the Space a pane reads (`SpaceCommentsTransport.threads`). The open threads always come,
351
+ * whole. Deleted threads never come.
352
+ */
353
+ export interface SpaceCommentThreadsInput {
354
+ /**
355
+ * How many Done threads the pane wants too, newest first (0 or absent: none). The host reads them a page at a time
356
+ * and answers every one it holds; `moreDone` says whether older ones are left.
357
+ */
358
+ done?: number;
359
+ /**
360
+ * Only these threads (the ids of their first comments), whatever their status: nothing else of the Space is read.
361
+ * For a host that shows a part of a Space's comments (those linked to one conversation).
362
+ */
363
+ only?: readonly string[] | null;
364
+ /** Comments whose threads come too, whatever their status and their place in the list (a link to one comment). */
365
+ include?: readonly string[];
366
+ }
367
+
368
+ /** What a bounded read answers. */
369
+ export interface SpaceCommentThreadsAnswer {
370
+ /** The comments of the threads read, in no particular order: every thread whole. */
371
+ comments: SpaceCommentRow[];
372
+ revision: number;
373
+ /**
374
+ * How many threads the Space holds by status, counted by the server (deleted ones left out), so a pane that holds a
375
+ * part of the Space still knows the totals. Null with `only`, and while the server has not said.
376
+ */
377
+ counts: { open: number; done: number } | null;
378
+ /**
379
+ * The pin number of the first comments that sit on a point or a zone, by comment id, counted by the server among
380
+ * every first comment of their page (deleted ones keep theirs).
381
+ */
382
+ numbers: Readonly<Record<string, number>>;
383
+ /** How many comments Copy changes would report with no checkpoint, counted by the server. Null when not known. */
384
+ changes: number | null;
385
+ /** True while Done threads older than the ones answered are left to read. */
386
+ moreDone: boolean;
387
+ }
388
+
389
+ /** The page the host shows: its record (null on the Space home), the view slug, and its name when known. */
390
+ export interface SpaceCommentPage { recordKey: string | null; view?: string | null; name?: string | null }
391
+
392
+ /** A new thread's first comment. `request_id` makes a retry return the same comment; `id` (a uuid) is optional. */
393
+ export interface SpaceCommentInsert extends SpaceCommentAnchor {
394
+ page_key: string | null;
395
+ view?: string | null;
396
+ body: string;
397
+ needs?: SpaceCommentNeeds;
398
+ options?: readonly string[];
399
+ /** With `needs: 'choice'`: the option recommended, and a line under an option (by option). */
400
+ recommended?: string | null;
401
+ option_details?: Readonly<Record<string, string>>;
402
+ attachments?: readonly SpaceCommentFile[];
403
+ id?: string;
404
+ request_id: string;
405
+ }
406
+
407
+ /**
408
+ * A reply. `answer_to` names the input ask it answers. An archived thread comes back when the reply waits for someone.
409
+ * `needs` and `options` make the reply a question, as on a first comment.
410
+ */
411
+ export interface SpaceCommentReply {
412
+ root_id: string;
413
+ body: string;
414
+ answer_to?: string | null;
415
+ needs?: SpaceCommentNeeds;
416
+ options?: readonly string[];
417
+ recommended?: string | null;
418
+ option_details?: Readonly<Record<string, string>>;
419
+ attachments?: readonly SpaceCommentFile[];
420
+ id?: string;
421
+ request_id: string;
422
+ }
423
+
424
+ /**
425
+ * Space-only host Comments panel and comment store: the comment threads of the page sit in the host's right panel,
426
+ * beside the chat, instead of a pane inside the Space, and every read and write goes through the host to the Space's
427
+ * one comment store (`portal_comments`). Absent on Sites, links, previews and older hosts: a Space then shows no
428
+ * comments at all (no pane, no pins, no highlights, no Comment on a selection; Cite stays).
429
+ *
430
+ * Every write resolves with the stored row (the server stamps author, dates, `change` and `revision`) or rejects with
431
+ * an Error whose `code` is the server's (`comment_forbidden`, `revision_conflict`, `comment_not_found`, ...).
237
432
  */
238
433
  export interface SpaceCommentsTransport {
239
434
  /** Lists a source in the Comments panel until the returned call-back runs. */
240
435
  attach(source: SpaceCommentSource): () => void;
241
436
  /**
242
- * The signed-in viewer: their name (the Author they write as; the server stamps it too) and whether they may edit
437
+ * The signed-in viewer: their name (the author they write as; the server stamps it) and whether they may edit
243
438
  * the Space. Undefined while it is not known yet: comments cannot be sent until it is.
244
439
  */
245
440
  viewer?: SpaceCommentViewer;
246
441
  /**
247
- * The manager threads each comment thread is linked to (1..n, SPC-113), by root record key, for the comment database
248
- * alias. The first one is where a reply goes ("Goes to"). A root missing from the answer has no link yet.
442
+ * The page the host shows (its record key, view and name): `useComments` and the passage highlights read its
443
+ * comments by default. Absent: the Space home.
444
+ */
445
+ page?: SpaceCommentPage | null;
446
+ /**
447
+ * The comments of a page (`page`: its record key, null for the Space home, 'all' for the whole Space), deleted ones
448
+ * included (they keep their "Comment deleted" line), with the store's revision. The host may answer from its own
449
+ * copy of the store. The SDK never passes `since_revision` and reads every answer as the whole page: a host that
450
+ * asks the server for changes only merges them into its copy and answers with the whole page.
451
+ */
452
+ list(input: { page: SpaceCommentPageKey; since_revision?: number }): Promise<{ comments: SpaceCommentRow[]; revision: number }>;
453
+ /**
454
+ * A bounded read of the Space's comment threads, for a pane that shows the whole Space: only the threads it lists,
455
+ * each whole (its first comment and its replies), instead of every comment of the Space (`list` with 'all'). See
456
+ * `SpaceCommentThreadsInput`. The host keeps its own copy and asks the server only for what the copy lacks and for
457
+ * what changed since. Resolves null when the server cannot answer this read: the reader then uses `list`. Absent
458
+ * on older hosts: `list` is used. `subscribe` with 'all' says when to read again.
459
+ */
460
+ threads?(input: SpaceCommentThreadsInput): Promise<SpaceCommentThreadsAnswer | null>;
461
+ /**
462
+ * Calls `listener` whenever the comments of `page` may have changed (a write here or elsewhere, the window coming
463
+ * back into focus, the host's poll): the reader lists them again. Returns the call-back that stops it.
249
464
  */
250
- links?(input: { database: string; rootKeys: readonly string[] }): Promise<Record<string, SpaceCommentThreadRef[]>>;
465
+ subscribe(input: { page: SpaceCommentPageKey }, listener: () => void): () => void;
466
+ /** Starts a thread. */
467
+ insert(input: SpaceCommentInsert): Promise<SpaceCommentRow>;
468
+ /** Replies in a thread. */
469
+ reply(input: SpaceCommentReply): Promise<SpaceCommentRow>;
470
+ /** Saves new text for the viewer's own comment (the server marks it edited). */
471
+ edit(input: { id: string; body: string }): Promise<SpaceCommentRow>;
472
+ /** Archives a thread (Done): people only, on its first comment. */
473
+ archive(input: { root_id: string }): Promise<SpaceCommentRow>;
474
+ /** Brings an archived thread back to open. */
475
+ unarchive(input: { root_id: string }): Promise<SpaceCommentRow>;
476
+ /** Deletes one comment (status deleted, kept for its line and the Bin). A first comment deletes its whole thread. */
477
+ remove(input: { id: string }): Promise<SpaceCommentRow>;
478
+ /** Brings a deleted comment back (Undo, the Bin). */
479
+ restore(input: { id: string }): Promise<SpaceCommentRow>;
480
+ /** Answers a check, choice or input ask. */
481
+ answer(input: { id: string; answer: string }): Promise<SpaceCommentRow>;
482
+ /**
483
+ * Uploads one picture or file for a comment not sent yet (signed-in people only; never on a Site, a link or a
484
+ * preview). Throws a `SpaceFileError` with a code the pane words. Absent: comments take text only.
485
+ */
486
+ upload?(input: { file: Blob; name?: string; requestId?: string; onProgress?(sent: number, total: number): void;
487
+ signal?: AbortSignal }): Promise<SpaceCommentFile>;
488
+ /** The largest file `upload` takes, in bytes. Default `SPACE_FILE_MAX_BYTES`. */
489
+ maxFileBytes?: number;
490
+ /**
491
+ * Opens the host's new comment on `anchor` (Comment on a text selection): the Comments panel opens with the
492
+ * comment's place shown in its box. The host first offers it to the source it shows (`SpaceCommentSource.start`).
493
+ * `page_key` and `view` default to the page the host shows.
494
+ */
495
+ startComment?(anchor: SpaceCommentAnchor & { page_key?: string | null; view?: string | null }): void;
496
+ /** Opens the Comments panel on one thread (a highlight clicked on the page), by any comment id of it. */
497
+ revealComment?(id: string): void;
498
+ /**
499
+ * The text comments of the page whose words the highlights could not find any more ("Passage changed": the
500
+ * thread stays open with its old quote). Called again whenever that set changes.
501
+ */
502
+ passagesChanged?(input: { page: string | null; ids: readonly string[] }): void;
503
+ /**
504
+ * The manager threads each comment thread is linked to (1..n, SPC-113), by root comment id. The first one is where
505
+ * a reply goes ("Goes to"). A root missing from the answer has no link yet.
506
+ */
507
+ links?(input: { rootIds: readonly string[] }): Promise<Record<string, SpaceCommentThreadRef[]>>;
251
508
  /** The best-match thread for a new comment on this page (THR-024), the one the chat suggests; null starts a new one. */
252
509
  bestMatch?(input: { recordKey?: string | null }): Promise<SpaceCommentThreadRef | null>;
253
510
  /**
@@ -259,17 +516,22 @@ export interface SpaceCommentsTransport {
259
516
  * Links a comment thread to a manager thread: after its first comment is saved (the To chip's thread), on Change, or
260
517
  * when a reply @-mentions another thread (`primary: false` adds it). Resolves with the thread replies now go to.
261
518
  */
262
- link?(input: { database: string; rootKey: string; pick: SpaceCommentThreadPick; primary?: boolean }): Promise<SpaceCommentThreadRef | null>;
519
+ link?(input: { rootId: string; pick: SpaceCommentThreadPick; primary?: boolean }): Promise<SpaceCommentThreadRef | null>;
263
520
  /** Opens a manager thread in the chat (the panel switches to Chat). */
264
521
  openThread?(threadId: string): void;
265
522
  /**
266
- * The link that opens this Space page with one comment thread revealed (`comment=<root key>`, the link a push or a
267
- * chat pill opens), as a full address another person can open: Copy link on a thread card copies it. Null when the
268
- * page has no shareable address. Without it the pane copies the page's own address with that param. `database` is
269
- * the comments database (its alias): the host may answer later (a promise) with the thread's own page in the link,
270
- * wherever the pane is (the Space home, another page).
523
+ * Opens the page of one comment thread with that thread shown on it, for a host that draws the comments where their
524
+ * page is not open (every Space's open comments, a conversation's comments): each card's "..." then offers Show on
525
+ * page. Absent beside the page itself, where a tap on the card already shows its place.
526
+ */
527
+ showOnPage?(input: { rootId: string }): void;
528
+ /**
529
+ * The link that opens the Space page of one comment thread with it revealed (`comment=<root id>`, the link a push
530
+ * or a chat pill opens), as a full address another person can open: Copy link on a thread card copies it. The host
531
+ * may answer later (a promise). Null when there is no shareable address; without it the pane copies the page's own
532
+ * address with that param.
271
533
  */
272
- commentLink?(input: { rootKey: string; database?: string }): string | null | Promise<string | null>;
534
+ commentLink?(input: { rootId: string }): string | null | Promise<string | null>;
273
535
  /**
274
536
  * Shows the page under the Comments panel (SPC-132): called when a point, box, items or time mode starts on a narrow
275
537
  * screen (under 768px wide), where the full-screen panel covers the page. The host closes its full-screen panel; the
@@ -277,16 +539,27 @@ export interface SpaceCommentsTransport {
277
539
  * does not cover the page ignores it.
278
540
  */
279
541
  showPage?(): void;
542
+ /**
543
+ * Names the mounted view this transport serves, the same object for its whole life. When a newer version of the
544
+ * view takes its place, the host hands what the comments show (the selected thread, the filters, a new comment
545
+ * being placed) from the old view's token to the new one's (`handOverCommentState`). Absent: nothing is handed.
546
+ */
547
+ viewToken?: object;
280
548
  }
281
549
  /**
282
550
  * The viewer as comments see them. `id` (their user id), when the host gives it, tells their comments by the row's
283
- * creator (`created_by`) instead of the Author name, so a renamed person keeps Edit and Delete on their comments.
551
+ * author (`author.user_id`) when a row does not say `author.you`, so a renamed person keeps Edit and Delete. The host
552
+ * maps the server's `viewer` answer (`{ user_id, name, can_edit_space }`) to this shape.
284
553
  */
285
554
  export interface SpaceCommentViewer { name: string; canEditSpace: boolean; id?: string | null }
286
555
  /**
287
556
  * A manager thread a comment thread is linked to. `subagent` names the subagent a reply goes back to, when one wrote it.
288
557
  * `threadId: null` with `status: 'pending'` is a "New <harness> thread" pick not started yet: the first wake
289
- * starts it.
558
+ * starts it. `threadId: null` with a `via` and `status: 'elsewhere'`: a plain reply wakes an agent another person
559
+ * runs, so no thread of the viewer's is named. `threadId: null` with `via: 'claimed'` and `outside: true`: an agent
560
+ * outside Notis holds the comment thread (SPC-535), so a reply stays with it and wakes nobody; `title` and
561
+ * `agentName` name it, `harness` picks its logo, `threadName` is the thread it said it works in and `readAt` when it
562
+ * last read the thread (SPC-536; null: not yet).
290
563
  */
291
564
  export interface SpaceCommentThreadRef {
292
565
  threadId: string | null;
@@ -294,6 +567,16 @@ export interface SpaceCommentThreadRef {
294
567
  harness?: string | null;
295
568
  status?: string | null;
296
569
  subagent?: string | null;
570
+ /**
571
+ * Not a link: the thread a plain reply wakes ahead of the links. `started`: the agent that wrote the first comment
572
+ * (its thread wins over every link while available); `replied`: with no link, the agent that replied last.
573
+ */
574
+ via?: 'started' | 'replied' | 'claimed';
575
+ outside?: boolean;
576
+ agentId?: string | null;
577
+ agentName?: string | null;
578
+ threadName?: string | null;
579
+ readAt?: string | null;
297
580
  }
298
581
  export type SpaceCommentThreadPick = SpaceCommentThreadRef | { newThread: string };
299
582
  /**
@@ -322,13 +605,51 @@ export type SpaceCloudComputerJobOperation = 'job.status' | 'job.logs' | 'job.ca
322
605
  export type SpaceCloudComputerTransferOperation = 'transfer.begin' | 'transfer.status' | 'transfer.commit' | 'transfer.abort';
323
606
  export type SpaceCloudComputerOperation = 'facts' | 'run' | 'upload' | SpaceCloudComputerJobOperation | 'service.lease'
324
607
  | 'service.access' | 'folder' | SpaceCloudComputerTransferOperation | 'import';
608
+ /**
609
+ * The signed-in viewer's own account in one connected app (`useConnection`). `available` is false where the host
610
+ * cannot answer (Sites, shared links, verification, previews offline, older hosts). `status` is the newest account's
611
+ * state (`ACTIVE`, `EXPIRED`, `FAILED`...), null when there is none. `account` is the GitHub login for GitHub, else
612
+ * the name the person gave the account, else null. Never a credential.
613
+ */
614
+ export interface SpaceConnection {
615
+ toolkit: string;
616
+ available: boolean;
617
+ connected: boolean;
618
+ account: string | null;
619
+ status: string | null;
620
+ }
621
+ /**
622
+ * The host's connected-app transport for a Space view: read the viewer's own account, and open the Portal's
623
+ * connect flow. `connect` must be called from the person's own click (the host refuses otherwise) and resolves
624
+ * once the account works, the person closed the window, or it timed out.
625
+ */
626
+ export interface SpaceConnectionsTransport {
627
+ read(toolkit: string): Promise<SpaceConnection>;
628
+ connect(toolkit: string): Promise<SpaceConnection>;
629
+ }
630
+ /** A toolkit slug such as `github`. */
631
+ export const SPACE_TOOLKIT_SLUG = /^[a-z0-9][a-z0-9_-]{0,63}$/;
325
632
  export interface SpaceCloudComputerStatus {
326
633
  level: SpaceCloudComputerLevel;
327
634
  approved: boolean;
328
- /** Why it is not approved: never allowed yet, or the Space changed since you allowed it. */
329
- reason: 'approval_required' | 'source_changed' | null;
635
+ /**
636
+ * Why it is not approved: never allowed yet, the Space changed since you allowed it, or a Store update
637
+ * asks for more than its installed copy was allowed.
638
+ */
639
+ reason: 'approval_required' | 'source_changed' | 'access_raised' | null;
330
640
  /** While not approved: the code asking, as the host prompt shows it. It informs the person and decides nothing. */
331
641
  release?: SpaceCloudComputerRelease;
642
+ /** While not approved, for code the Store installed for you: the installed copy one Allow covers. */
643
+ copy?: SpaceCloudComputerCopy;
644
+ }
645
+ /** An installed Store copy: one Allow covers its root and every Space installed with it, and the updates you apply. */
646
+ export interface SpaceCloudComputerCopy {
647
+ /** The copy's root Space, by its name in your account; null when it has none. */
648
+ name: string | null;
649
+ /** The highest level its Spaces ask for. */
650
+ level: SpaceCloudComputerLevel | null;
651
+ /** The names of its Spaces that ask for the Cloud Computer. */
652
+ spaces: string[];
332
653
  }
333
654
  /** Who released the code asking into this Space, and whether it is an unreleased preview. */
334
655
  export interface SpaceCloudComputerRelease {
@@ -748,9 +1069,10 @@ export interface SpaceDefinition {
748
1069
  */
749
1070
  cloudComputer?: SpaceCloudComputerLevel | SpaceCloudComputerDeclaration;
750
1071
  /**
751
- * Agents this Space's database changes wake. A person's new comment, reply or answer wakes their own
752
- * thread for the item (or, for a reply to an agent's comment, that agent's thread) after a quiet
753
- * moment, once that person allowed this Space's agents. Agents' own writes never wake anything.
1072
+ * Agents this Space wakes: `on: 'comments'` for its comments, `on: { database }` for a database's changes. A
1073
+ * person's new comment, reply, answer or edit wakes their own thread for the item (or, for a reply to an agent's
1074
+ * comment, that agent's thread) after a quiet moment, with no approval first. Agents' own writes never wake
1075
+ * anything.
754
1076
  */
755
1077
  agents?: SpaceAgentDeclaration[];
756
1078
  /**
@@ -758,17 +1080,52 @@ export interface SpaceDefinition {
758
1080
  * with their state and actions. Declared on the view whose `actions` hold each kind's read action.
759
1081
  */
760
1082
  threadItems?: Record<string, SpaceThreadItemKind>;
1083
+ /**
1084
+ * Server code this Space declares once and Notis calls from its views, its API and MCP server, Notis agents,
1085
+ * thread items, thread hooks and comment options (see `SpaceFunctionDeclaration`).
1086
+ */
1087
+ functions?: Record<string, import('./functions').SpaceFunctionDeclaration>;
1088
+ /**
1089
+ * The function that runs after a built-in thread action (archive, read, star, Later, delete and their opposites)
1090
+ * on a thread one of this Space's items is attached to. The action itself never waits for it. Its `input` is
1091
+ * `threadHookInput`, or `threadIdleInput` for the idle hook.
1092
+ */
1093
+ threadHooks?: Partial<Record<import('./functions').SpaceThreadHookEvent, string>>;
1094
+ /**
1095
+ * Options that run a function when a person answers a choice comment in this Space with them. Its `input` is
1096
+ * `commentOptionInput`.
1097
+ */
1098
+ commentOptions?: Record<string, import('./functions').SpaceCommentOption>;
761
1099
  /**
762
1100
  * Lists the database's records as sidebar rows under this Space. Only for a short list people navigate
763
1101
  * like pages (folders, chapters); a database that keeps growing belongs in the view's `shows` instead.
764
1102
  */
765
1103
  collection?: { database: string; titleProperty: string; parentProperty?: string; allowCreate?: boolean };
1104
+ /**
1105
+ * What ships to the Store when this Space is published as a root (truths SPC-150 to SPC-152). Declared on the root's
1106
+ * own definition; publishing is refused until it is.
1107
+ */
1108
+ store?: SpaceStore;
766
1109
  /** Reproducible source dependencies not discovered by the module graph. */
767
1110
  sourceIncludes?: string[];
768
1111
  /** Explicit synthetic action cases for offline render verification. */
769
1112
  verificationFixtures?: string;
770
1113
  }
771
1114
 
1115
+ /**
1116
+ * The Store allowlist: `ships` maps the source key of this Space and of each sub-Space that goes to the Store to the
1117
+ * aliases of its linked items (databases, Skills, automations, pages) that go with it. Anything unlisted stays private,
1118
+ * a sub-Space or link added later included. A listed sub-Space needs its parent listed too, and a shipped view must
1119
+ * list every database it reads or writes. Spaces inside records travel with their record.
1120
+ *
1121
+ * ```ts
1122
+ * store: { ships: { coding: ['repositories'], workspaces: ['workspaces', 'new-workspace'] } }
1123
+ * ```
1124
+ */
1125
+ export interface SpaceStore {
1126
+ ships: Record<string, string[]>;
1127
+ }
1128
+
772
1129
  export interface SpacesWorkspace {
773
1130
  /** One project, independently built/released definitions. */
774
1131
  spaces: Record<string, { definition: string; parent?: string; defaultChild?: string }>;
@@ -838,6 +1195,8 @@ export interface SpaceRuntimeDescriptor {
838
1195
  shows?: Record<string, SpaceShownDescriptor>;
839
1196
  chrome?: SpaceChrome;
840
1197
  actions: Record<string, SpaceActionDescriptor>;
1198
+ /** The functions this viewer may call from the page (`expose: ['page']` and their role in `access`). */
1199
+ functions?: Record<string, import('./functions').SpaceFunctionDescriptor>;
841
1200
  bindings: Record<string, {
842
1201
  kind: SpaceResourceReference['kind'];
843
1202
  operations?: Partial<Record<'query' | 'insert' | 'update' | 'delete', string>>;
@@ -981,7 +1340,9 @@ export function publicSpaceDescriptor(space: SpaceRuntimeDescriptor): SpaceRunti
981
1340
  ? { ...binding, operations: Object.fromEntries(Object.entries(binding.operations).filter(([, id]) => Boolean(id && Object.hasOwn(actions, id)))) }
982
1341
  : binding]));
983
1342
  const { editorsOnly: _marks, viewerReads: _reads, cloudComputer: _computer, ...rest } = space;
1343
+ const functions = Object.fromEntries(Object.entries(space.functions ?? {}).filter(([, declared]) => declared.public));
984
1344
  return { ...rest, audience: 'public', actions, bindings,
1345
+ ...(space.functions ? { functions } : {}),
985
1346
  ...(space.shows ? { shows: without(space.shows, marks.shows) } : {}),
986
1347
  ...(space.params ? { params: without(space.params, marks.params) } : {}) };
987
1348
  }
@@ -1126,6 +1487,7 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
1126
1487
  };
1127
1488
  const deny = async (): Promise<never> => { throw protocolError('Use a declared Space action; account-wide tool and backend calls are unavailable.'); };
1128
1489
  const callAction = runtime.callAction;
1490
+ const callFunction = runtime.callFunction;
1129
1491
  if (!callAction) throw new Error('This host needs the current Space action protocol.');
1130
1492
  const asPublic = runtime.space!.viewAs === 'public';
1131
1493
  const space = asPublic ? publicSpaceDescriptor(runtime.space!) : runtime.space!;
@@ -1252,7 +1614,8 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
1252
1614
  return floorResult(await shown<TResult>(name, visible, options), floor, learnOf(list.database));
1253
1615
  } : undefined,
1254
1616
  handover: undefined,
1255
- ...(asPublic ? { spaceFiles: undefined } : {}),
1617
+ // View as the public never reads the editor's own connected apps.
1618
+ ...(asPublic ? { spaceFiles: undefined, spaceConnections: undefined } : {}),
1256
1619
  // The legacy facts hook keeps working in a Space that declares the cloud computer.
1257
1620
  cloudComputerFacts: cloudComputer && cloudLevel ? async (options?: { refresh?: boolean }) => guardedCloud('facts').facts(options) : undefined,
1258
1621
  spaceCloudComputer: cloudComputer && cloudLevel ? Object.freeze({
@@ -1295,6 +1658,11 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
1295
1658
  if (!space.viewerReads?.includes(family)) throw protocolError(`This Space does not declare viewer reads of ${family}.`, 'readUnavailable');
1296
1659
  return viewerRead<TResult>(operation, input);
1297
1660
  } : undefined,
1661
+ callFunction: callFunction ? async function guardedFunction<TResult>(name: string, input: Record<string, unknown> = {},
1662
+ options: import('./functions').SpaceFunctionCallOptions = {}): Promise<TResult> {
1663
+ if (!space.functions || !Object.hasOwn(space.functions, name)) throw protocolError('This view cannot call that function.', 'actionUnavailable');
1664
+ return callFunction<TResult>(name, input, options);
1665
+ } : undefined,
1298
1666
  async callAction<TResult>(id: string, inputs: Record<string, unknown> = {}, options: SpaceActionOptions = {}): Promise<TResult> {
1299
1667
  const descriptor = Object.hasOwn(space.actions, id) ? space.actions[id] : null;
1300
1668
  if (!descriptor) throw undeclared(options.readOnly || options.dedupe ? 'actionUnavailable' : undefined);