@notis_ai/cli 0.2.33 → 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 (56) hide show
  1. package/README.md +1 -2
  2. package/dist/agent-hooks/notis-agent-hook.mjs +82 -19
  3. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  4. package/dist/base-skills/notis-cli/SKILL.md +1 -1
  5. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  6. package/dist/base-skills/notis-spaces/references/comments.md +11 -3
  7. package/dist/sdk/src/components/NotisSelectionBoundary.tsx +13 -5
  8. package/dist/sdk/src/components/SelectionActionBar.tsx +3 -1
  9. package/dist/sdk/src/components/SpaceTextComments.tsx +13 -4
  10. package/dist/sdk/src/components/selectionRange.ts +65 -0
  11. package/dist/sdk/src/config.ts +1 -1
  12. package/dist/sdk/src/functions.ts +17 -2
  13. package/dist/sdk/src/hooks/useCollectionInteractions.ts +59 -7
  14. package/dist/sdk/src/index.ts +4 -3
  15. package/dist/sdk/src/interactions/shortcuts.tsx +6 -1
  16. package/dist/sdk/src/interactions/swipeDownToDismiss.ts +158 -0
  17. package/dist/sdk/src/interactions/textBoxTwoState.ts +174 -0
  18. package/dist/sdk/src/interactions.ts +17 -0
  19. package/dist/sdk/src/space.ts +73 -5
  20. package/dist/skill-sync/index.js +23 -1
  21. package/dist/skill-sync-worker.mjs +62 -3
  22. package/dist/space-harness/host.js +351 -237
  23. package/dist/space-sdk/dist/chunk-3NPBCE6E.js +3 -0
  24. package/dist/space-sdk/dist/index.js +2 -2
  25. package/dist/space-sdk/dist/ui.js +16 -12
  26. package/dist/space-sdk/src/config.ts +1 -1
  27. package/dist/space-sdk/src/functions.ts +17 -2
  28. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +5 -0
  29. package/dist/space-sdk/src/index.d.ts +3 -3
  30. package/dist/space-sdk/src/interactions/shortcuts.d.ts +5 -0
  31. package/dist/space-sdk/src/space.ts +73 -5
  32. package/dist/space-sdk/src/tailwind-candidates.d.ts +234 -71
  33. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +86 -14
  34. package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +4 -1
  35. package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +0 -6
  36. package/dist/space-sdk/src/ui/comments/commentDrafts.d.ts +63 -0
  37. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +4 -0
  38. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +23 -1
  39. package/dist/space-sdk/src/ui/comments/handover.d.ts +34 -0
  40. package/dist/space-sdk/src/ui/comments/hostPanel.d.ts +113 -0
  41. package/dist/space-sdk/src/ui/comments/index.d.ts +6 -1
  42. package/dist/space-sdk/src/ui/comments/paneOutlet.d.ts +33 -0
  43. package/dist/space-sdk/src/ui/comments/paneParts.d.ts +54 -32
  44. package/dist/space-sdk/src/ui/comments/reviewRun.d.ts +190 -0
  45. package/dist/space-sdk/src/ui/comments/useComments.d.ts +52 -3
  46. package/dist/view-renderer/dist/host.js +413 -299
  47. package/package.json +3 -3
  48. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +1 -1
  49. package/src/runtime/agent-identity.js +3 -4
  50. package/src/runtime/app-platform.js +1 -1
  51. package/src/runtime/profiles.js +59 -2
  52. package/src/runtime/skill-sync/cloud-client.ts +33 -3
  53. package/src/runtime/skill-sync/index.ts +1 -1
  54. package/src/runtime/skill-sync/types.ts +4 -1
  55. package/src/runtime/space-functions.js +5 -3
  56. package/dist/space-sdk/dist/chunk-4GWS2IFO.js +0 -3
package/README.md CHANGED
@@ -82,9 +82,8 @@ export NOTIS_AGENT_THREAD_NAME="PR #3851" # the name of the thread you work in,
82
82
  - The CLI tells Notis which harness runs it (Claude Code, Codex, Cursor...) from the variables that harness sets, so your comments show its logo; `NOTIS_AGENT_HARNESS` (`claude_code`, `codex`, `cursor_agent`...) overrides it.
83
83
  - The name is required whenever an id, a thread or a thread name is set. The thread is an id or link of up to 512 characters without spaces. A Notis thread of yours named in `NOTIS_AGENT_THREAD` gets the replies to the agent's comments. A Notis thread you do not own is ignored; any other value (another tool's session id or link) is kept as a label.
84
84
  - The declaration names the writer; it never grants access, and Notis records it as declared. A Notis agent's own Cloud Computer command already carries a signed identity, which wins over a declaration.
85
- - Declarations take effect on accounts with unified comments on (being rolled out). On other accounts Notis ignores them and every write counts as yours, as before; only a badly formed name still stops the command locally.
86
85
  - A comment thread you wrote in last is yours: when the person replies or answers there, Notis wakes no agent of its own; you read the reply the next time you check (`list`, `thread` or `waiting` of `LOCAL_NOTIS_SPACE_COMMENT_THREADS`), and until then the person sees that you have not read it yet. The person can hand the thread to a Notis thread with Change.
87
- - With unified comments on, comments written through the CLI always need a name, even when you type the command yourself: without one the comment is refused with `agent_name_required`, and a declaration without an id with `agent_id_required`. Other writes made with your own sign-in and no declaration count as yours. The Notis assistant itself never writes comments: it starts a sub-agent, whose comments carry the sub-agent's name.
86
+ - Comments are being rolled out: on an account without them the comment tool is not available. Where they are on, comments written through the CLI always need a name, even when you type the command yourself: without one the comment is refused with `agent_name_required`, and a declaration without an id with `agent_id_required`. Other writes made with your own sign-in and no declaration count as yours. The Notis assistant itself never writes comments: it starts a sub-agent, whose comments carry the sub-agent's name.
88
87
 
89
88
  ## Authentication
90
89
 
@@ -27621,6 +27621,7 @@ var init_agent_credential = __esm({
27621
27621
  });
27622
27622
 
27623
27623
  // src/runtime/profiles.js
27624
+ import { spawnSync } from "node:child_process";
27624
27625
  import { createHash as createHash2 } from "node:crypto";
27625
27626
  import {
27626
27627
  existsSync as existsSync3,
@@ -27775,6 +27776,30 @@ function processIsAlive(pid) {
27775
27776
  return error?.code === "EPERM";
27776
27777
  }
27777
27778
  }
27779
+ function localRuntimeApiAnswers(apiBase) {
27780
+ if (runtimeApiProbeResults.has(apiBase)) {
27781
+ return runtimeApiProbeResults.get(apiBase);
27782
+ }
27783
+ let answered = false;
27784
+ try {
27785
+ const probe = spawnSync(process.execPath, ["-e", RUNTIME_API_PROBE_SOURCE, apiBase], {
27786
+ env: { PATH: process.env.PATH || "" },
27787
+ stdio: "ignore",
27788
+ timeout: RUNTIME_API_PROBE_TIMEOUT_MS + 2500
27789
+ });
27790
+ answered = probe.status === 0;
27791
+ } catch {
27792
+ answered = false;
27793
+ }
27794
+ runtimeApiProbeResults.set(apiBase, answered);
27795
+ return answered;
27796
+ }
27797
+ function devRuntimeIsAlive(pid, apiBase) {
27798
+ if (processIsAlive(pid)) {
27799
+ return true;
27800
+ }
27801
+ return Number.isInteger(pid) && pid > 0 && localRuntimeApiAnswers(apiBase);
27802
+ }
27778
27803
  function resolveWorktreeRuntime(startDir = process.cwd()) {
27779
27804
  if (process.env.NODE_ENV === "test" && process.env.NOTIS_TEST_DISABLE_WORKTREE_ROUTING === "1") {
27780
27805
  return null;
@@ -27801,12 +27826,14 @@ function resolveWorktreeRuntime(startDir = process.cwd()) {
27801
27826
  return null;
27802
27827
  }
27803
27828
  const runtime = readJsonFile(runtimePath);
27829
+ const secrets = readJsonFile(join4(dirname4(runtimePath), WORKTREE_RUNTIME_SECRETS_FILENAME));
27830
+ const sessionSecrets = secrets && runtime && secrets.dev_session_id === runtime.dev_session_id ? secrets : null;
27804
27831
  const apiBase = typeof runtime?.api_base === "string" ? runtime.api_base.replace(/\/+$/, "") : "";
27805
27832
  const profile = typeof runtime?.profile === "string" ? runtime.profile.trim() : "";
27806
- const devAccessToken = typeof runtime?.dev_access_token === "string" ? runtime.dev_access_token.trim() : "";
27833
+ const devAccessToken = typeof sessionSecrets?.dev_access_token === "string" && sessionSecrets.dev_access_token.trim() ? sessionSecrets.dev_access_token.trim() : typeof runtime?.dev_access_token === "string" ? runtime.dev_access_token.trim() : "";
27807
27834
  const desktopDeepLinkScheme = typeof runtime?.desktop_deep_link_scheme === "string" ? runtime.desktop_deep_link_scheme.trim() : "";
27808
27835
  const pid = Number(runtime?.dev_pid);
27809
- if (runtime?.mode !== "local-only" || !isLocalApiBase(apiBase) || !profile || !devAccessToken || !processIsAlive(pid)) {
27836
+ if (runtime?.mode !== "local-only" || !isLocalApiBase(apiBase) || !profile || !devAccessToken || !devRuntimeIsAlive(pid, apiBase)) {
27810
27837
  return {
27811
27838
  unavailable: new CliError({
27812
27839
  code: "dev_runtime_unavailable",
@@ -28319,7 +28346,7 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds2 = Math.floor(Dat
28319
28346
  function workspacePath(appId) {
28320
28347
  return join4(WORKSPACE_DIR, appId);
28321
28348
  }
28322
- var CONFIG_DIR, CONFIG_FILE, WORKSPACE_DIR, DEFAULT_API_BASE, NIGHTLY_API_BASE, DEFAULT_PROFILE, PROFILE_NAME_PATTERN, LEGACY_DESKTOP_PROFILE_KEYS, WORKTREE_RUNTIME_FILENAME, WORKTREE_ROUTING_FILENAME, LOCAL_API_HOSTS;
28349
+ var CONFIG_DIR, CONFIG_FILE, WORKSPACE_DIR, DEFAULT_API_BASE, NIGHTLY_API_BASE, DEFAULT_PROFILE, PROFILE_NAME_PATTERN, LEGACY_DESKTOP_PROFILE_KEYS, WORKTREE_RUNTIME_FILENAME, WORKTREE_RUNTIME_SECRETS_FILENAME, WORKTREE_ROUTING_FILENAME, LOCAL_API_HOSTS, RUNTIME_API_PROBE_TIMEOUT_MS, RUNTIME_API_PROBE_SOURCE, runtimeApiProbeResults;
28323
28350
  var init_profiles = __esm({
28324
28351
  "src/runtime/profiles.js"() {
28325
28352
  init_errors();
@@ -28347,8 +28374,20 @@ var init_profiles = __esm({
28347
28374
  "desktop_pid"
28348
28375
  ];
28349
28376
  WORKTREE_RUNTIME_FILENAME = join4(".context", "notis-runtime.json");
28377
+ WORKTREE_RUNTIME_SECRETS_FILENAME = "notis-runtime-secrets.json";
28350
28378
  WORKTREE_ROUTING_FILENAME = join4(".context", "notis-routing.json");
28351
28379
  LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
28380
+ RUNTIME_API_PROBE_TIMEOUT_MS = 1500;
28381
+ RUNTIME_API_PROBE_SOURCE = `
28382
+ const target = process.argv[1].replace(/\\/+$/, '') + '/openapi.json';
28383
+ fetch(target, { redirect: 'manual', signal: AbortSignal.timeout(${RUNTIME_API_PROBE_TIMEOUT_MS}) })
28384
+ .then((response) => {
28385
+ response.body?.cancel().catch(() => {});
28386
+ process.exit(response.ok ? 0 : 1);
28387
+ })
28388
+ .catch(() => process.exit(1));
28389
+ `;
28390
+ runtimeApiProbeResults = /* @__PURE__ */ new Map();
28352
28391
  }
28353
28392
  });
28354
28393
 
@@ -38108,6 +38147,8 @@ var require_dist = __commonJS({
38108
38147
  // dist/skill-sync/index.js
38109
38148
  var skill_sync_exports = {};
38110
38149
  __export(skill_sync_exports, {
38150
+ MAX_SYNC_PUSH_SKILL_BYTES: () => MAX_SYNC_PUSH_SKILL_BYTES,
38151
+ SERVER_REQUEST_BODY_MAX_BYTES: () => SERVER_REQUEST_BODY_MAX_BYTES,
38111
38152
  fetchSyncSettings: () => fetchSyncSettings,
38112
38153
  isolatedLinkOptions: () => isolatedLinkOptions,
38113
38154
  materializeCloudSkillsForLocalShell: () => materializeCloudSkillsForLocalShell,
@@ -39126,6 +39167,18 @@ async function skillPushPayload(skill) {
39126
39167
  } : {}
39127
39168
  };
39128
39169
  }
39170
+ function mib(bytes) {
39171
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
39172
+ }
39173
+ function tooLargeFailure(name, sizeBytes, limitBytes) {
39174
+ return {
39175
+ name,
39176
+ error: `Skill is too large to sync (${mib(sizeBytes)}, the limit is ${mib(limitBytes)}); remove large files from its folder to sync it`,
39177
+ code: "skill_too_large",
39178
+ size_bytes: sizeBytes,
39179
+ limit_bytes: limitBytes
39180
+ };
39181
+ }
39129
39182
  function pushBatches(payloads, maxBodyBytes) {
39130
39183
  const batches = [];
39131
39184
  let batch = [];
@@ -39156,9 +39209,15 @@ function pushFailure(name, error) {
39156
39209
  return { name, error: "Upload failed; sync will retry", code };
39157
39210
  }
39158
39211
  async function pushChangedSkills(serverUrl, jwt, changedSkills, options = {}) {
39159
- const payloadSkills = await Promise.all(changedSkills.map(skillPushPayload));
39212
+ const maxSkillBytes = options.maxSkillBytes ?? MAX_SYNC_PUSH_SKILL_BYTES;
39160
39213
  const saved = [];
39161
39214
  const failed = [];
39215
+ const payloadSkills = [];
39216
+ for (const payload of await Promise.all(changedSkills.map(skillPushPayload))) {
39217
+ const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
39218
+ if (bytes > maxSkillBytes) failed.push(tooLargeFailure(String(payload.name), bytes, maxSkillBytes));
39219
+ else payloadSkills.push(payload);
39220
+ }
39162
39221
  for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
39163
39222
  try {
39164
39223
  const result = await requestJson(`${serverUrl}/portal_skills/sync-push`, jwt, {
@@ -40396,7 +40455,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
40396
40455
  failedPushes
40397
40456
  };
40398
40457
  }
40399
- var DEFAULT_AGENT_TARGETS, NATIVE_IDENTITY_FILE, UUID2, HOME_DIR, execFileAsync, NativeSkillIdentityError, AGENTS_DIR, LEGACY_AGENTS_SKILLS_DIR, NOTIS_SKILL_SYNC_ROOT, LEGACY_NOTIS_SYNC_STATE_PATH, AGENTS_SKILLS_DIR, SKILL_LOCK_PATH, DEFAULT_SYNC_STATE, EXCLUDED_TOP_LEVEL_ROOT_NAMES, DEFAULT_SYNC_PATHS, IGNORED_SKILL_DIRECTORIES, SkillSyncHttpError, MAX_SYNC_PUSH_BODY_BYTES, SYNC_PUSH_ENVELOPE_BYTES, HOME_DIR2, EXTERNAL_AGENT_SKILL_DIRS, EXTERNAL_AGENTS, AGENT_FAILURE_LABELS, BASE_SKILL_LINK_NAMES, NATIVE_FOLDER_NAME, READABLE_SKILL_NAME, BASE_SKILL_NAMES2, DEFAULT_RUN_SKILL_SYNC_DEPS, MIRROR_ONLY_DEPS;
40458
+ var DEFAULT_AGENT_TARGETS, NATIVE_IDENTITY_FILE, UUID2, HOME_DIR, execFileAsync, NativeSkillIdentityError, AGENTS_DIR, LEGACY_AGENTS_SKILLS_DIR, NOTIS_SKILL_SYNC_ROOT, LEGACY_NOTIS_SYNC_STATE_PATH, AGENTS_SKILLS_DIR, SKILL_LOCK_PATH, DEFAULT_SYNC_STATE, EXCLUDED_TOP_LEVEL_ROOT_NAMES, DEFAULT_SYNC_PATHS, IGNORED_SKILL_DIRECTORIES, SkillSyncHttpError, MAX_SYNC_PUSH_BODY_BYTES, SYNC_PUSH_ENVELOPE_BYTES, SERVER_REQUEST_BODY_MAX_BYTES, MAX_SYNC_PUSH_SKILL_BYTES, HOME_DIR2, EXTERNAL_AGENT_SKILL_DIRS, EXTERNAL_AGENTS, AGENT_FAILURE_LABELS, BASE_SKILL_LINK_NAMES, NATIVE_FOLDER_NAME, READABLE_SKILL_NAME, BASE_SKILL_NAMES2, DEFAULT_RUN_SKILL_SYNC_DEPS, MIRROR_ONLY_DEPS;
40400
40459
  var init_skill_sync = __esm({
40401
40460
  "dist/skill-sync/index.js"() {
40402
40461
  DEFAULT_AGENT_TARGETS = {
@@ -40465,6 +40524,8 @@ var init_skill_sync = __esm({
40465
40524
  };
40466
40525
  MAX_SYNC_PUSH_BODY_BYTES = 2 * 1024 * 1024;
40467
40526
  SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
40527
+ SERVER_REQUEST_BODY_MAX_BYTES = 64 * 1024 * 1024;
40528
+ MAX_SYNC_PUSH_SKILL_BYTES = SERVER_REQUEST_BODY_MAX_BYTES - SYNC_PUSH_ENVELOPE_BYTES;
40468
40529
  HOME_DIR2 = os2.homedir();
40469
40530
  EXTERNAL_AGENT_SKILL_DIRS = {
40470
40531
  claude_code: path22.join(HOME_DIR2, ".claude", "skills"),
@@ -67358,7 +67419,7 @@ import { randomUUID as randomUUID8 } from "node:crypto";
67358
67419
 
67359
67420
  // src/runtime/git.js
67360
67421
  init_errors();
67361
- import { spawnSync } from "node:child_process";
67422
+ import { spawnSync as spawnSync2 } from "node:child_process";
67362
67423
  import { lstatSync as lstatSync2, readFileSync as readFileSync14 } from "node:fs";
67363
67424
  import { basename as basename6, relative as relative2, resolve as resolve4, sep } from "node:path";
67364
67425
  var GIT_TIMEOUT_MS = 12e4;
@@ -67373,7 +67434,7 @@ var SENSITIVE_CONTENT = [
67373
67434
  /\bsk-[A-Za-z0-9_-]{20,}\b/
67374
67435
  ];
67375
67436
  function runGit(args, { cwd = process.cwd(), timeoutMs = GIT_TIMEOUT_MS, trimOutput = true } = {}) {
67376
- const result = spawnSync("git", args, {
67437
+ const result = spawnSync2("git", args, {
67377
67438
  cwd,
67378
67439
  encoding: "utf8",
67379
67440
  timeout: timeoutMs,
@@ -68204,7 +68265,7 @@ init_oauth();
68204
68265
  // src/runtime/skill-sync-service.js
68205
68266
  init_api_hosts();
68206
68267
  init_profiles();
68207
- import { spawnSync as spawnSync2 } from "node:child_process";
68268
+ import { spawnSync as spawnSync3 } from "node:child_process";
68208
68269
  import { createHash as createHash14 } from "node:crypto";
68209
68270
  import { existsSync as existsSync10, mkdirSync as mkdirSync10, readFileSync as readFileSync15, renameSync as renameSync10, writeFileSync as writeFileSync10 } from "node:fs";
68210
68271
  import { homedir as homedir8 } from "node:os";
@@ -68255,7 +68316,7 @@ async function installSkillSyncServiceLocked(runtime, {
68255
68316
  platform = process.platform,
68256
68317
  nodePath = process.execPath,
68257
68318
  source = bundlePath,
68258
- run = spawnSync2,
68319
+ run = spawnSync3,
68259
68320
  uid = process.getuid?.()
68260
68321
  } = {}) {
68261
68322
  if (platform !== "darwin") return { status: "unsupported_platform" };
@@ -68692,7 +68753,7 @@ import { join as join19 } from "node:path";
68692
68753
 
68693
68754
  // src/runtime/app-platform.js
68694
68755
  init_errors();
68695
- import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
68756
+ import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
68696
68757
  import { createHash as createHash15, randomUUID as randomUUID10 } from "node:crypto";
68697
68758
  import { closeSync, constants as fsConstants2, copyFileSync, cpSync as cpSync2, existsSync as existsSync13, fstatSync, linkSync, lstatSync as lstatSync4, mkdirSync as mkdirSync11, mkdtempSync as mkdtempSync2, openSync, readFileSync as readFileSync18, realpathSync as realpathSync2, renameSync as renameSync11, rmdirSync as rmdirSync2, unlinkSync as unlinkSync4, writeFileSync as writeFileSync11, readdirSync as readdirSync7, rmSync as rmSync5, statSync as statSync5 } from "node:fs";
68698
68759
  import { createRequire as createRequire2 } from "node:module";
@@ -69574,7 +69635,7 @@ function stripNotisSdkImports(source) {
69574
69635
  const schemas = [];
69575
69636
  for (const imported of names2.split(",").map((value) => value.trim()).filter(Boolean)) {
69576
69637
  if (imported.startsWith("type ")) continue;
69577
- if (/^(threadHookInput|threadSettleInput|commentOptionInput)(?:\s+as\s+[A-Za-z_$][\w$]*)?$/.test(imported)) {
69638
+ if (/^(threadHookInput|threadIdleInput|threadSettleInput|commentOptionInput)(?:\s+as\s+[A-Za-z_$][\w$]*)?$/.test(imported)) {
69578
69639
  schemas.push(imported);
69579
69640
  continue;
69580
69641
  }
@@ -70223,7 +70284,7 @@ var LOCK_UPDATE_ARGS = Object.freeze([
70223
70284
  "--fetch-retry-mintimeout=1000"
70224
70285
  ]);
70225
70286
  function updatePackageLock(projectDir) {
70226
- const result = spawnSync3("npm", [...LOCK_UPDATE_ARGS], {
70287
+ const result = spawnSync4("npm", [...LOCK_UPDATE_ARGS], {
70227
70288
  cwd: projectDir,
70228
70289
  encoding: "utf8",
70229
70290
  stdio: ["ignore", "pipe", "pipe"],
@@ -72384,7 +72445,7 @@ var EXPOSURES = ["page", "api", "agents"];
72384
72445
  var ROLES = ["public", "viewer", "editor", "key"];
72385
72446
  var LEVELS = ["read", "shell"];
72386
72447
  var THREAD_OPERATIONS = Object.freeze(["archive", "unarchive", "read", "unread", "star", "unstar", "later", "back"]);
72387
- var THREAD_HOOK_EVENTS = Object.freeze([...THREAD_OPERATIONS, "delete"]);
72448
+ var THREAD_HOOK_EVENTS = Object.freeze([...THREAD_OPERATIONS, "delete", "idle"]);
72388
72449
  var FUNCTION_FIELDS = ["description", "kind", "input", "output", "expose", "access", "uses", "handler"];
72389
72450
  var USES_FIELDS = ["actions", "cloudComputer", "threads"];
72390
72451
  var HOOK_INPUT_FIELDS = "actor,event,items,thread";
@@ -72469,8 +72530,10 @@ function validateSpaceFunctions(definition, { entry } = {}) {
72469
72530
  if (!hasItems) throw usageError("threadHooks follow the threads this Space's items are attached to: declare threadItems first.");
72470
72531
  for (const [event, name] of Object.entries(threadHooks)) {
72471
72532
  if (typeof name !== "string" || !Object.hasOwn(functions, name)) throw usageError(`Thread hook ${event} names a function this Space does not declare.`);
72472
- if (inputFields(functions[name]) !== HOOK_INPUT_FIELDS) {
72473
- throw usageError(`Function ${name} runs as a thread hook: declare its input as threadHookInput from @notis/sdk.`);
72533
+ const idle = event === "idle";
72534
+ if (inputFields(functions[name]) !== (idle ? "actor,event,items,run_id,thread" : HOOK_INPUT_FIELDS)) {
72535
+ const schema = idle ? "threadIdleInput" : "threadHookInput";
72536
+ throw usageError(`Function ${name} runs as a thread hook: declare its input as ${schema} from @notis/sdk.`);
72474
72537
  }
72475
72538
  }
72476
72539
  }
@@ -73094,7 +73157,7 @@ init_errors();
73094
73157
 
73095
73158
  // src/runtime/space-dependencies.js
73096
73159
  init_errors();
73097
- import { spawnSync as spawnSync4 } from "node:child_process";
73160
+ import { spawnSync as spawnSync5 } from "node:child_process";
73098
73161
  import { existsSync as existsSync14 } from "node:fs";
73099
73162
  import { createRequire as createRequire4 } from "node:module";
73100
73163
  import { join as join23 } from "node:path";
@@ -73110,7 +73173,7 @@ function spaceDependenciesInstalled(projectDir) {
73110
73173
  }
73111
73174
  }
73112
73175
  function runNpm(args, projectDir) {
73113
- return spawnSync4("npm", args, {
73176
+ return spawnSync5("npm", args, {
73114
73177
  cwd: projectDir,
73115
73178
  encoding: "utf8",
73116
73179
  stdio: ["ignore", "pipe", "pipe"],
@@ -77199,7 +77262,7 @@ var ccCommandSpecs = [
77199
77262
 
77200
77263
  // src/command-specs/computer.js
77201
77264
  init_errors();
77202
- import { spawn as spawn4, spawnSync as spawnSync5 } from "node:child_process";
77265
+ import { spawn as spawn4, spawnSync as spawnSync6 } from "node:child_process";
77203
77266
  import { randomUUID as randomUUID14 } from "node:crypto";
77204
77267
  import { existsSync as existsSync22, mkdirSync as mkdirSync17, readFileSync as readFileSync26 } from "node:fs";
77205
77268
  import { connect as netConnect } from "node:net";
@@ -77325,7 +77388,7 @@ function readPublicKey(paths) {
77325
77388
  }
77326
77389
  function makeKey(paths, deviceName) {
77327
77390
  mkdirSync17(paths.dir, { recursive: true, mode: 448 });
77328
- const result = spawnSync5("ssh-keygen", [
77391
+ const result = spawnSync6("ssh-keygen", [
77329
77392
  "-q",
77330
77393
  "-t",
77331
77394
  "ed25519",
@@ -1 +1 @@
1
- {"schema":1,"stamp":1795375614,"commit":"f09e2798430a8975fc45a48f786a4c155368285f"}
1
+ {"schema":1,"stamp":1795641403,"commit":"f4cf1ecad4007a21c73c2a394187d804ddeceb48"}
@@ -68,7 +68,7 @@ export NOTIS_AGENT_THREAD_NAME="PR #3851" # the thread you work in, shown
68
68
  export NOTIS_AGENT_THREAD="<Notis thread id>" # only when you work for one of the person's Notis threads
69
69
  ```
70
70
 
71
- or pass `--agent-name`, `--agent-id`, `--agent-thread-name` and `--agent-thread` on a single command (a flag wins over its variable). Without `NOTIS_AGENT_ID` the CLI generates one id for each name the first time it is used on the computer and keeps sending it; the id is what makes your comments yours to edit or delete. The CLI also sends the harness that runs it (Claude Code, Codex, Cursor), detected from that harness's own variables, so your comments show its logo; `NOTIS_AGENT_HARNESS` overrides it. A comment thread you wrote in last is held by you: when the person replies or answers there, Notis wakes no agent of its own, so read the replies yourself when you check (`waiting`, `list` or `thread` of `LOCAL_NOTIS_SPACE_COMMENT_THREADS`); until you read them the person sees "<your name> has not read it yet". Name a Notis thread only when you work for one of the person's Notis threads: replies to your comments then wake that thread; anything else is kept as a label. Declarations take effect where the person has unified comments on (being rolled out); elsewhere Notis ignores them and writes count as the person's, as before. With unified comments on, every comment written through the CLI needs the name, even one the person types: without it the write is refused (`agent_name_required`), and a name sent without an id is refused too (`agent_id_required`). Other writes with the person's own sign-in and no name are the person's. A name that breaks the rule is sent as written and the server refuses the call (`invalid_agent_identity`) where unified comments are on, reads included; elsewhere it is ignored. A declaration names you; it never gives access to anything more. The Notis assistant itself never writes comments (`orchestrator_comments_refused`): it starts a sub-agent for comment work, signed with that sub-agent's band name.
71
+ or pass `--agent-name`, `--agent-id`, `--agent-thread-name` and `--agent-thread` on a single command (a flag wins over its variable). Without `NOTIS_AGENT_ID` the CLI generates one id for each name the first time it is used on the computer and keeps sending it; the id is what makes your comments yours to edit or delete. The CLI also sends the harness that runs it (Claude Code, Codex, Cursor), detected from that harness's own variables, so your comments show its logo; `NOTIS_AGENT_HARNESS` overrides it. A comment thread you wrote in last is held by you: when the person replies or answers there, Notis wakes no agent of its own, so read the replies yourself when you check (`waiting`, `list` or `thread` of `LOCAL_NOTIS_SPACE_COMMENT_THREADS`); until you read them the person sees "<your name> has not read it yet". Name a Notis thread only when you work for one of the person's Notis threads: replies to your comments then wake that thread; anything else is kept as a label. Comments are being rolled out: where the person does not have them, `LOCAL_NOTIS_SPACE_COMMENT_THREADS` is not available. Where they are on, every comment written through the CLI needs the name, even one the person types: without it the write is refused (`agent_name_required`), and a name sent without an id is refused too (`agent_id_required`). Other writes with the person's own sign-in and no name are the person's. A name that breaks the rule is sent as written and the server refuses the call (`invalid_agent_identity`), reads included. A declaration names you; it never gives access to anything more. The Notis assistant itself never writes comments (`orchestrator_comments_refused`): it starts a sub-agent for comment work, signed with that sub-agent's band name.
72
72
 
73
73
  Space comments are not database rows: read and write them only with `LOCAL_NOTIS_SPACE_COMMENT_THREADS` (for example `notis tools exec LOCAL_NOTIS_SPACE_COMMENT_THREADS --arguments '{"protocol":2,"operation":"list","space":"<space id>","page":"all"}'`, then `reply` with the root's `comment_id` and a `body`), never with `LOCAL_NOTIS_DATABASE_QUERY` or an upsert. Check its schema with `--get-schema` first. Agents never archive comments.
74
74
 
@@ -1 +1 @@
1
- {"schema":1,"stamp":1795375614,"commit":"f09e2798430a8975fc45a48f786a4c155368285f"}
1
+ {"schema":1,"stamp":1795641403,"commit":"f4cf1ecad4007a21c73c2a394187d804ddeceb48"}
@@ -77,9 +77,17 @@ Agents read and write comments only with `LOCAL_NOTIS_SPACE_COMMENT_THREADS`
77
77
  (`protocol` 2; operations `list`, `thread`, `comment`, `reply`, `edit`, `delete`,
78
78
  `restore`, `answer`, `links`, `link`, `unlink`, `waiting`, `best_match`,
79
79
  `viewer`, `page_link`; parameters `space`, `page` (a record key, `home` or
80
- `all`), `view`, `anchor`, `comment_id`, `body`, `needs`, `options`,
81
- `answer_to`, `answer`, `files`). Never query or upsert comments through a
82
- database tool. Agents never archive: that is the people's. An agent's
80
+ `all`), `status`, `limit`, `before`, `view`, `anchor`, `comment_id`, `body`, `needs`, `options`,
81
+ `recommended`, `option_details`, `answer_to`, `answer`, `files`). A question
82
+ with choices (`needs: "choice"`) shows one row per option, like a question in
83
+ a conversation: keep each option a short name, name the one you recommend in
84
+ `recommended` (it gets the Recommended tag and Enter picks it) and say what
85
+ an option means in one line with `option_details` (`{"<option>": "<line>"}`).
86
+ `list` on a whole Space answers its open comment threads, newest first and
87
+ each with its replies, 50 at a time (`status` `done` or `all` for the others,
88
+ `next` back as `before` for the ones after, `counts` for the totals), never
89
+ every comment the Space ever held.
90
+ Never query or upsert comments through a database tool. Agents never archive: that is the people's. An agent's
83
91
  comment is signed with its band name and never wakes it; the Notis
84
92
  assistant never writes comments itself (`orchestrator_comments_refused`)
85
93
  and starts a sub-agent for comment work. Through the Notis CLI, every
@@ -3,6 +3,7 @@ import React, { useCallback } from 'react';
3
3
  import { useNotisRuntime } from '../provider';
4
4
  import type { ContextResource, ContextSelection, NotisRuntime } from '../runtime';
5
5
  import { newSelectionId } from './selectionId';
6
+ import { trimRange } from './selectionRange';
6
7
 
7
8
  export const NOTIS_CONTEXT_CLIPBOARD_TYPE = 'application/x-notis-context+json';
8
9
 
@@ -14,10 +15,10 @@ export interface NotisSelectionBoundaryProps {
14
15
  }
15
16
 
16
17
  /** The selection's markup for other paste targets: hidden parts dropped, links made absolute. */
17
- function selectionHtml(selection: Selection): string {
18
+ function selectionHtml(ranges: Range[]): string {
18
19
  if (typeof document === 'undefined') return '';
19
20
  const container = document.createElement('div');
20
- for (let index = 0; index < selection.rangeCount; index += 1) container.appendChild(selection.getRangeAt(index).cloneContents());
21
+ for (const range of ranges) container.appendChild(range.cloneContents());
21
22
  container.querySelectorAll('[hidden],script,style,template').forEach(node => node.remove());
22
23
  container.querySelectorAll('[href],[src]').forEach(node => {
23
24
  for (const name of ['href', 'src']) {
@@ -48,18 +49,25 @@ export function addCopiedSelectionToClipboard(
48
49
  if (event.clipboardData.getData(NOTIS_CONTEXT_CLIPBOARD_TYPE)) return null;
49
50
  const scope = boundary.getRootNode() as ShadowRoot & { getSelection?: () => Selection | null };
50
51
  const selection = scope?.getSelection?.() || window.getSelection();
51
- if (!selection || !boundary.contains(selection.anchorNode) || !boundary.contains(selection.focusNode)) return null;
52
+ if (!selection?.rangeCount) return null;
53
+ // A paragraph selected by clicking ends at the next block's start, often past the boundary: its words are still here.
54
+ const live = selection.getRangeAt(0);
55
+ const range = trimRange(live);
56
+ if (!boundary.contains(range.startContainer) || !boundary.contains(range.endContainer)) return null;
52
57
  const editorWrote = event.nativeEvent?.defaultPrevented ?? event.defaultPrevented;
53
58
  const wrotePlain = editorWrote ? event.clipboardData.getData('text/plain') : '';
54
59
  // A handler that cancelled the copy and wrote nothing at all blocked it: quote nothing.
55
60
  if (editorWrote && !wrotePlain && !event.clipboardData.getData('text/html')) return null;
56
- const text = wrotePlain || selection.toString();
61
+ // A paragraph selected by clicking is copied as its words, without the next block it reaches into.
62
+ const trimmed = range !== live && selection.rangeCount === 1;
63
+ const ranges = trimmed ? [range] : Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index));
64
+ const text = wrotePlain || (trimmed ? range.toString() : selection.toString());
57
65
  if (!text.trim()) return null;
58
66
 
59
67
  const payload: ContextSelection = { ...context, id: newSelectionId(), text };
60
68
  if (!editorWrote) {
61
69
  // Keep the copied formatting (links, bold, tables) for every other paste target.
62
- const html = selectionHtml(selection);
70
+ const html = selectionHtml(ranges);
63
71
  event.clipboardData.setData('text/plain', text);
64
72
  if (html) event.clipboardData.setData('text/html', html);
65
73
  event.preventDefault();
@@ -2,6 +2,7 @@
2
2
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from 'react';
3
3
  import { useToolkitLocale } from '../ui/engine/hooks';
4
4
  import type { Words } from '../words/types';
5
+ import { trimRange } from './selectionRange';
5
6
 
6
7
  /**
7
8
  * The floating bar on selected text (truths PRT-087, PRT-090, PRT-094): one dark labelled pill at the end of the
@@ -149,7 +150,8 @@ export function useSelectionAnchor(root: RefObject<HTMLElement | null>, options:
149
150
  const selection = selectionIn(node);
150
151
  if (!selection?.rangeCount || selection.isCollapsed || !selection.toString().trim()) return null;
151
152
  const live = selection.getRangeAt(0);
152
- let range: Range | null = live.cloneRange();
153
+ // A paragraph selection ends at the next block's start, often outside the surface: read it up to its last word.
154
+ let range: Range | null = trimRange(live.cloneRange());
153
155
  const clipped = !node.contains(range.startContainer) || !node.contains(range.endContainer);
154
156
  if (clipped) {
155
157
  // A selection in another tree (the page around a Space's shadow root) cannot be compared with this one.
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Text comments on every Space page (SPC-118 text mode): Comment on selected words (the shared selection bar, next to
4
4
  * Cite) and the highlights of the page's open text comments. Both need the host comment store
5
- * (`runtime.spaceComments`, on while `unified_comments` is); without it the page shows Cite alone and no highlights.
5
+ * (`runtime.spaceComments`); without it the page shows Cite alone and no highlights.
6
6
  *
7
7
  * A text comment keeps its words with up to 40 characters before and after them. The highlights find those words
8
8
  * again in the page as it is now (white space ignored, the surrounding words telling apart several matches); words
@@ -138,10 +138,19 @@ function usePageTextComments(transport: SpaceCommentsTransport | undefined): Spa
138
138
  if (!store) { setRows([]); return undefined; }
139
139
  let live = true;
140
140
  let seq = 0;
141
+ // The Space home: its open comments are among the Space's open threads, which the home's pane reads by thread
142
+ // (`threads`). The highlights read that same copy, never every comment of the home (Done and deleted ones too).
143
+ // A host without that read, or whose server cannot answer it (null), lists the home as before.
144
+ let byThread = page === null && typeof store.threads === 'function';
145
+ const list = (mine: number) => store.list({ page }).then(answer => {
146
+ if (live && mine === seq) setRows(Array.isArray(answer?.comments) ? answer.comments : []);
147
+ }, () => undefined);
141
148
  const read = () => {
142
149
  const mine = ++seq;
143
- store.list({ page }).then(answer => {
144
- if (live && mine === seq) setRows(Array.isArray(answer?.comments) ? answer.comments : []);
150
+ if (!byThread || !store.threads) { void list(mine); return; }
151
+ store.threads({}).then(answer => {
152
+ if (!answer) { byThread = false; void list(mine); return; }
153
+ if (live && mine === seq) setRows((Array.isArray(answer.comments) ? answer.comments : []).filter(row => row.page_key == null));
145
154
  }, () => undefined);
146
155
  };
147
156
  // The first read waits for the page to go idle: a Space open never contends with the highlights' read and drawing
@@ -152,7 +161,7 @@ function usePageTextComments(transport: SpaceCommentsTransport | undefined): Spa
152
161
  const idleRead = idleWindow ? idleWindow.requestIdleCallback(read, { timeout: 1500 }) : null;
153
162
  const timer = idleWindow ? null : setTimeout(read, 0);
154
163
  let stop: (() => void) | undefined;
155
- try { stop = store.subscribe({ page }, read); } catch { /* no live feed */ }
164
+ try { stop = store.subscribe({ page: byThread ? 'all' : page }, read); } catch { /* no live feed */ }
156
165
  return () => {
157
166
  live = false;
158
167
  if (idleRead !== null) cancelIdle?.call(idleWindow, idleRead);
@@ -0,0 +1,65 @@
1
+ // Node and NodeFilter constants, without their globals (absent from some test and frame realms).
2
+ const TEXT_NODE = 3;
3
+ const SHOW_TEXT = 0x4;
4
+ // Text nobody reads as selected words: code, styles and the selection bar's own labels.
5
+ const UNREAD = 'script,style,noscript,template,[data-notis-selection-ui]';
6
+
7
+ function isText(node: Node): node is Text {
8
+ return node.nodeType === TEXT_NODE;
9
+ }
10
+
11
+ function blankBefore(text: string, end: number): number {
12
+ let index = end;
13
+ while (index > 0 && /\s/.test(text[index - 1]!)) index -= 1;
14
+ return index;
15
+ }
16
+
17
+ function blankAfter(text: string, start: number): number {
18
+ let index = start;
19
+ while (index < text.length && /\s/.test(text[index]!)) index += 1;
20
+ return index;
21
+ }
22
+
23
+ /**
24
+ * A copy of `range` reduced to its selected words. Selecting a whole sentence or paragraph by clicking ends the
25
+ * browser's range at the start of the next block (Chrome, Safari) or starts it before the block (Firefox), which may
26
+ * lie outside the surface or be the selection bar itself: the words are the same, so the surface reads them and its
27
+ * bar stays. Returns `range` itself when both its ends already sit on selected words.
28
+ */
29
+ export function trimRange(range: Range): Range {
30
+ const { startContainer, startOffset, endContainer, endOffset, commonAncestorContainer } = range;
31
+ const startsOnWords = isText(startContainer) && startContainer.data.slice(startOffset,
32
+ startContainer === endContainer ? endOffset : undefined).trim();
33
+ const endsOnWords = isText(endContainer) && endContainer.data.slice(
34
+ endContainer === startContainer ? startOffset : 0, endOffset).trim();
35
+ if ((startsOnWords && endsOnWords) || isText(commonAncestorContainer)) return range;
36
+ const document = commonAncestorContainer.ownerDocument;
37
+ if (!document) return range;
38
+ const walker = document.createTreeWalker(commonAncestorContainer, SHOW_TEXT);
39
+ // Start at the range's start, not at the top of a container that may hold the whole page.
40
+ let node: Node | null = null;
41
+ const child = isText(startContainer) ? startContainer : startContainer.childNodes[startOffset];
42
+ if (child && isText(child)) node = child;
43
+ else {
44
+ walker.currentNode = child ?? commonAncestorContainer;
45
+ node = walker.nextNode();
46
+ }
47
+ let first: { node: Text; offset: number } | null = null;
48
+ let last: { node: Text; offset: number } | null = null;
49
+ for (; node; walker.currentNode = node, node = walker.nextNode()) {
50
+ if (range.comparePoint(node, 0) > 0) break;
51
+ if (!isText(node) || !range.intersectsNode(node) || node.parentElement?.closest(UNREAD)) continue;
52
+ const from = node === startContainer ? startOffset : 0;
53
+ const to = node === endContainer ? endOffset : node.data.length;
54
+ const words = node.data.slice(from, to);
55
+ if (!words.trim()) continue;
56
+ if (!first) first = { node, offset: blankAfter(node.data, from) };
57
+ last = { node, offset: blankBefore(node.data, to) };
58
+ if (node === endContainer) break;
59
+ }
60
+ if (!first || !last) return range;
61
+ const trimmed = range.cloneRange();
62
+ if (!startsOnWords) trimmed.setStart(first.node, first.offset);
63
+ if (!endsOnWords) trimmed.setEnd(last.node, last.offset);
64
+ return trimmed;
65
+ }
@@ -1,7 +1,7 @@
1
1
  export { defineSpace, defineSpaces } from './space';
2
2
  export type { SpaceDefinition, SpacesWorkspace, SpaceActionTemplate, SpaceResourceReference, SpaceDatabaseCreate, SpaceStore } from './space';
3
3
  export type { SpaceViewParam, SpaceViewParamType, SpaceShows, SpaceMemoryPolicy, SpaceMemorySnapshot, SpaceChrome, SpaceMarkdownInput } from './space';
4
- export { threadHookInput, threadSettleInput, commentOptionInput } from './functions';
4
+ export { threadHookInput, threadIdleInput, threadSettleInput, commentOptionInput } from './functions';
5
5
  export type { SpaceFunctionDeclaration, SpaceFunctionHandler, SpaceFunctionContext } from './functions';
6
6
 
7
7
  /**
@@ -39,7 +39,7 @@ export type SpaceFunctionRole = 'public' | 'viewer' | 'editor' | 'key';
39
39
  /** Notis's built-in thread actions a function may run, only on a thread one of the Space's items is attached to. */
40
40
  export type SpaceThreadOperation = 'archive' | 'unarchive' | 'read' | 'unread' | 'star' | 'unstar' | 'later' | 'back';
41
41
  /** The built-in thread actions a Space can follow with a function (`threadHooks`). */
42
- export type SpaceThreadHookEvent = SpaceThreadOperation | 'delete';
42
+ export type SpaceThreadHookEvent = SpaceThreadOperation | 'delete' | 'idle';
43
43
 
44
44
  export interface SpaceFunctionUses {
45
45
  /** This Space's declared `actions`, run through the sealed action pipeline with the caller as the actor. */
@@ -95,6 +95,17 @@ export const threadHookInput = {
95
95
  },
96
96
  } satisfies SpaceFunctionDeclaration['input'];
97
97
 
98
+ /** Input for the idle hook after the thread finishes its current work. */
99
+ export const threadIdleInput = {
100
+ ...threadHookInput,
101
+ required: [...threadHookInput.required, 'run_id'],
102
+ properties: {
103
+ ...threadHookInput.properties,
104
+ event: { type: 'string', enum: ['idle'] },
105
+ run_id: { type: 'string' },
106
+ },
107
+ } satisfies SpaceFunctionDeclaration['input'];
108
+
98
109
  /**
99
110
  * The `input` of the function a thread item kind settles with (`threadItems.<kind>.settle`): copy it as written.
100
111
  * Notis runs it once when an item of that kind first reaches a final state, with the item and its thread.
@@ -137,13 +148,17 @@ export interface SpaceFunctionThread {
137
148
  }
138
149
  /** What a thread hook's function receives: the built-in action that just happened, and who did it. */
139
150
  export interface SpaceThreadHookInput {
140
- event: SpaceThreadHookEvent;
151
+ event: Exclude<SpaceThreadHookEvent, 'idle'>;
141
152
  /** The person, one of their agents, or Notis itself (an automatic change, or another function's thread action). */
142
153
  actor: 'person' | 'agent' | 'notis';
143
154
  thread: SpaceFunctionThread;
144
155
  /** This Space's items attached to the thread. */
145
156
  items: SpaceFunctionThreadItem[];
146
157
  }
158
+ export interface SpaceThreadIdleInput extends Omit<SpaceThreadHookInput, 'event'> {
159
+ event: 'idle';
160
+ run_id: string;
161
+ }
147
162
  /** What a thread item kind's settle function receives: the item that reached a final state, and its thread. */
148
163
  export interface SpaceThreadSettleInput {
149
164
  item: SpaceFunctionThreadItem;