@notis_ai/cli 0.2.31 → 0.2.33

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 (92) hide show
  1. package/README.md +88 -9
  2. package/config/notis_app_design_rules.json +22 -0
  3. package/dist/agent-hooks/notis-agent-hook.mjs +4677 -913
  4. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  5. package/dist/base-skills/notis-cli/SKILL.md +7 -3
  6. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  7. package/dist/base-skills/notis-spaces/SKILL.md +9 -4
  8. package/dist/base-skills/notis-spaces/references/comments.md +94 -0
  9. package/dist/base-skills/notis-spaces/references/context.md +20 -19
  10. package/dist/base-skills/notis-spaces/references/design.md +3 -2
  11. package/dist/base-skills/notis-spaces/references/fixtures.md +4 -2
  12. package/dist/base-skills/notis-spaces/references/reading.md +3 -1
  13. package/dist/base-skills/notis-spaces/references/release.md +3 -1
  14. package/dist/base-skills/notis-spaces/references/sdk.md +160 -88
  15. package/dist/base-skills/notis-spaces/references/store.md +24 -1
  16. package/dist/sdk/src/components/SelectionActionBar.tsx +42 -7
  17. package/dist/sdk/src/components/SpaceTextComments.tsx +284 -0
  18. package/dist/sdk/src/config.ts +3 -1
  19. package/dist/sdk/src/functions.ts +203 -0
  20. package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
  21. package/dist/sdk/src/hooks/useCollectionInteractions.ts +7 -2
  22. package/dist/sdk/src/hooks/useConnection.ts +102 -0
  23. package/dist/sdk/src/hooks/useFunction.ts +42 -0
  24. package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
  25. package/dist/sdk/src/index.ts +15 -4
  26. package/dist/sdk/src/runtime.ts +16 -1
  27. package/dist/sdk/src/space.ts +333 -33
  28. package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
  29. package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
  30. package/dist/sdk/src/ui/icons.tsx +17 -1
  31. package/dist/skill-sync/index.js +239 -30
  32. package/dist/skill-sync-worker.mjs +453 -124
  33. package/dist/space-harness/host.js +218 -93
  34. package/dist/space-sdk/dist/chunk-4GWS2IFO.js +3 -0
  35. package/dist/space-sdk/dist/index.js +3 -3
  36. package/dist/space-sdk/dist/ui.js +9 -8
  37. package/dist/space-sdk/src/config.ts +3 -1
  38. package/dist/space-sdk/src/functions.ts +203 -0
  39. package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
  40. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +2 -0
  41. package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
  42. package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
  43. package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
  44. package/dist/space-sdk/src/index.d.ts +10 -4
  45. package/dist/space-sdk/src/runtime.d.ts +14 -1
  46. package/dist/space-sdk/src/space.ts +333 -33
  47. package/dist/space-sdk/src/tailwind-candidates.d.ts +227 -152
  48. package/dist/space-sdk/src/ui/blocks/blocks.d.ts +18 -0
  49. package/dist/space-sdk/src/ui/blocks/index.d.ts +2 -2
  50. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +7 -4
  51. package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +10 -2
  52. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +55 -88
  53. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +9 -0
  54. package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
  55. package/dist/space-sdk/src/ui/comments/index.d.ts +1 -1
  56. package/dist/space-sdk/src/ui/comments/paneParts.d.ts +27 -5
  57. package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
  58. package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
  59. package/dist/space-sdk/src/ui/comments/useComments.d.ts +64 -74
  60. package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
  61. package/dist/space-sdk/src/ui/icons.d.ts +6 -0
  62. package/dist/space-sdk/src/ui/index.d.ts +2 -2
  63. package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
  64. package/dist/space-sdk/src/ui/list/ListReader.d.ts +8 -0
  65. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
  66. package/dist/view-renderer/dist/host.js +285 -160
  67. package/package.json +3 -3
  68. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
  69. package/skills/notis-spaces/cli.md +17 -3
  70. package/src/cli.js +2 -1
  71. package/src/command-specs/index.js +3 -0
  72. package/src/command-specs/repository-secrets.js +171 -0
  73. package/src/command-specs/spaces.js +70 -3
  74. package/src/runtime/agent-credential.js +175 -0
  75. package/src/runtime/agent-identity.js +92 -15
  76. package/src/runtime/app-boundary-validator.js +248 -3
  77. package/src/runtime/app-data-literals.js +32 -23
  78. package/src/runtime/app-platform.js +8 -0
  79. package/src/runtime/auth-recovery.js +14 -0
  80. package/src/runtime/profiles.js +15 -0
  81. package/src/runtime/skill-sync/index.ts +3 -2
  82. package/src/runtime/skill-sync/symlink-manager.ts +354 -35
  83. package/src/runtime/skill-sync/types.ts +10 -1
  84. package/src/runtime/space-functions.js +211 -0
  85. package/src/runtime/space-platform.js +12 -3
  86. package/src/runtime/space-source.js +116 -13
  87. package/src/runtime/space-test-server.js +44 -7
  88. package/src/runtime/space-verification.js +3 -1
  89. package/src/runtime/transport.js +15 -0
  90. package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
  91. package/dist/space-sdk/dist/chunk-3DFOGU26.js +0 -3
  92. 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,201 @@ 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
+ answer: string | null;
322
+ answered_at: string | null;
323
+ answer_to: string | null;
324
+ change: SpaceCommentChange | null;
325
+ attachments: SpaceCommentAttachment[];
326
+ author: { user_id: string; name: string; you: boolean };
327
+ agent: { name: string; id?: string | null; thread_id?: string | null; row_id?: string | null;
328
+ runtime?: Record<string, string | null> | null;
329
+ /** An agent outside Notis: the thread it works in, the harness running it, and that it is outside (SPC-535). */
330
+ thread_name?: string | null; harness?: string | null; outside?: boolean } | null;
331
+ example: boolean;
332
+ revision: number;
333
+ created_at: string;
334
+ changed_at: string;
335
+ edited_at: string | null;
336
+ deleted_at: string | null;
337
+ }
338
+
339
+ /**
340
+ * Which comments a read covers: one page by its record key, `null` for the Space home (comments on no page), or
341
+ * `'all'` for every comment of the Space.
342
+ */
343
+ export type SpaceCommentPageKey = string | null | 'all';
344
+
345
+ /** The page the host shows: its record (null on the Space home), the view slug, and its name when known. */
346
+ export interface SpaceCommentPage { recordKey: string | null; view?: string | null; name?: string | null }
347
+
348
+ /** A new thread's first comment. `request_id` makes a retry return the same comment; `id` (a uuid) is optional. */
349
+ export interface SpaceCommentInsert extends SpaceCommentAnchor {
350
+ page_key: string | null;
351
+ view?: string | null;
352
+ body: string;
353
+ needs?: SpaceCommentNeeds;
354
+ options?: readonly string[];
355
+ attachments?: readonly SpaceCommentFile[];
356
+ id?: string;
357
+ request_id: string;
358
+ }
359
+
360
+ /**
361
+ * A reply. `answer_to` names the input ask it answers. An archived thread comes back when the reply waits for someone.
362
+ * `needs` and `options` make the reply a question, as on a first comment.
363
+ */
364
+ export interface SpaceCommentReply {
365
+ root_id: string;
366
+ body: string;
367
+ answer_to?: string | null;
368
+ needs?: SpaceCommentNeeds;
369
+ options?: readonly string[];
370
+ attachments?: readonly SpaceCommentFile[];
371
+ id?: string;
372
+ request_id: string;
232
373
  }
374
+
233
375
  /**
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).
376
+ * Space-only host Comments panel and comment store: the comment threads of the page sit in the host's right panel,
377
+ * beside the chat, instead of a pane inside the Space, and every read and write goes through the host to the Space's
378
+ * one comment store (`portal_comments`). Absent while comments are off for the viewer (`unified_comments`), on Sites,
379
+ * links, previews and older hosts: a Space then shows no comments at all (no pane, no pins, no highlights, no Comment
380
+ * on a selection; Cite stays).
381
+ *
382
+ * Every write resolves with the stored row (the server stamps author, dates, `change` and `revision`) or rejects with
383
+ * an Error whose `code` is the server's (`feature_disabled`, `revision_conflict`, `comment_not_found`, ...).
237
384
  */
238
385
  export interface SpaceCommentsTransport {
239
386
  /** Lists a source in the Comments panel until the returned call-back runs. */
240
387
  attach(source: SpaceCommentSource): () => void;
241
388
  /**
242
- * The signed-in viewer: their name (the Author they write as; the server stamps it too) and whether they may edit
389
+ * The signed-in viewer: their name (the author they write as; the server stamps it) and whether they may edit
243
390
  * the Space. Undefined while it is not known yet: comments cannot be sent until it is.
244
391
  */
245
392
  viewer?: SpaceCommentViewer;
246
393
  /**
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.
394
+ * The page the host shows (its record key, view and name): `useComments` and the passage highlights read its
395
+ * comments by default. Absent: the Space home.
396
+ */
397
+ page?: SpaceCommentPage | null;
398
+ /**
399
+ * The comments of a page (`page`: its record key, null for the Space home, 'all' for the whole Space), deleted ones
400
+ * included (they keep their "Comment deleted" line), with the store's revision. The host may answer from its own
401
+ * copy of the store. The SDK never passes `since_revision` and reads every answer as the whole page: a host that
402
+ * asks the server for changes only merges them into its copy and answers with the whole page.
403
+ */
404
+ list(input: { page: SpaceCommentPageKey; since_revision?: number }): Promise<{ comments: SpaceCommentRow[]; revision: number }>;
405
+ /**
406
+ * Calls `listener` whenever the comments of `page` may have changed (a write here or elsewhere, the window coming
407
+ * back into focus, the host's poll): the reader lists them again. Returns the call-back that stops it.
408
+ */
409
+ subscribe(input: { page: SpaceCommentPageKey }, listener: () => void): () => void;
410
+ /** Starts a thread. */
411
+ insert(input: SpaceCommentInsert): Promise<SpaceCommentRow>;
412
+ /** Replies in a thread. */
413
+ reply(input: SpaceCommentReply): Promise<SpaceCommentRow>;
414
+ /** Saves new text for the viewer's own comment (the server marks it edited). */
415
+ edit(input: { id: string; body: string }): Promise<SpaceCommentRow>;
416
+ /** Archives a thread (Done): people only, on its first comment. */
417
+ archive(input: { root_id: string }): Promise<SpaceCommentRow>;
418
+ /** Brings an archived thread back to open. */
419
+ unarchive(input: { root_id: string }): Promise<SpaceCommentRow>;
420
+ /** Deletes one comment (status deleted, kept for its line and the Bin). A first comment deletes its whole thread. */
421
+ remove(input: { id: string }): Promise<SpaceCommentRow>;
422
+ /** Brings a deleted comment back (Undo, the Bin). */
423
+ restore(input: { id: string }): Promise<SpaceCommentRow>;
424
+ /** Answers a check, choice or input ask. */
425
+ answer(input: { id: string; answer: string }): Promise<SpaceCommentRow>;
426
+ /**
427
+ * Uploads one picture or file for a comment not sent yet (signed-in people only; never on a Site, a link or a
428
+ * preview). Throws a `SpaceFileError` with a code the pane words. Absent: comments take text only.
429
+ */
430
+ upload?(input: { file: Blob; name?: string; requestId?: string; onProgress?(sent: number, total: number): void;
431
+ signal?: AbortSignal }): Promise<SpaceCommentFile>;
432
+ /** The largest file `upload` takes, in bytes. Default `SPACE_FILE_MAX_BYTES`. */
433
+ maxFileBytes?: number;
434
+ /**
435
+ * Opens the host's new comment on `anchor` (Comment on a text selection): the Comments panel opens with the
436
+ * comment's place shown in its box. The host first offers it to the source it shows (`SpaceCommentSource.start`).
437
+ * `page_key` and `view` default to the page the host shows.
249
438
  */
250
- links?(input: { database: string; rootKeys: readonly string[] }): Promise<Record<string, SpaceCommentThreadRef[]>>;
439
+ startComment?(anchor: SpaceCommentAnchor & { page_key?: string | null; view?: string | null }): void;
440
+ /** Opens the Comments panel on one thread (a highlight clicked on the page), by any comment id of it. */
441
+ revealComment?(id: string): void;
442
+ /**
443
+ * The text comments of the page whose words the highlights could not find any more ("Passage changed": the
444
+ * thread stays open with its old quote). Called again whenever that set changes.
445
+ */
446
+ passagesChanged?(input: { page: string | null; ids: readonly string[] }): void;
447
+ /**
448
+ * The manager threads each comment thread is linked to (1..n, SPC-113), by root comment id. The first one is where
449
+ * a reply goes ("Goes to"). A root missing from the answer has no link yet.
450
+ */
451
+ links?(input: { rootIds: readonly string[] }): Promise<Record<string, SpaceCommentThreadRef[]>>;
251
452
  /** The best-match thread for a new comment on this page (THR-024), the one the chat suggests; null starts a new one. */
252
453
  bestMatch?(input: { recordKey?: string | null }): Promise<SpaceCommentThreadRef | null>;
253
454
  /**
@@ -259,17 +460,16 @@ export interface SpaceCommentsTransport {
259
460
  * Links a comment thread to a manager thread: after its first comment is saved (the To chip's thread), on Change, or
260
461
  * when a reply @-mentions another thread (`primary: false` adds it). Resolves with the thread replies now go to.
261
462
  */
262
- link?(input: { database: string; rootKey: string; pick: SpaceCommentThreadPick; primary?: boolean }): Promise<SpaceCommentThreadRef | null>;
463
+ link?(input: { rootId: string; pick: SpaceCommentThreadPick; primary?: boolean }): Promise<SpaceCommentThreadRef | null>;
263
464
  /** Opens a manager thread in the chat (the panel switches to Chat). */
264
465
  openThread?(threadId: string): void;
265
466
  /**
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).
467
+ * The link that opens the Space page of one comment thread with it revealed (`comment=<root id>`, the link a push
468
+ * or a chat pill opens), as a full address another person can open: Copy link on a thread card copies it. The host
469
+ * may answer later (a promise). Null when there is no shareable address; without it the pane copies the page's own
470
+ * address with that param.
271
471
  */
272
- commentLink?(input: { rootKey: string; database?: string }): string | null | Promise<string | null>;
472
+ commentLink?(input: { rootId: string }): string | null | Promise<string | null>;
273
473
  /**
274
474
  * Shows the page under the Comments panel (SPC-132): called when a point, box, items or time mode starts on a narrow
275
475
  * screen (under 768px wide), where the full-screen panel covers the page. The host closes its full-screen panel; the
@@ -280,13 +480,18 @@ export interface SpaceCommentsTransport {
280
480
  }
281
481
  /**
282
482
  * 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.
483
+ * author (`author.user_id`) when a row does not say `author.you`, so a renamed person keeps Edit and Delete. The host
484
+ * maps the server's `viewer` answer (`{ user_id, name, can_edit_space }`) to this shape.
284
485
  */
285
486
  export interface SpaceCommentViewer { name: string; canEditSpace: boolean; id?: string | null }
286
487
  /**
287
488
  * A manager thread a comment thread is linked to. `subagent` names the subagent a reply goes back to, when one wrote it.
288
489
  * `threadId: null` with `status: 'pending'` is a "New <harness> thread" pick not started yet: the first wake
289
- * starts it.
490
+ * starts it. `threadId: null` with a `via` and `status: 'elsewhere'`: a plain reply wakes an agent another person
491
+ * runs, so no thread of the viewer's is named. `threadId: null` with `via: 'claimed'` and `outside: true`: an agent
492
+ * outside Notis holds the comment thread (SPC-535), so a reply stays with it and wakes nobody; `title` and
493
+ * `agentName` name it, `harness` picks its logo, `threadName` is the thread it said it works in and `readAt` when it
494
+ * last read the thread (SPC-536; null: not yet).
290
495
  */
291
496
  export interface SpaceCommentThreadRef {
292
497
  threadId: string | null;
@@ -294,6 +499,16 @@ export interface SpaceCommentThreadRef {
294
499
  harness?: string | null;
295
500
  status?: string | null;
296
501
  subagent?: string | null;
502
+ /**
503
+ * Not a link: the thread a plain reply wakes ahead of the links. `started`: the agent that wrote the first comment
504
+ * (its thread wins over every link while available); `replied`: with no link, the agent that replied last.
505
+ */
506
+ via?: 'started' | 'replied' | 'claimed';
507
+ outside?: boolean;
508
+ agentId?: string | null;
509
+ agentName?: string | null;
510
+ threadName?: string | null;
511
+ readAt?: string | null;
297
512
  }
298
513
  export type SpaceCommentThreadPick = SpaceCommentThreadRef | { newThread: string };
299
514
  /**
@@ -322,13 +537,51 @@ export type SpaceCloudComputerJobOperation = 'job.status' | 'job.logs' | 'job.ca
322
537
  export type SpaceCloudComputerTransferOperation = 'transfer.begin' | 'transfer.status' | 'transfer.commit' | 'transfer.abort';
323
538
  export type SpaceCloudComputerOperation = 'facts' | 'run' | 'upload' | SpaceCloudComputerJobOperation | 'service.lease'
324
539
  | 'service.access' | 'folder' | SpaceCloudComputerTransferOperation | 'import';
540
+ /**
541
+ * The signed-in viewer's own account in one connected app (`useConnection`). `available` is false where the host
542
+ * cannot answer (Sites, shared links, verification, previews offline, older hosts). `status` is the newest account's
543
+ * state (`ACTIVE`, `EXPIRED`, `FAILED`...), null when there is none. `account` is the GitHub login for GitHub, else
544
+ * the name the person gave the account, else null. Never a credential.
545
+ */
546
+ export interface SpaceConnection {
547
+ toolkit: string;
548
+ available: boolean;
549
+ connected: boolean;
550
+ account: string | null;
551
+ status: string | null;
552
+ }
553
+ /**
554
+ * The host's connected-app transport for a Space view: read the viewer's own account, and open the Portal's
555
+ * connect flow. `connect` must be called from the person's own click (the host refuses otherwise) and resolves
556
+ * once the account works, the person closed the window, or it timed out.
557
+ */
558
+ export interface SpaceConnectionsTransport {
559
+ read(toolkit: string): Promise<SpaceConnection>;
560
+ connect(toolkit: string): Promise<SpaceConnection>;
561
+ }
562
+ /** A toolkit slug such as `github`. */
563
+ export const SPACE_TOOLKIT_SLUG = /^[a-z0-9][a-z0-9_-]{0,63}$/;
325
564
  export interface SpaceCloudComputerStatus {
326
565
  level: SpaceCloudComputerLevel;
327
566
  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;
567
+ /**
568
+ * Why it is not approved: never allowed yet, the Space changed since you allowed it, or a Store update
569
+ * asks for more than its installed copy was allowed.
570
+ */
571
+ reason: 'approval_required' | 'source_changed' | 'access_raised' | null;
330
572
  /** While not approved: the code asking, as the host prompt shows it. It informs the person and decides nothing. */
331
573
  release?: SpaceCloudComputerRelease;
574
+ /** While not approved, for code the Store installed for you: the installed copy one Allow covers. */
575
+ copy?: SpaceCloudComputerCopy;
576
+ }
577
+ /** An installed Store copy: one Allow covers its root and every Space installed with it, and the updates you apply. */
578
+ export interface SpaceCloudComputerCopy {
579
+ /** The copy's root Space, by its name in your account; null when it has none. */
580
+ name: string | null;
581
+ /** The highest level its Spaces ask for. */
582
+ level: SpaceCloudComputerLevel | null;
583
+ /** The names of its Spaces that ask for the Cloud Computer. */
584
+ spaces: string[];
332
585
  }
333
586
  /** Who released the code asking into this Space, and whether it is an unreleased preview. */
334
587
  export interface SpaceCloudComputerRelease {
@@ -748,9 +1001,10 @@ export interface SpaceDefinition {
748
1001
  */
749
1002
  cloudComputer?: SpaceCloudComputerLevel | SpaceCloudComputerDeclaration;
750
1003
  /**
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.
1004
+ * Agents this Space wakes: `on: 'comments'` for its comments, `on: { database }` for a database's changes. A
1005
+ * person's new comment, reply, answer or edit wakes their own thread for the item (or, for a reply to an agent's
1006
+ * comment, that agent's thread) after a quiet moment, with no approval first. Agents' own writes never wake
1007
+ * anything.
754
1008
  */
755
1009
  agents?: SpaceAgentDeclaration[];
756
1010
  /**
@@ -758,17 +1012,52 @@ export interface SpaceDefinition {
758
1012
  * with their state and actions. Declared on the view whose `actions` hold each kind's read action.
759
1013
  */
760
1014
  threadItems?: Record<string, SpaceThreadItemKind>;
1015
+ /**
1016
+ * Server code this Space declares once and Notis calls from its views, its API and MCP server, Notis agents,
1017
+ * thread items, thread hooks and comment options (see `SpaceFunctionDeclaration`).
1018
+ */
1019
+ functions?: Record<string, import('./functions').SpaceFunctionDeclaration>;
1020
+ /**
1021
+ * The function that runs after a built-in thread action (archive, read, star, Later, delete and their opposites)
1022
+ * on a thread one of this Space's items is attached to. The action itself never waits for it. Its `input` is
1023
+ * `threadHookInput`.
1024
+ */
1025
+ threadHooks?: Partial<Record<import('./functions').SpaceThreadHookEvent, string>>;
1026
+ /**
1027
+ * Options that run a function when a person answers a choice comment in this Space with them. Its `input` is
1028
+ * `commentOptionInput`.
1029
+ */
1030
+ commentOptions?: Record<string, import('./functions').SpaceCommentOption>;
761
1031
  /**
762
1032
  * Lists the database's records as sidebar rows under this Space. Only for a short list people navigate
763
1033
  * like pages (folders, chapters); a database that keeps growing belongs in the view's `shows` instead.
764
1034
  */
765
1035
  collection?: { database: string; titleProperty: string; parentProperty?: string; allowCreate?: boolean };
1036
+ /**
1037
+ * What ships to the Store when this Space is published as a root (truths SPC-150 to SPC-152). Declared on the root's
1038
+ * own definition; publishing is refused until it is.
1039
+ */
1040
+ store?: SpaceStore;
766
1041
  /** Reproducible source dependencies not discovered by the module graph. */
767
1042
  sourceIncludes?: string[];
768
1043
  /** Explicit synthetic action cases for offline render verification. */
769
1044
  verificationFixtures?: string;
770
1045
  }
771
1046
 
1047
+ /**
1048
+ * The Store allowlist: `ships` maps the source key of this Space and of each sub-Space that goes to the Store to the
1049
+ * aliases of its linked items (databases, Skills, automations, pages) that go with it. Anything unlisted stays private,
1050
+ * a sub-Space or link added later included. A listed sub-Space needs its parent listed too, and a shipped view must
1051
+ * list every database it reads or writes. Spaces inside records travel with their record.
1052
+ *
1053
+ * ```ts
1054
+ * store: { ships: { coding: ['repositories'], workspaces: ['workspaces', 'new-workspace'] } }
1055
+ * ```
1056
+ */
1057
+ export interface SpaceStore {
1058
+ ships: Record<string, string[]>;
1059
+ }
1060
+
772
1061
  export interface SpacesWorkspace {
773
1062
  /** One project, independently built/released definitions. */
774
1063
  spaces: Record<string, { definition: string; parent?: string; defaultChild?: string }>;
@@ -838,6 +1127,8 @@ export interface SpaceRuntimeDescriptor {
838
1127
  shows?: Record<string, SpaceShownDescriptor>;
839
1128
  chrome?: SpaceChrome;
840
1129
  actions: Record<string, SpaceActionDescriptor>;
1130
+ /** The functions this viewer may call from the page (`expose: ['page']` and their role in `access`). */
1131
+ functions?: Record<string, import('./functions').SpaceFunctionDescriptor>;
841
1132
  bindings: Record<string, {
842
1133
  kind: SpaceResourceReference['kind'];
843
1134
  operations?: Partial<Record<'query' | 'insert' | 'update' | 'delete', string>>;
@@ -981,7 +1272,9 @@ export function publicSpaceDescriptor(space: SpaceRuntimeDescriptor): SpaceRunti
981
1272
  ? { ...binding, operations: Object.fromEntries(Object.entries(binding.operations).filter(([, id]) => Boolean(id && Object.hasOwn(actions, id)))) }
982
1273
  : binding]));
983
1274
  const { editorsOnly: _marks, viewerReads: _reads, cloudComputer: _computer, ...rest } = space;
1275
+ const functions = Object.fromEntries(Object.entries(space.functions ?? {}).filter(([, declared]) => declared.public));
984
1276
  return { ...rest, audience: 'public', actions, bindings,
1277
+ ...(space.functions ? { functions } : {}),
985
1278
  ...(space.shows ? { shows: without(space.shows, marks.shows) } : {}),
986
1279
  ...(space.params ? { params: without(space.params, marks.params) } : {}) };
987
1280
  }
@@ -1126,6 +1419,7 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
1126
1419
  };
1127
1420
  const deny = async (): Promise<never> => { throw protocolError('Use a declared Space action; account-wide tool and backend calls are unavailable.'); };
1128
1421
  const callAction = runtime.callAction;
1422
+ const callFunction = runtime.callFunction;
1129
1423
  if (!callAction) throw new Error('This host needs the current Space action protocol.');
1130
1424
  const asPublic = runtime.space!.viewAs === 'public';
1131
1425
  const space = asPublic ? publicSpaceDescriptor(runtime.space!) : runtime.space!;
@@ -1252,7 +1546,8 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
1252
1546
  return floorResult(await shown<TResult>(name, visible, options), floor, learnOf(list.database));
1253
1547
  } : undefined,
1254
1548
  handover: undefined,
1255
- ...(asPublic ? { spaceFiles: undefined } : {}),
1549
+ // View as the public never reads the editor's own connected apps.
1550
+ ...(asPublic ? { spaceFiles: undefined, spaceConnections: undefined } : {}),
1256
1551
  // The legacy facts hook keeps working in a Space that declares the cloud computer.
1257
1552
  cloudComputerFacts: cloudComputer && cloudLevel ? async (options?: { refresh?: boolean }) => guardedCloud('facts').facts(options) : undefined,
1258
1553
  spaceCloudComputer: cloudComputer && cloudLevel ? Object.freeze({
@@ -1295,6 +1590,11 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
1295
1590
  if (!space.viewerReads?.includes(family)) throw protocolError(`This Space does not declare viewer reads of ${family}.`, 'readUnavailable');
1296
1591
  return viewerRead<TResult>(operation, input);
1297
1592
  } : undefined,
1593
+ callFunction: callFunction ? async function guardedFunction<TResult>(name: string, input: Record<string, unknown> = {},
1594
+ options: import('./functions').SpaceFunctionCallOptions = {}): Promise<TResult> {
1595
+ if (!space.functions || !Object.hasOwn(space.functions, name)) throw protocolError('This view cannot call that function.', 'actionUnavailable');
1596
+ return callFunction<TResult>(name, input, options);
1597
+ } : undefined,
1298
1598
  async callAction<TResult>(id: string, inputs: Record<string, unknown> = {}, options: SpaceActionOptions = {}): Promise<TResult> {
1299
1599
  const descriptor = Object.hasOwn(space.actions, id) ? space.actions[id] : null;
1300
1600
  if (!descriptor) throw undeclared(options.readOnly || options.dedupe ? 'actionUnavailable' : undefined);
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Comments on a passage of a page's text (pure; no React). A thread can sit on words (a subject, a Markdown body, any
3
+ * text of the page) instead of a pin: the comment keeps the quoted words, a few words before and after them, and the
4
+ * field they are in when the Space names one (`field`). The quote is found again in the text as it is now, white
5
+ * space ignored, the surrounding words telling apart several matches; when the quoted words are gone the thread reads
6
+ * Passage changed (it stays open with its old quote).
7
+ */
8
+
9
+ import type { Words } from '../../words';
10
+
11
+ /** The words a thread sits on, with the words around them. */
12
+ export interface TextPassage { quote: string; prefix: string; suffix: string }
13
+ /** A passage in one field of the record. */
14
+ export interface PassageAnchor extends TextPassage { field: string }
15
+
16
+ /** A text property comments can sit on. */
17
+ export interface PassageField {
18
+ /** The Space's own name for the field (`subject`, `bodyEn`). */
19
+ key: string;
20
+ /** Its name in the pane, above each quote. */
21
+ label: Words;
22
+ /** Fields shown together, such as one language. The pane lists the threads of the group on screen. */
23
+ group?: string;
24
+ /** The value is Markdown: Text changed and the reading order look at its words, not its syntax. */
25
+ markdown?: boolean;
26
+ }
27
+
28
+ /**
29
+ * The Space page's selection bar hands a selection in a Space's own commentable rich text to that text with this DOM
30
+ * event (detail: `{ range }`), so one bar shows Cite and Comment together and the text draws no button of its own.
31
+ */
32
+ export const PASSAGE_COMMENT_EVENT = 'notis-passage-comment';
33
+ /** On the Space page root while its selection bar takes comments: own rich text then leaves Comment to the bar. */
34
+ export const SELECTION_BAR_COMMENTS_ATTR = 'data-notis-bar-comments';
35
+
36
+ /** Characters kept before and after a quote. */
37
+ export const PASSAGE_CONTEXT = 40;
38
+ /** The longest quote kept. */
39
+ export const PASSAGE_MAX_QUOTE = 1000;
40
+
41
+ const collapse = (value: string) => value.replace(/\s+/g, ' ');
42
+ const squeeze = (value: string) => value.replace(/\s+/g, '');
43
+
44
+ /**
45
+ * Finds a passage in `text`, white space ignored (line breaks and block gaps move with edits). With several matches,
46
+ * the one whose surrounding words best match the stored prefix and suffix. Offsets in `text`, or null when the quoted
47
+ * words are gone.
48
+ */
49
+ export function locatePassage(text: string, passage: TextPassage): { start: number; end: number } | null {
50
+ const quote = squeeze(passage.quote);
51
+ if (!quote) return null;
52
+ const at: number[] = [];
53
+ let flat = '';
54
+ for (let i = 0; i < text.length; i += 1) if (!/\s/.test(text[i]!)) { at.push(i); flat += text[i]; }
55
+ const before = squeeze(passage.prefix);
56
+ const after = squeeze(passage.suffix);
57
+ let best = -1;
58
+ let bestScore = -1;
59
+ for (let k = flat.indexOf(quote); k !== -1; k = flat.indexOf(quote, k + 1)) {
60
+ let score = 0;
61
+ while (score < before.length && k - 1 - score >= 0 && flat[k - 1 - score] === before[before.length - 1 - score]) score += 1;
62
+ let tail = 0;
63
+ const end = k + quote.length;
64
+ while (tail < after.length && end + tail < flat.length && flat[end + tail] === after[tail]) tail += 1;
65
+ if (score + tail > bestScore) { best = k; bestScore = score + tail; }
66
+ }
67
+ if (best < 0) return null;
68
+ return { start: at[best]!, end: at[best + quote.length - 1]! + 1 };
69
+ }
70
+
71
+ /** The passage between two offsets of `text`, with its prefix and suffix; null when only white space is selected. */
72
+ export function passageAt(text: string, start: number, end: number): TextPassage | null {
73
+ const quote = collapse(text.slice(start, end)).trim().slice(0, PASSAGE_MAX_QUOTE);
74
+ if (!squeeze(quote)) return null;
75
+ const prefix = collapse(text.slice(Math.max(0, start - PASSAGE_CONTEXT * 2), start)).trimStart().slice(-PASSAGE_CONTEXT);
76
+ const suffix = collapse(text.slice(end, end + PASSAGE_CONTEXT * 2)).trimEnd().slice(0, PASSAGE_CONTEXT);
77
+ return { quote, prefix, suffix };
78
+ }
79
+
80
+ /** The words a reader sees in Markdown source: link and image targets, HTML tags and markup characters left out. */
81
+ export function markdownReadableText(source: string): string {
82
+ return source
83
+ .replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')
84
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
85
+ .replace(/<[^>]+>/g, ' ')
86
+ .replace(/[*_`#>|~\\]/g, '');
87
+ }
88
+
89
+ /**
90
+ * Where a passage starts in a field's value, or null when its words are no longer there. For Markdown the words are
91
+ * looked for in what a reader sees (the offset is then proportional), then in the source itself.
92
+ */
93
+ export function passageOffset(value: string, passage: TextPassage, markdown = false): number | null {
94
+ if (!markdown) return locatePassage(value, passage)?.start ?? null;
95
+ const words = markdownReadableText(value);
96
+ const hit = locatePassage(words, passage);
97
+ if (hit) return Math.round((hit.start / Math.max(1, words.length)) * value.length);
98
+ return locatePassage(value, passage)?.start ?? null;
99
+ }