subagent-extension-for-codex 0.2.0 → 0.3.0

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 (45) hide show
  1. package/README.md +5 -5
  2. package/assets/icons/arrow-up-circle.svg +14 -0
  3. package/assets/icons/check-circle.svg +14 -0
  4. package/assets/icons/file-code.svg +17 -0
  5. package/assets/icons/file-diff.svg +17 -0
  6. package/assets/icons/file-text.svg +17 -0
  7. package/assets/icons/note.svg +16 -0
  8. package/dist/THIRD_PARTY_LICENSES.txt +21 -1
  9. package/dist/app.html +644 -132
  10. package/dist/bundle/chunks/{chunk-MOWBM7MZ.js → chunk-36LESPFG.js} +1752 -196
  11. package/dist/bundle/chunks/chunk-36LESPFG.js.map +6 -0
  12. package/dist/bundle/chunks/{chunk-5TX3SEV2.js → chunk-FT2Y2DFZ.js} +137 -1
  13. package/dist/bundle/chunks/chunk-FT2Y2DFZ.js.map +6 -0
  14. package/dist/bundle/chunks/{chunk-DGCGXY3T.js → chunk-L5ILPS3O.js} +1722 -687
  15. package/dist/bundle/chunks/chunk-L5ILPS3O.js.map +6 -0
  16. package/dist/bundle/chunks/chunk-TPCNCQM7.js +970 -0
  17. package/dist/bundle/chunks/chunk-TPCNCQM7.js.map +6 -0
  18. package/dist/bundle/chunks/{v4-LDJUK5DU.js → v4-NCRHZ3K4.js} +2 -2
  19. package/dist/bundle/main.js +14481 -11021
  20. package/dist/bundle/main.js.map +3 -3
  21. package/dist/bundle/projects-cli.js +6 -3
  22. package/dist/bundle/projects-cli.js.map +1 -1
  23. package/dist/bundle/stdio.js +106 -8
  24. package/dist/bundle/stdio.js.map +2 -2
  25. package/migrations/20261107064009_claude-sdk-settings/migration.sql +39 -0
  26. package/migrations/20261107064009_claude-sdk-settings/snapshot.json +615 -0
  27. package/migrations/20261107203218_task-read-indexes/migration.sql +9 -0
  28. package/migrations/20261107203218_task-read-indexes/snapshot.json +762 -0
  29. package/migrations/20261107210532_chat-events-backfill/migration.sql +23 -0
  30. package/migrations/20261107210532_chat-events-backfill/snapshot.json +762 -0
  31. package/migrations/20261108005345_task-messages/migration.sql +9 -0
  32. package/migrations/20261108005345_task-messages/snapshot.json +841 -0
  33. package/migrations/20261108005348_task-messages-backfill/migration.sql +14 -0
  34. package/migrations/20261108005348_task-messages-backfill/snapshot.json +841 -0
  35. package/migrations/20261110025216_task-attachments/migration.sql +21 -0
  36. package/migrations/20261110025216_task-attachments/snapshot.json +1040 -0
  37. package/package.json +1 -1
  38. package/plugin.json +1 -1
  39. package/skills/delegation/SKILL.md +14 -7
  40. package/dist/bundle/chunks/chunk-5TX3SEV2.js.map +0 -6
  41. package/dist/bundle/chunks/chunk-DGCGXY3T.js.map +0 -6
  42. package/dist/bundle/chunks/chunk-MOWBM7MZ.js.map +0 -6
  43. package/dist/bundle/chunks/chunk-ZSLXLKU2.js +0 -1702
  44. package/dist/bundle/chunks/chunk-ZSLXLKU2.js.map +0 -6
  45. /package/dist/bundle/chunks/{v4-LDJUK5DU.js.map → v4-NCRHZ3K4.js.map} +0 -0
@@ -1,38 +1,71 @@
1
1
  import { createRequire as __bundleCreateRequire } from "node:module"; const require = __bundleCreateRequire(import.meta.url);
2
2
  import {
3
- external_exports
4
- } from "./chunk-5TX3SEV2.js";
3
+ external_exports,
4
+ init_define_EXTENSION_BUILD_INFO
5
+ } from "./chunk-FT2Y2DFZ.js";
5
6
 
6
7
  // src/service/platform/logging/logger.ts
8
+ init_define_EXTENSION_BUILD_INFO();
7
9
  import { AsyncLocalStorage } from "node:async_hooks";
8
10
  import { randomUUID } from "node:crypto";
9
11
  import { homedir } from "node:os";
10
12
 
11
13
  // src/service/platform/logging/error-metadata.ts
14
+ init_define_EXTENSION_BUILD_INFO();
15
+
16
+ // src/shared/tasks/failure.ts
17
+ init_define_EXTENSION_BUILD_INFO();
18
+ var FAILURE_MESSAGES = /* @__PURE__ */ new Map([
19
+ ["cost_budget_exhausted", "Cost limit reached."],
20
+ ["runtime_budget_exhausted", "Runtime limit reached."],
21
+ ["error_max_turns", "Claude stopped at its turn limit."],
22
+ [
23
+ "error_max_structured_output_retries",
24
+ "Claude couldn't produce the structured reply it was asked for."
25
+ ],
26
+ ["error_during_execution", "Claude stopped because of an error."]
27
+ ]);
28
+ function isBudgetFailure(code) {
29
+ return code === "cost_budget_exhausted" || code === "runtime_budget_exhausted";
30
+ }
31
+ function failureMessage({
32
+ error_code,
33
+ error
34
+ }) {
35
+ const summary2 = error_code ? FAILURE_MESSAGES.get(error_code) ?? `Unexpected error: ${error_code}.` : void 0;
36
+ return [summary2, error].filter(Boolean).join(" ") || void 0;
37
+ }
38
+
39
+ // src/service/platform/logging/error-metadata.ts
40
+ var PolicyRejectedError = class extends Error {
41
+ name = "PolicyRejectedError";
42
+ };
12
43
  function errorCategory(error) {
13
44
  if (!(error instanceof Error)) return "unknown";
14
- const message = error.message.toLowerCase();
45
+ if (error instanceof PolicyRejectedError) return "policy";
46
+ if ("code" in error && isBudgetFailure(error.code)) return "budget";
47
+ const message2 = error.message.toLowerCase();
15
48
  const status = "status" in error ? error.status : void 0;
16
49
  if (status === 401 || status === 403 || /unauthorized|authentication|invalid.*(?:token|api.?key)|missing.*(?:token|api.?key)|not logged in/.test(
17
- message
50
+ message2
18
51
  )) {
19
52
  return "authentication";
20
53
  }
21
- if (status === 429 || /rate.?limit|too many requests/.test(message)) {
54
+ if (status === 429 || /rate.?limit|too many requests/.test(message2)) {
22
55
  return "rate_limit";
23
56
  }
24
57
  if (error.name === "AbortError") return "aborted";
25
- if (error.name === "TimeoutError" || /timed? ?out|timeout/.test(message)) {
58
+ if (error.name === "TimeoutError" || /timed? ?out|timeout/.test(message2)) {
26
59
  return "timeout";
27
60
  }
28
- if (/econnrefused|econnreset|enotfound|fetch failed|network/.test(message)) {
61
+ if (/econnrefused|econnreset|enotfound|fetch failed|network/.test(message2)) {
29
62
  return "connection";
30
63
  }
31
- if (/budget.*exhausted|maximum.*budget/.test(message)) return "budget";
32
64
  return "unknown";
33
65
  }
34
66
 
35
67
  // src/service/platform/logging/jsonl-writer.ts
68
+ init_define_EXTENSION_BUILD_INFO();
36
69
  import { appendFile, chmod, rename, stat } from "node:fs/promises";
37
70
  var JsonlWriter = class {
38
71
  constructor(path, options = {}) {
@@ -225,6 +258,7 @@ function flushLogs() {
225
258
  }
226
259
 
227
260
  // src/service/platform/service/runtime.ts
261
+ init_define_EXTENSION_BUILD_INFO();
228
262
  import { readFileSync } from "node:fs";
229
263
  import { homedir as homedir2 } from "node:os";
230
264
  import { dirname, join, resolve } from "node:path";
@@ -278,26 +312,24 @@ function databasePath(data) {
278
312
  }
279
313
 
280
314
  // src/service/features/workspaces/workspace.ts
281
- import {
282
- access,
283
- copyFile,
284
- mkdir,
285
- mkdtemp,
286
- opendir,
287
- realpath as realpath2,
288
- rm,
289
- stat as stat2,
290
- utimes
291
- } from "node:fs/promises";
292
- import { isAbsolute, join as join2, relative, resolve as resolve2, sep } from "node:path";
315
+ init_define_EXTENSION_BUILD_INFO();
316
+ import { access, mkdir, opendir, realpath as realpath4, stat as stat2 } from "node:fs/promises";
317
+ import { isAbsolute, join as join4, relative, sep as sep2 } from "node:path";
293
318
 
294
319
  // src/service/features/workspaces/git.ts
320
+ init_define_EXTENSION_BUILD_INFO();
295
321
  import { execFile } from "node:child_process";
296
322
  import { realpath } from "node:fs/promises";
297
323
  import { promisify } from "node:util";
298
324
  var exec = promisify(execFile);
325
+ var SAFE_CONFIG = [
326
+ "-c",
327
+ "core.hooksPath=/dev/null",
328
+ "-c",
329
+ "core.fsmonitor=false"
330
+ ];
299
331
  async function git(cwd, args, env, input, timeoutMs) {
300
- const run = exec("git", ["-C", cwd, ...args], {
332
+ const run = exec("git", [...SAFE_CONFIG, "-C", cwd, ...args], {
301
333
  // Diffs are returned whole, however large.
302
334
  maxBuffer: 1024 * 1024 * 1024,
303
335
  ...timeoutMs ? { timeout: timeoutMs, killSignal: "SIGKILL" } : {},
@@ -312,6 +344,18 @@ async function git(cwd, args, env, input, timeoutMs) {
312
344
  if (stdinError) throw stdinError;
313
345
  return stdout;
314
346
  }
347
+ async function gitBytes(cwd, args, maxBytes, timeoutMs) {
348
+ const run = exec("git", [...SAFE_CONFIG, "-C", cwd, ...args], {
349
+ encoding: "buffer",
350
+ maxBuffer: maxBytes,
351
+ timeout: timeoutMs,
352
+ killSignal: "SIGKILL",
353
+ // Optional locks would let a read refresh the user's index.
354
+ env: { ...process.env, LC_ALL: "C", GIT_OPTIONAL_LOCKS: "0" }
355
+ });
356
+ run.child.stdin?.end();
357
+ return (await run).stdout;
358
+ }
315
359
  var ROOT_PROBE_TIMEOUT_MS = 5e3;
316
360
  async function gitRepositoryRoot(cwd) {
317
361
  try {
@@ -362,6 +406,138 @@ async function gitState(cwd) {
362
406
  }
363
407
  }
364
408
 
409
+ // src/service/features/workspaces/workspace-deletion.ts
410
+ init_define_EXTENSION_BUILD_INFO();
411
+ import { createHash } from "node:crypto";
412
+ import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
413
+ import { dirname as dirname2, join as join3, resolve as resolve3 } from "node:path";
414
+
415
+ // src/service/platform/filesystem/path-symlinks.ts
416
+ init_define_EXTENSION_BUILD_INFO();
417
+ import { lstat, realpath as realpath2 } from "node:fs/promises";
418
+ import { join as join2, parse, resolve as resolve2, sep } from "node:path";
419
+ async function pathSymlinks(path) {
420
+ const absolute = resolve2(path);
421
+ const root = parse(absolute).root;
422
+ const links = [];
423
+ let current = root;
424
+ for (const part of absolute.slice(root.length).split(sep)) {
425
+ current = join2(current, part);
426
+ let entry;
427
+ try {
428
+ entry = await lstat(current);
429
+ } catch (error) {
430
+ if (error.code === "ENOENT") break;
431
+ throw error;
432
+ }
433
+ if (entry.isSymbolicLink()) {
434
+ links.push({ path: current, target: await realpath2(current) });
435
+ }
436
+ }
437
+ return links;
438
+ }
439
+
440
+ // src/service/features/workspaces/workspace-deletion.ts
441
+ async function workspaceDeletion(task, managedRoot) {
442
+ if (task.workspace_strategy !== "worktree" || !task.workspace && !task.branch) {
443
+ return { version: "none" };
444
+ }
445
+ const root = resolve3(managedRoot);
446
+ const expectedPath = resolve3(root, task.id);
447
+ if (!task.workspace || !task.branch || dirname2(expectedPath) !== root || resolve3(task.workspace) !== expectedPath) {
448
+ const retained = retainedWorktree(task);
449
+ return { retained, version: JSON.stringify(retained) };
450
+ }
451
+ const entry = await worktreeEntry(task.workspace);
452
+ const repository = await realpath3(task.repository);
453
+ const repositoryIdentity = await lstat2(repository);
454
+ const repositoryCommon = await commonDirectory(repository);
455
+ const commonIdentity = await lstat2(repositoryCommon);
456
+ let worktree;
457
+ if (entry) {
458
+ if (!entry.isDirectory() || task.workspace_removed) {
459
+ throw new Error(
460
+ "The task's worktree was replaced or linked. It cannot be deleted safely."
461
+ );
462
+ }
463
+ const actual = await realpath3(task.workspace);
464
+ if (actual !== join3(await realpath3(root), task.id) || await gitRepositoryRoot(actual) !== actual) {
465
+ throw new Error("The task's worktree location changed.");
466
+ }
467
+ const [branch, common] = await Promise.all([
468
+ git(actual, ["symbolic-ref", "--quiet", "HEAD"]),
469
+ commonDirectory(actual)
470
+ ]);
471
+ if (branch.trim() !== `refs/heads/${task.branch}` || common !== repositoryCommon) {
472
+ throw new Error(
473
+ "The worktree now belongs to a different branch or repository."
474
+ );
475
+ }
476
+ worktree = actual;
477
+ }
478
+ const tip = await branchTip(task.repository, task.branch);
479
+ const worktreeSymlinks = await pathSymlinks(task.workspace);
480
+ if (tip && task.branch_deleted) {
481
+ throw new Error(
482
+ "The task's deleted branch was recreated. It will be kept."
483
+ );
484
+ }
485
+ return {
486
+ worktree,
487
+ worktreeSymlinks,
488
+ branch: tip ? task.branch : void 0,
489
+ branchTip: tip,
490
+ version: createHash("sha256").update(
491
+ JSON.stringify([
492
+ repository,
493
+ repositoryIdentity.dev,
494
+ repositoryIdentity.ino,
495
+ repositoryCommon,
496
+ commonIdentity.dev,
497
+ commonIdentity.ino,
498
+ expectedPath,
499
+ entry?.dev,
500
+ entry?.ino,
501
+ task.branch,
502
+ tip,
503
+ worktreeSymlinks
504
+ ])
505
+ ).digest("hex")
506
+ };
507
+ }
508
+ function retainedWorktree(task) {
509
+ return {
510
+ ...!task.workspace_removed ? { worktree: task.workspace } : {},
511
+ ...!task.branch_deleted ? { branch: task.branch } : {}
512
+ };
513
+ }
514
+ async function branchTip(repository, branch) {
515
+ return git(repository, [
516
+ "rev-parse",
517
+ "--verify",
518
+ "--quiet",
519
+ `refs/heads/${branch}`
520
+ ]).then(
521
+ (value) => value.trim(),
522
+ (error) => {
523
+ if (error.code === 1) return void 0;
524
+ throw error;
525
+ }
526
+ );
527
+ }
528
+ async function commonDirectory(path) {
529
+ const common = (await git(path, ["rev-parse", "--git-common-dir"])).trim();
530
+ return realpath3(resolve3(path, common));
531
+ }
532
+ async function worktreeEntry(path) {
533
+ try {
534
+ return await lstat2(path);
535
+ } catch (error) {
536
+ if (error.code === "ENOENT") return void 0;
537
+ throw error;
538
+ }
539
+ }
540
+
365
541
  // src/service/features/workspaces/workspace.ts
366
542
  var exists = (path) => access(path).then(
367
543
  () => true,
@@ -369,11 +545,11 @@ var exists = (path) => access(path).then(
369
545
  );
370
546
  var within = (parent, path) => {
371
547
  const child = relative(parent, path);
372
- return child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
548
+ return child !== ".." && !child.startsWith(`..${sep2}`) && !isAbsolute(child);
373
549
  };
374
550
  async function accessibleRealpath(path) {
375
551
  try {
376
- const actual = await realpath2(path);
552
+ const actual = await realpath4(path);
377
553
  if ((await stat2(actual)).isDirectory()) {
378
554
  await (await opendir(actual)).close();
379
555
  }
@@ -392,7 +568,7 @@ async function accessibleRealpath(path) {
392
568
  var realRoots = (roots) => Promise.all(
393
569
  roots.map(async (root) => {
394
570
  try {
395
- return await realpath2(root);
571
+ return await realpath4(root);
396
572
  } catch (error) {
397
573
  const code = error.code;
398
574
  if (code === "ENOENT" || code === "ENOTDIR" || code === "EPERM" || code === "EACCES") {
@@ -412,73 +588,6 @@ var Workspaces = class {
412
588
  root;
413
589
  allowedRoots;
414
590
  exactRoots;
415
- /**
416
- * Records a checkout's files, as `git add -A` would stage them, as a tree
417
- * id. A temporary index in the extension's directory keeps the checkout's
418
- * own index and files untouched. `.gitignore` applies. New content is
419
- * written to the object store as unreferenced blobs, which `git gc` prunes
420
- * after its grace period.
421
- */
422
- async snapshot(cwd) {
423
- await mkdir(this.root, { recursive: true, mode: 448 });
424
- const dir = await mkdtemp(join2(this.root, ".snapshot-"));
425
- const index2 = join2(dir, "index");
426
- const run = (args, input) => git(
427
- cwd,
428
- [
429
- "-c",
430
- "core.splitIndex=false",
431
- "-c",
432
- "core.fsmonitor=false",
433
- // Otherwise Git would trust every cached entry, as assume-unchanged.
434
- "-c",
435
- "core.ignoreStat=false",
436
- ...args
437
- ],
438
- { GIT_INDEX_FILE: index2 },
439
- input
440
- );
441
- try {
442
- if (await this.copyIndex(cwd, index2)) {
443
- try {
444
- const assumed = (await run(["ls-files", "-v", "-z"])).split("\0").filter((entry) => /^[a-z] /.test(entry)).map((entry) => entry.slice(2));
445
- if (assumed.length) {
446
- await run(
447
- ["update-index", "--no-assume-unchanged", "-z", "--stdin"],
448
- assumed.join("\0")
449
- );
450
- }
451
- await run(["add", "-A"]);
452
- return (await run(["write-tree"])).trim();
453
- } catch {
454
- await rm(index2, { force: true });
455
- }
456
- }
457
- await run(["read-tree", "HEAD"]);
458
- await run(["add", "-A"]);
459
- return (await run(["write-tree"])).trim();
460
- } finally {
461
- await rm(dir, { recursive: true, force: true });
462
- }
463
- }
464
- /**
465
- * Copies a checkout's index to `target`; false when it has none. Git
466
- * replaces the index by renaming a finished file, so a copy is never torn.
467
- */
468
- async copyIndex(cwd, target) {
469
- const path = resolve2(
470
- cwd,
471
- (await git(cwd, ["rev-parse", "--git-path", "index"])).trim()
472
- );
473
- try {
474
- const { atime, mtime } = await stat2(path);
475
- await copyFile(path, target);
476
- await utimes(target, atime, mtime);
477
- return true;
478
- } catch {
479
- return false;
480
- }
481
- }
482
591
  async repository(path) {
483
592
  const actual = await accessibleRealpath(path);
484
593
  const roots = await realRoots(this.allowedRoots);
@@ -517,7 +626,7 @@ var Workspaces = class {
517
626
  throw new Error(`Invalid worktree branch name: ${branchPrefix}${t.id}`);
518
627
  })).trim();
519
628
  await mkdir(this.root, { recursive: true, mode: 448 });
520
- const workspace = join2(this.root, t.id);
629
+ const workspace = join4(this.root, t.id);
521
630
  await git(t.repository, [
522
631
  "worktree",
523
632
  "add",
@@ -540,6 +649,7 @@ var Workspaces = class {
540
649
  if (!await exists(t.workspace)) {
541
650
  throw new Error("The worktree was already removed.");
542
651
  }
652
+ const resources = await this.managedDeletion(t);
543
653
  if (!force) {
544
654
  const entries = (await git(t.workspace, ["status", "--porcelain", "-z"])).split("\0"), files = [];
545
655
  for (let index2 = 0; index2 < entries.length; index2++) {
@@ -554,13 +664,12 @@ var Workspaces = class {
554
664
  "worktree",
555
665
  "remove",
556
666
  ...force ? ["--force"] : [],
557
- t.workspace
667
+ resources.worktree
558
668
  ]);
559
669
  return { status: "removed" };
560
670
  }
561
671
  /**
562
- * Deletes a worktree task's branch, once its worktree is removed, and its
563
- * snapshot refs, since nothing reads its changes after that.
672
+ * Deletes a worktree task's branch once its worktree is removed.
564
673
  */
565
674
  async deleteBranch(t) {
566
675
  if (t.workspace_strategy !== "worktree" || !t.workspace || !t.branch) {
@@ -569,23 +678,58 @@ var Workspaces = class {
569
678
  if (await exists(t.workspace)) {
570
679
  throw new Error("Remove the worktree before deleting its branch.");
571
680
  }
681
+ await this.managedDeletion(t);
572
682
  await git(t.repository, ["branch", "-D", "--end-of-options", t.branch]);
573
683
  }
574
684
  /**
575
- * Removes everything a task left in its repository: a worktree task's
576
- * worktree, uncommitted changes included, its branch and its snapshot refs.
577
- * A current_repo task's checkout is the user's own and stays as it is.
685
+ * Removes the task's worktree, including uncommitted files, and its branch.
686
+ * A current_repo task's checkout stays as it is.
578
687
  */
579
- async discard(t) {
580
- if (t.workspace_strategy === "worktree" && t.workspace) {
581
- if (await exists(t.workspace)) {
582
- await git(t.repository, ["worktree", "remove", "--force", t.workspace]);
688
+ async discard(t, expectedVersion) {
689
+ const resources = await this.deletion(t);
690
+ if (expectedVersion && expectedVersion !== resources.version) {
691
+ throw new Error(
692
+ "Worktree or branch changed. Review the deletion details again."
693
+ );
694
+ }
695
+ if (resources.worktree) {
696
+ await git(t.repository, [
697
+ "worktree",
698
+ "remove",
699
+ "--force",
700
+ resources.worktree
701
+ ]);
702
+ }
703
+ if (resources.branch) {
704
+ const tip = await branchTip(t.repository, resources.branch);
705
+ if (tip && tip !== resources.branchTip) {
706
+ throw new Error(
707
+ "The branch changed during cleanup. Review the deletion details again."
708
+ );
583
709
  }
584
- if (t.branch && await this.branchExists(t)) {
585
- await git(t.repository, ["branch", "-D", "--end-of-options", t.branch]);
710
+ if (tip) {
711
+ await git(t.repository, [
712
+ "branch",
713
+ "-D",
714
+ "--end-of-options",
715
+ resources.branch
716
+ ]);
586
717
  }
587
718
  }
588
719
  }
720
+ deletion(t) {
721
+ return workspaceDeletion(t, this.root);
722
+ }
723
+ /** Worktree actions only change a worktree inside the managed folder. */
724
+ async managedDeletion(t) {
725
+ const resources = await this.deletion(t);
726
+ if (resources.retained) {
727
+ throw new Error(
728
+ "The recorded worktree is outside this task's managed location."
729
+ );
730
+ }
731
+ return resources;
732
+ }
589
733
  /** Whether a worktree task's worktree is gone, so its next turn recreates it. */
590
734
  async worktreeMissing(t) {
591
735
  return t.workspace_strategy === "worktree" && !!t.workspace && !await exists(t.workspace);
@@ -627,19 +771,20 @@ var Workspaces = class {
627
771
  () => false
628
772
  );
629
773
  }
630
- /** The diff between two trees or commits, as one text. */
631
- async diff(cwd, from, to) {
632
- return git(cwd, ["diff", "--no-ext-diff", "--no-color", from, to, "--"]);
633
- }
634
774
  };
635
775
 
636
776
  // src/service/features/projects/projects.ts
777
+ init_define_EXTENSION_BUILD_INFO();
637
778
  import { realpathSync } from "node:fs";
638
- import { realpath as realpath3, stat as stat3 } from "node:fs/promises";
779
+ import { realpath as realpath5, stat as stat3 } from "node:fs/promises";
639
780
  import { homedir as homedir3 } from "node:os";
640
- import { basename, dirname as dirname2, isAbsolute as isAbsolute2 } from "node:path";
781
+ import { basename, dirname as dirname3, isAbsolute as isAbsolute2 } from "node:path";
782
+
783
+ // node_modules/drizzle-orm/index.js
784
+ init_define_EXTENSION_BUILD_INFO();
641
785
 
642
786
  // node_modules/drizzle-orm/entity.js
787
+ init_define_EXTENSION_BUILD_INFO();
643
788
  var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
644
789
  var kindsByConstructor = /* @__PURE__ */ new WeakMap();
645
790
  function collectKinds(ctor) {
@@ -663,14 +808,18 @@ function entityKindsOf(value) {
663
808
  return kindsByConstructor.get(ctor) ?? collectKinds(ctor);
664
809
  }
665
810
 
811
+ // node_modules/drizzle-orm/table.utils.js
812
+ init_define_EXTENSION_BUILD_INFO();
813
+
666
814
  // node_modules/drizzle-orm/errors.js
815
+ init_define_EXTENSION_BUILD_INFO();
667
816
  var DrizzleError = class extends Error {
668
817
  static [entityKind] = "DrizzleError";
669
818
  static [Symbol.hasInstance](value) {
670
819
  return is(value, this);
671
820
  }
672
- constructor({ message, cause }) {
673
- super(message);
821
+ constructor({ message: message2, cause }) {
822
+ super(message2);
674
823
  this.name = "DrizzleError";
675
824
  this.cause = cause;
676
825
  }
@@ -715,6 +864,7 @@ var Qualifier = /* @__PURE__ */ Symbol.for("drizzle:Qualifier");
715
864
  var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
716
865
 
717
866
  // node_modules/drizzle-orm/table.js
867
+ init_define_EXTENSION_BUILD_INFO();
718
868
  var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
719
869
  var Table = class {
720
870
  static [entityKind] = "Table";
@@ -780,7 +930,11 @@ function getTableName(table) {
780
930
  return table[TableName];
781
931
  }
782
932
 
933
+ // node_modules/drizzle-orm/column.js
934
+ init_define_EXTENSION_BUILD_INFO();
935
+
783
936
  // node_modules/drizzle-orm/column-common.js
937
+ init_define_EXTENSION_BUILD_INFO();
784
938
  var OriginalColumn = /* @__PURE__ */ Symbol.for("drizzle:OriginalColumn");
785
939
 
786
940
  // node_modules/drizzle-orm/column.js
@@ -862,6 +1016,7 @@ function getColumnTable(column) {
862
1016
  }
863
1017
 
864
1018
  // node_modules/drizzle-orm/sql/common-chunks.js
1019
+ init_define_EXTENSION_BUILD_INFO();
865
1020
  var StringChunk = class {
866
1021
  value;
867
1022
  static [entityKind] = "StringChunk";
@@ -926,7 +1081,14 @@ var commonStringChunks = {
926
1081
  "first(": new StringChunk("first(")
927
1082
  };
928
1083
 
1084
+ // node_modules/drizzle-orm/sql/sql.js
1085
+ init_define_EXTENSION_BUILD_INFO();
1086
+
1087
+ // node_modules/drizzle-orm/view.js
1088
+ init_define_EXTENSION_BUILD_INFO();
1089
+
929
1090
  // node_modules/drizzle-orm/view-common.js
1091
+ init_define_EXTENSION_BUILD_INFO();
930
1092
  var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");
931
1093
 
932
1094
  // node_modules/drizzle-orm/view.js
@@ -977,6 +1139,7 @@ function isView(view) {
977
1139
  }
978
1140
 
979
1141
  // node_modules/drizzle-orm/subquery.js
1142
+ init_define_EXTENSION_BUILD_INFO();
980
1143
  var Subquery = class {
981
1144
  static [entityKind] = "Subquery";
982
1145
  static [Symbol.hasInstance](value) {
@@ -1001,12 +1164,12 @@ var Subquery = class {
1001
1164
  get [TableColumns]() {
1002
1165
  return this._.selectedFields;
1003
1166
  }
1004
- constructor(sql2, fields, alias, isWith = false) {
1167
+ constructor(sql2, fields, alias2, isWith = false) {
1005
1168
  this._ = {
1006
1169
  brand: "Subquery",
1007
1170
  sql: sql2,
1008
1171
  selectedFields: fields,
1009
- alias,
1172
+ alias: alias2,
1010
1173
  isWith
1011
1174
  };
1012
1175
  }
@@ -1016,6 +1179,7 @@ var WithSubquery = class extends Subquery {
1016
1179
  };
1017
1180
 
1018
1181
  // node_modules/drizzle-orm/tracing.js
1182
+ init_define_EXTENSION_BUILD_INFO();
1019
1183
  var hasTelemetry = false;
1020
1184
  var tracer = { startActiveSpan(name2, fn) {
1021
1185
  return fn();
@@ -1268,9 +1432,9 @@ var SQL = class SQL2 {
1268
1432
  getSQL() {
1269
1433
  return this;
1270
1434
  }
1271
- as(alias) {
1272
- if (alias === void 0) return this;
1273
- return new SQL2.Aliased(this, alias);
1435
+ as(alias2) {
1436
+ if (alias2 === void 0) return this;
1437
+ return new SQL2.Aliased(this, alias2);
1274
1438
  }
1275
1439
  mapWith(decoder) {
1276
1440
  this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
@@ -1426,7 +1590,7 @@ function sql(strings, ...params) {
1426
1590
  return new SQL([new StringChunk(str)]);
1427
1591
  }
1428
1592
  _sql.raw = raw;
1429
- function join3(chunks, separator) {
1593
+ function join5(chunks, separator) {
1430
1594
  const { length } = chunks;
1431
1595
  if (separator === void 0 || length === 0) return new SQL(chunks.slice());
1432
1596
  const result = new Array(length * 2 - 1);
@@ -1436,7 +1600,7 @@ function sql(strings, ...params) {
1436
1600
  }
1437
1601
  return new SQL(result);
1438
1602
  }
1439
- _sql.join = join3;
1603
+ _sql.join = join5;
1440
1604
  function identifier(value) {
1441
1605
  return new Name(value);
1442
1606
  }
@@ -1646,6 +1810,7 @@ defineQualifier(View.prototype, (view) => qualifiedName(view[ViewBaseConfig].sch
1646
1810
  defineQualifier(Subquery.prototype, (subquery) => new Name(subquery._.alias));
1647
1811
 
1648
1812
  // node_modules/drizzle-orm/utils.js
1813
+ init_define_EXTENSION_BUILD_INFO();
1649
1814
  function resolveNullableObjectPaths(columns, joinsNotNullableMap) {
1650
1815
  if (!joinsNotNullableMap) return void 0;
1651
1816
  const tableOf = /* @__PURE__ */ new Map();
@@ -1998,6 +2163,7 @@ var CONSTANTS = {
1998
2163
  };
1999
2164
 
2000
2165
  // node_modules/drizzle-orm/alias.js
2166
+ init_define_EXTENSION_BUILD_INFO();
2001
2167
  var ColumnTableAliasProxyHandler = class {
2002
2168
  table;
2003
2169
  ignoreColumnAlias;
@@ -2052,8 +2218,8 @@ var TableAliasProxyHandler = class {
2052
2218
  static [Symbol.hasInstance](value) {
2053
2219
  return is(value, this);
2054
2220
  }
2055
- constructor(alias, replaceOriginalName, ignoreColumnAlias) {
2056
- this.alias = alias;
2221
+ constructor(alias2, replaceOriginalName, ignoreColumnAlias) {
2222
+ this.alias = alias2;
2057
2223
  this.replaceOriginalName = replaceOriginalName;
2058
2224
  this.ignoreColumnAlias = ignoreColumnAlias;
2059
2225
  }
@@ -2120,9 +2286,9 @@ var SubquerySelectionAliasProxyHandler = class {
2120
2286
  static [Symbol.hasInstance](value) {
2121
2287
  return is(value, this);
2122
2288
  }
2123
- constructor(subquery, alias) {
2289
+ constructor(subquery, alias2) {
2124
2290
  this.subquery = subquery;
2125
- this.alias = alias;
2291
+ this.alias = alias2;
2126
2292
  }
2127
2293
  memo;
2128
2294
  columnHandler;
@@ -2149,8 +2315,8 @@ var SubqueryAliasProxyHandler = class {
2149
2315
  static [Symbol.hasInstance](value) {
2150
2316
  return is(value, this);
2151
2317
  }
2152
- constructor(alias) {
2153
- this.alias = alias;
2318
+ constructor(alias2) {
2319
+ this.alias = alias2;
2154
2320
  }
2155
2321
  /** Alias as identifier, replaces `[Qualifier]` of subqueries */
2156
2322
  qualifier;
@@ -2181,8 +2347,8 @@ var ColumnAliasProxyHandler = class {
2181
2347
  static [Symbol.hasInstance](value) {
2182
2348
  return is(value, this);
2183
2349
  }
2184
- constructor(alias) {
2185
- this.alias = alias;
2350
+ constructor(alias2) {
2351
+ this.alias = alias2;
2186
2352
  }
2187
2353
  get(target, prop) {
2188
2354
  if (prop === "isAlias") return true;
@@ -2198,8 +2364,8 @@ var RelationTableAliasProxyHandler = class {
2198
2364
  static [Symbol.hasInstance](value) {
2199
2365
  return is(value, this);
2200
2366
  }
2201
- constructor(alias) {
2202
- this.alias = alias;
2367
+ constructor(alias2) {
2368
+ this.alias = alias2;
2203
2369
  }
2204
2370
  get(target, prop) {
2205
2371
  if (prop === "sourceTable") return aliasedTable(target.sourceTable, this.alias);
@@ -2214,17 +2380,18 @@ function aliasedTableSQL(table) {
2214
2380
  const name2 = sql.identifier(table[Table.Symbol.OriginalName]);
2215
2381
  return schema ? sql`${sql.identifier(schema)}.${name2} ${table}` : sql`${name2} ${table}`;
2216
2382
  }
2217
- function aliasedColumn(column, alias) {
2218
- return new Proxy(column, new ColumnAliasProxyHandler(alias));
2383
+ function aliasedColumn(column, alias2) {
2384
+ return new Proxy(column, new ColumnAliasProxyHandler(alias2));
2219
2385
  }
2220
- Column.prototype.as = function(alias) {
2221
- return aliasedColumn(this, alias);
2386
+ Column.prototype.as = function(alias2) {
2387
+ return aliasedColumn(this, alias2);
2222
2388
  };
2223
2389
  function getOriginalColumnFromAlias(column) {
2224
2390
  return column[OriginalColumn]();
2225
2391
  }
2226
2392
 
2227
2393
  // node_modules/drizzle-orm/column-builder.js
2394
+ init_define_EXTENSION_BUILD_INFO();
2228
2395
  function extractExtendedColumnType(column) {
2229
2396
  const [type, constraint] = column.dataType.split(" ");
2230
2397
  return {
@@ -2343,13 +2510,14 @@ var ColumnBuilder = class {
2343
2510
  };
2344
2511
 
2345
2512
  // node_modules/drizzle-orm/logger.js
2513
+ init_define_EXTENSION_BUILD_INFO();
2346
2514
  var ConsoleLogWriter = class {
2347
2515
  static [entityKind] = "ConsoleLogWriter";
2348
2516
  static [Symbol.hasInstance](value) {
2349
2517
  return is(value, this);
2350
2518
  }
2351
- write(message) {
2352
- console.log(message);
2519
+ write(message2) {
2520
+ console.log(message2);
2353
2521
  }
2354
2522
  };
2355
2523
  var DefaultLogger = class {
@@ -2383,6 +2551,7 @@ var NoopLogger = class {
2383
2551
  };
2384
2552
 
2385
2553
  // node_modules/drizzle-orm/query-promise.js
2554
+ init_define_EXTENSION_BUILD_INFO();
2386
2555
  var QueryPromise = class {
2387
2556
  static [entityKind] = "QueryPromise";
2388
2557
  static [Symbol.hasInstance](value) {
@@ -2407,6 +2576,7 @@ var QueryPromise = class {
2407
2576
  };
2408
2577
 
2409
2578
  // node_modules/drizzle-orm/sql/expressions/conditions.js
2579
+ init_define_EXTENSION_BUILD_INFO();
2410
2580
  function bindIfParam(value, column) {
2411
2581
  if (isDriverValueEncoder(column) && !isSQLWrapper(value)) {
2412
2582
  const kind = chunkKindOf(value);
@@ -2533,6 +2703,7 @@ function arrayOverlaps(column, values) {
2533
2703
  }
2534
2704
 
2535
2705
  // node_modules/drizzle-orm/sql/expressions/select.js
2706
+ init_define_EXTENSION_BUILD_INFO();
2536
2707
  function asc(column) {
2537
2708
  return sql`${column} asc`;
2538
2709
  }
@@ -2541,6 +2712,7 @@ function desc(column) {
2541
2712
  }
2542
2713
 
2543
2714
  // node_modules/drizzle-orm/relations.js
2715
+ init_define_EXTENSION_BUILD_INFO();
2544
2716
  var Relation = class {
2545
2717
  targetTableName;
2546
2718
  static [entityKind] = "RelationV2";
@@ -3626,11 +3798,25 @@ function getTableAsAliasSQL(table, collectTo = []) {
3626
3798
  var EmptyFilter = /* @__PURE__ */ Symbol.for("drizzle:EmptyFilter");
3627
3799
 
3628
3800
  // node_modules/drizzle-orm/sql/functions/aggregate.js
3801
+ init_define_EXTENSION_BUILD_INFO();
3802
+ function count(expression) {
3803
+ return sql`count(${expression || sql.raw("*")})`.mapWith(Number);
3804
+ }
3629
3805
  function max(expression) {
3630
3806
  return sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String);
3631
3807
  }
3632
3808
 
3809
+ // src/service/features/projects/schema.ts
3810
+ init_define_EXTENSION_BUILD_INFO();
3811
+
3812
+ // node_modules/drizzle-orm/sqlite-core/index.js
3813
+ init_define_EXTENSION_BUILD_INFO();
3814
+
3815
+ // node_modules/drizzle-orm/sqlite-core/columns/common.js
3816
+ init_define_EXTENSION_BUILD_INFO();
3817
+
3633
3818
  // node_modules/drizzle-orm/sqlite-core/foreign-keys.js
3819
+ init_define_EXTENSION_BUILD_INFO();
3634
3820
  var ForeignKeyBuilder = class {
3635
3821
  static [entityKind] = "SQLiteForeignKeyBuilder";
3636
3822
  static [Symbol.hasInstance](value) {
@@ -3754,7 +3940,14 @@ var SQLiteColumn = class extends Column {
3754
3940
  }
3755
3941
  };
3756
3942
 
3943
+ // node_modules/drizzle-orm/sqlite-core/columns/blob.js
3944
+ init_define_EXTENSION_BUILD_INFO();
3945
+
3946
+ // node_modules/drizzle-orm/sqlite-core/codecs.js
3947
+ init_define_EXTENSION_BUILD_INFO();
3948
+
3757
3949
  // node_modules/drizzle-orm/codecs.js
3950
+ init_define_EXTENSION_BUILD_INFO();
3758
3951
  var noopCodecs = {};
3759
3952
  var noCodecs = {
3760
3953
  cast: void 0,
@@ -4190,6 +4383,7 @@ function blob(a, b) {
4190
4383
  }
4191
4384
 
4192
4385
  // node_modules/drizzle-orm/sqlite-core/columns/custom.js
4386
+ init_define_EXTENSION_BUILD_INFO();
4193
4387
  var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
4194
4388
  static [entityKind] = "SQLiteCustomColumnBuilder";
4195
4389
  constructor(name2, fieldConfig, customTypeParams) {
@@ -4231,6 +4425,7 @@ function customType(customTypeParams) {
4231
4425
  }
4232
4426
 
4233
4427
  // node_modules/drizzle-orm/sqlite-core/columns/integer.js
4428
+ init_define_EXTENSION_BUILD_INFO();
4234
4429
  var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
4235
4430
  static [entityKind] = "SQLiteBaseIntegerBuilder";
4236
4431
  constructor(name2, dataType, columnType) {
@@ -4321,6 +4516,7 @@ function integer(a, b) {
4321
4516
  }
4322
4517
 
4323
4518
  // node_modules/drizzle-orm/sqlite-core/columns/numeric.js
4519
+ init_define_EXTENSION_BUILD_INFO();
4324
4520
  var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
4325
4521
  static [entityKind] = "SQLiteNumericBuilder";
4326
4522
  constructor(name2) {
@@ -4384,6 +4580,7 @@ function numeric(a, b) {
4384
4580
  }
4385
4581
 
4386
4582
  // node_modules/drizzle-orm/sqlite-core/columns/real.js
4583
+ init_define_EXTENSION_BUILD_INFO();
4387
4584
  var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
4388
4585
  static [entityKind] = "SQLiteRealBuilder";
4389
4586
  constructor(name2) {
@@ -4407,6 +4604,7 @@ function real(name2) {
4407
4604
  }
4408
4605
 
4409
4606
  // node_modules/drizzle-orm/sqlite-core/columns/text.js
4607
+ init_define_EXTENSION_BUILD_INFO();
4410
4608
  var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
4411
4609
  static [entityKind] = "SQLiteTextBuilder";
4412
4610
  constructor(name2, config) {
@@ -4458,7 +4656,11 @@ function text(a, b = {}) {
4458
4656
  return new SQLiteTextBuilder(name2, config);
4459
4657
  }
4460
4658
 
4659
+ // node_modules/drizzle-orm/sqlite-core/table.js
4660
+ init_define_EXTENSION_BUILD_INFO();
4661
+
4461
4662
  // node_modules/drizzle-orm/sqlite-core/columns/all.js
4663
+ init_define_EXTENSION_BUILD_INFO();
4462
4664
  function getSQLiteColumnBuilders() {
4463
4665
  return {
4464
4666
  blob,
@@ -4471,6 +4673,7 @@ function getSQLiteColumnBuilders() {
4471
4673
  }
4472
4674
 
4473
4675
  // node_modules/drizzle-orm/casing.js
4676
+ init_define_EXTENSION_BUILD_INFO();
4474
4677
  function toSnakeCase(input) {
4475
4678
  return (input.replace(/['\u2019]/g, "").match(/[\d\p{Ll}\p{Lo}]+|[\p{Lu}]+(?![\p{Ll}\p{Lo}])|[\p{Lu}][\d\p{Ll}\p{Lo}]+/gu) ?? []).map((word) => word.toLowerCase()).join("_");
4476
4679
  }
@@ -4521,6 +4724,7 @@ function sqliteTableWithCasing(casing) {
4521
4724
  var sqliteTable = sqliteTableWithCasing(void 0);
4522
4725
 
4523
4726
  // node_modules/drizzle-orm/sqlite-core/indexes.js
4727
+ init_define_EXTENSION_BUILD_INFO();
4524
4728
  var IndexBuilderOn = class {
4525
4729
  name;
4526
4730
  unique;
@@ -4586,6 +4790,7 @@ function uniqueIndex(name2) {
4586
4790
  }
4587
4791
 
4588
4792
  // node_modules/drizzle-orm/sqlite-core/primary-keys.js
4793
+ init_define_EXTENSION_BUILD_INFO();
4589
4794
  function primaryKey(...config) {
4590
4795
  if (config[0].columns) return new PrimaryKeyBuilder(config[0].columns, config[0].name);
4591
4796
  return new PrimaryKeyBuilder(config);
@@ -4628,6 +4833,12 @@ var PrimaryKey = class {
4628
4833
  }
4629
4834
  };
4630
4835
 
4836
+ // node_modules/drizzle-orm/sqlite-core/dialect.js
4837
+ init_define_EXTENSION_BUILD_INFO();
4838
+
4839
+ // node_modules/drizzle-orm/sqlite-core/columns/index.js
4840
+ init_define_EXTENSION_BUILD_INFO();
4841
+
4631
4842
  // node_modules/drizzle-orm/sqlite-core/dialect.js
4632
4843
  var escapeSQLiteName = memoizeEscape((name2) => `"${name2.replace(/"/g, '""')}"`);
4633
4844
  var rqbChunks = {
@@ -4851,7 +5062,7 @@ var SQLiteDialect = class {
4851
5062
  const fieldsList = fieldsFlat ?? orderSelectedFields(fields, void 0, this.codecs);
4852
5063
  const tableKind = chunkKindOf(table);
4853
5064
  const ownTableName = isChunk(table, tableKind, chunkKinds.subquery) ? table._.alias : isChunk(table, tableKind, chunkKinds.view) ? table[ViewBaseConfig].name : isChunk(table, tableKind, chunkKinds.sql) ? void 0 : getTableName(table);
4854
- for (const f of fieldsList) if (is(f.field, Column) && getTableName(f.field.table) !== ownTableName && !((table2) => joins?.some(({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
5065
+ for (const f of fieldsList) if (is(f.field, Column) && getTableName(f.field.table) !== ownTableName && !((table2) => joins?.some(({ alias: alias2 }) => alias2 === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
4855
5066
  const tableName = getTableName(f.field.table);
4856
5067
  throw new Error(`Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`);
4857
5068
  }
@@ -5051,7 +5262,7 @@ var SQLiteDialect = class {
5051
5262
  }
5052
5263
  if (!selected && !withKeys.length) throw new DrizzleError({ message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}` });
5053
5264
  for (const k of withKeys) {
5054
- const join3 = withParam[k];
5265
+ const join5 = withParam[k];
5055
5266
  const relation = tableConfig.relations[k];
5056
5267
  if (!relation) throw new DrizzleError({ message: `Unknown relation "${tableConfig.name}" -> "${k}"` });
5057
5268
  const isSingle2 = relation.relationType === "one";
@@ -5067,7 +5278,7 @@ var SQLiteDialect = class {
5067
5278
  table: targetTable,
5068
5279
  mode: isSingle2 ? "first" : "many",
5069
5280
  schema,
5070
- queryConfig: join3,
5281
+ queryConfig: join5,
5071
5282
  tableConfig: schema[relation.targetTableName],
5072
5283
  relationWhere: filter,
5073
5284
  nested: true,
@@ -5101,7 +5312,7 @@ var SQLiteDialect = class {
5101
5312
  key: k,
5102
5313
  selection: innerSelection,
5103
5314
  isArray: !isSingle2,
5104
- isOptional: (relation.optional ?? false) || join3 !== true && !!join3.where
5315
+ isOptional: (relation.optional ?? false) || join5 !== true && !!join5.where
5105
5316
  });
5106
5317
  }
5107
5318
  collectTo.push(commonStringChunks[" from "]);
@@ -5120,12 +5331,17 @@ var SQLiteDialect = class {
5120
5331
  }
5121
5332
  };
5122
5333
 
5334
+ // node_modules/drizzle-orm/sqlite-core/query-builders/select.js
5335
+ init_define_EXTENSION_BUILD_INFO();
5336
+
5123
5337
  // node_modules/drizzle-orm/sqlite-core/view-base.js
5338
+ init_define_EXTENSION_BUILD_INFO();
5124
5339
  var SQLiteViewBase = class extends View {
5125
5340
  static [entityKind] = "SQLiteViewBase";
5126
5341
  };
5127
5342
 
5128
5343
  // node_modules/drizzle-orm/selection-proxy.js
5344
+ init_define_EXTENSION_BUILD_INFO();
5129
5345
  var SelectionProxyHandler = class SelectionProxyHandler2 {
5130
5346
  static [entityKind] = "SelectionProxyHandler";
5131
5347
  static [Symbol.hasInstance](value) {
@@ -5174,6 +5390,7 @@ var SelectionProxyHandler = class SelectionProxyHandler2 {
5174
5390
  };
5175
5391
 
5176
5392
  // node_modules/drizzle-orm/used-tables.js
5393
+ init_define_EXTENSION_BUILD_INFO();
5177
5394
  function usedTablesOf(source) {
5178
5395
  if (is(source, Table)) return [source[CacheKey]];
5179
5396
  const out = /* @__PURE__ */ new Set();
@@ -5182,6 +5399,7 @@ function usedTablesOf(source) {
5182
5399
  }
5183
5400
 
5184
5401
  // node_modules/drizzle-orm/query-builders/query-builder.js
5402
+ init_define_EXTENSION_BUILD_INFO();
5185
5403
  var TypedQueryBuilder = class {
5186
5404
  static [entityKind] = "TypedQueryBuilder";
5187
5405
  static [Symbol.hasInstance](value) {
@@ -5274,7 +5492,7 @@ var SQLiteSelectBase = class extends TypedQueryBuilder {
5274
5492
  return (table, on) => {
5275
5493
  const baseTableName = this.tableName;
5276
5494
  const tableName = getTableLikeName(table);
5277
- if (typeof tableName === "string" && this.config.joins?.some((join3) => join3.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
5495
+ if (typeof tableName === "string" && this.config.joins?.some((join5) => join5.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
5278
5496
  this.config.fieldsFlat = void 0;
5279
5497
  this.config.mapper = void 0;
5280
5498
  if (!this.isPartialSelect) {
@@ -5731,9 +5949,9 @@ var SQLiteSelectBase = class extends TypedQueryBuilder {
5731
5949
  toSQL(withCastCodecs = true) {
5732
5950
  return this.dialect.sqlToQuery(this.getSQL(withCastCodecs));
5733
5951
  }
5734
- as(alias) {
5735
- return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias), new SelectionProxyHandler({
5736
- alias,
5952
+ as(alias2) {
5953
+ return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias2), new SelectionProxyHandler({
5954
+ alias: alias2,
5737
5955
  sqlAliasedBehavior: "alias",
5738
5956
  sqlBehavior: "error"
5739
5957
  }));
@@ -5773,6 +5991,7 @@ var intersect = createSetOperator("intersect", false);
5773
5991
  var except = createSetOperator("except", false);
5774
5992
 
5775
5993
  // node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js
5994
+ init_define_EXTENSION_BUILD_INFO();
5776
5995
  var QueryBuilder = class {
5777
5996
  static [entityKind] = "SQLiteQueryBuilder";
5778
5997
  static [Symbol.hasInstance](value) {
@@ -5784,13 +6003,13 @@ var QueryBuilder = class {
5784
6003
  this.dialect = is(dialect, SQLiteDialect) ? dialect : void 0;
5785
6004
  this.dialectConfig = is(dialect, SQLiteDialect) ? void 0 : dialect;
5786
6005
  }
5787
- $with = (alias, selection) => {
6006
+ $with = (alias2, selection) => {
5788
6007
  const queryBuilder = this;
5789
6008
  const as = (qb) => {
5790
6009
  if (typeof qb === "function") qb = qb(queryBuilder);
5791
6010
  const sql2 = qb.getSQL();
5792
- return new Proxy(new WithSubquery(sql2, selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
5793
- alias,
6011
+ return new Proxy(new WithSubquery(sql2, selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias2, true), new SelectionProxyHandler({
6012
+ alias: alias2,
5794
6013
  sqlAliasedBehavior: "alias",
5795
6014
  sqlBehavior: "error"
5796
6015
  }));
@@ -5843,6 +6062,7 @@ var QueryBuilder = class {
5843
6062
  };
5844
6063
 
5845
6064
  // node_modules/drizzle-orm/sqlite-core/session.js
6065
+ init_define_EXTENSION_BUILD_INFO();
5846
6066
  var SQLitePreparedQuery = class {
5847
6067
  query;
5848
6068
  mode;
@@ -5875,7 +6095,17 @@ var SQLiteSession = class {
5875
6095
  }
5876
6096
  };
5877
6097
 
6098
+ // node_modules/drizzle-orm/sqlite-core/alias.js
6099
+ init_define_EXTENSION_BUILD_INFO();
6100
+ function alias(table, alias2) {
6101
+ return new Proxy(table, new TableAliasProxyHandler(alias2, false));
6102
+ }
6103
+
6104
+ // node_modules/drizzle-orm/sqlite-core/async/count.js
6105
+ init_define_EXTENSION_BUILD_INFO();
6106
+
5878
6107
  // node_modules/drizzle-orm/sqlite-core/query-builders/count.js
6108
+ init_define_EXTENSION_BUILD_INFO();
5879
6109
  var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
5880
6110
  countConfig;
5881
6111
  static [entityKind] = "SQLiteCountBuilder";
@@ -5932,7 +6162,11 @@ var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
5932
6162
  }
5933
6163
  };
5934
6164
 
6165
+ // node_modules/drizzle-orm/sqlite-core/async/query.js
6166
+ init_define_EXTENSION_BUILD_INFO();
6167
+
5935
6168
  // node_modules/drizzle-orm/sqlite-core/query-builders/query.js
6169
+ init_define_EXTENSION_BUILD_INFO();
5936
6170
  var RelationalQueryBuilder = class {
5937
6171
  mode;
5938
6172
  schema;
@@ -6054,7 +6288,14 @@ var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
6054
6288
  };
6055
6289
  applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
6056
6290
 
6291
+ // node_modules/drizzle-orm/sqlite-core/async/db.js
6292
+ init_define_EXTENSION_BUILD_INFO();
6293
+
6294
+ // node_modules/drizzle-orm/sqlite-core/async/delete.js
6295
+ init_define_EXTENSION_BUILD_INFO();
6296
+
6057
6297
  // node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
6298
+ init_define_EXTENSION_BUILD_INFO();
6058
6299
  var SQLiteDeleteBase = class {
6059
6300
  table;
6060
6301
  session;
@@ -6174,7 +6415,11 @@ var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
6174
6415
  };
6175
6416
  applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
6176
6417
 
6418
+ // node_modules/drizzle-orm/sqlite-core/async/insert.js
6419
+ init_define_EXTENSION_BUILD_INFO();
6420
+
6177
6421
  // node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
6422
+ init_define_EXTENSION_BUILD_INFO();
6178
6423
  var SQLiteInsertBuilder = class {
6179
6424
  table;
6180
6425
  session;
@@ -6321,7 +6566,11 @@ var SQLiteAsyncInsertBase = class extends SQLiteInsertBase {
6321
6566
  };
6322
6567
  applyMixins(SQLiteAsyncInsertBase, [QueryPromise]);
6323
6568
 
6569
+ // node_modules/drizzle-orm/sqlite-core/async/raw.js
6570
+ init_define_EXTENSION_BUILD_INFO();
6571
+
6324
6572
  // node_modules/drizzle-orm/sqlite-core/query-builders/raw.js
6573
+ init_define_EXTENSION_BUILD_INFO();
6325
6574
  var SQLiteRaw = class {
6326
6575
  prepared;
6327
6576
  sql;
@@ -6360,6 +6609,7 @@ var SQLiteAsyncRaw = class extends SQLiteRaw {
6360
6609
  applyMixins(SQLiteAsyncRaw, [QueryPromise]);
6361
6610
 
6362
6611
  // node_modules/drizzle-orm/sqlite-core/async/select.js
6612
+ init_define_EXTENSION_BUILD_INFO();
6363
6613
  var SQLiteAsyncSelectBase = class extends SQLiteSelectBase {
6364
6614
  static [entityKind] = "SQLiteAsyncSelect";
6365
6615
  /** @internal */
@@ -6394,7 +6644,11 @@ var SQLiteAsyncSelectBase = class extends SQLiteSelectBase {
6394
6644
  };
6395
6645
  applyMixins(SQLiteAsyncSelectBase, [QueryPromise]);
6396
6646
 
6647
+ // node_modules/drizzle-orm/sqlite-core/async/update.js
6648
+ init_define_EXTENSION_BUILD_INFO();
6649
+
6397
6650
  // node_modules/drizzle-orm/sqlite-core/query-builders/update.js
6651
+ init_define_EXTENSION_BUILD_INFO();
6398
6652
  var SQLiteUpdateBuilder = class {
6399
6653
  table;
6400
6654
  session;
@@ -6442,7 +6696,7 @@ var SQLiteUpdateBase = class {
6442
6696
  createJoin(joinType) {
6443
6697
  return ((table, on) => {
6444
6698
  const tableName = getTableLikeName(table);
6445
- if (typeof tableName === "string" && this.config.joins.some((join3) => join3.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
6699
+ if (typeof tableName === "string" && this.config.joins.some((join5) => join5.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
6446
6700
  if (typeof on === "function") {
6447
6701
  const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
6448
6702
  on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
@@ -6570,6 +6824,9 @@ var SQLiteAsyncUpdateBase = class extends SQLiteUpdateBase {
6570
6824
  };
6571
6825
  applyMixins(SQLiteAsyncUpdateBase, [QueryPromise]);
6572
6826
 
6827
+ // node_modules/drizzle-orm/sqlite-core/query-builders/index.js
6828
+ init_define_EXTENSION_BUILD_INFO();
6829
+
6573
6830
  // node_modules/drizzle-orm/sqlite-core/async/db.js
6574
6831
  var SQLiteAsyncDatabase = class {
6575
6832
  resultKind;
@@ -6628,13 +6885,13 @@ var SQLiteAsyncDatabase = class {
6628
6885
  * const result = await db.with(sq).select({ name: sq.name }).from(sq);
6629
6886
  * ```
6630
6887
  */
6631
- $with = (alias, selection) => {
6888
+ $with = (alias2, selection) => {
6632
6889
  const self = this;
6633
6890
  const as = (qb) => {
6634
6891
  if (typeof qb === "function") qb = qb(new QueryBuilder(self.dialect));
6635
6892
  const sql2 = qb.getSQL();
6636
- return new Proxy(new WithSubquery(sql2, selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
6637
- alias,
6893
+ return new Proxy(new WithSubquery(sql2, selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias2, true), new SelectionProxyHandler({
6894
+ alias: alias2,
6638
6895
  sqlAliasedBehavior: "alias",
6639
6896
  sqlBehavior: "error"
6640
6897
  }));
@@ -6818,7 +7075,11 @@ var SQLiteAsyncDatabase = class {
6818
7075
  }
6819
7076
  };
6820
7077
 
7078
+ // node_modules/drizzle-orm/sqlite-core/async/session.js
7079
+ init_define_EXTENSION_BUILD_INFO();
7080
+
6821
7081
  // node_modules/drizzle-orm/cache/core/cache.js
7082
+ init_define_EXTENSION_BUILD_INFO();
6822
7083
  var Cache = class {
6823
7084
  static [entityKind] = "Cache";
6824
7085
  static [Symbol.hasInstance](value) {
@@ -7078,8 +7339,8 @@ function serializeParam(value) {
7078
7339
  }
7079
7340
  async function hashQuery(sql2, params) {
7080
7341
  const dataToHash = `${sql2}-${serializeParam(params)}`;
7081
- const createHash = getNodeCreateHash();
7082
- if (createHash) return createHash("sha256").update(dataToHash).digest("hex");
7342
+ const createHash2 = getNodeCreateHash();
7343
+ if (createHash2) return createHash2("sha256").update(dataToHash).digest("hex");
7083
7344
  encoder ??= new TextEncoder();
7084
7345
  const data = encoder.encode(dataToHash);
7085
7346
  const subtle = typeof globalThis.crypto !== "undefined" ? globalThis.crypto.subtle : void 0;
@@ -7087,6 +7348,7 @@ async function hashQuery(sql2, params) {
7087
7348
  }
7088
7349
 
7089
7350
  // node_modules/drizzle-orm/migrator.utils.js
7351
+ init_define_EXTENSION_BUILD_INFO();
7090
7352
  function formatToMillis(dateStr) {
7091
7353
  const year = parseInt(dateStr.slice(0, 4), 10);
7092
7354
  const month = parseInt(dateStr.slice(4, 6), 10) - 1;
@@ -7285,10 +7547,10 @@ var projectRoots = sqliteTable("project_roots", {
7285
7547
  });
7286
7548
 
7287
7549
  // src/service/features/projects/projects.ts
7288
- var realpathOrSame = (path) => realpath3(path).catch(() => path);
7550
+ var realpathOrSame = (path) => realpath5(path).catch(() => path);
7289
7551
  async function assertPlainFolderAllowed(folder) {
7290
7552
  const home = await realpathOrSame(homedir3());
7291
- if (dirname2(folder) === folder || within(folder, home)) {
7553
+ if (dirname3(folder) === folder || within(folder, home)) {
7292
7554
  throw new Error(
7293
7555
  `${folder} is too broad to add. Choose a more specific folder.`
7294
7556
  );
@@ -7367,6 +7629,19 @@ var Projects = class {
7367
7629
  )
7368
7630
  );
7369
7631
  }
7632
+ /**
7633
+ * The list now, with each repository's Git state from `known`, an earlier
7634
+ * `listWithGit` result. A project added since has no Git state yet.
7635
+ */
7636
+ withKnownGit(known) {
7637
+ const states = new Map(
7638
+ known.map((project) => [project.repository, project.git])
7639
+ );
7640
+ return this.list().map((project) => {
7641
+ const git2 = project.kind === "repository" ? states.get(project.repository) : void 0;
7642
+ return git2 ? { ...project, git: git2 } : project;
7643
+ });
7644
+ }
7370
7645
  async recentGitState(repository) {
7371
7646
  const recent = this.gitStates.get(repository);
7372
7647
  if (recent && Date.now() - recent.readAt < GIT_STATE_REUSE_MS) {
@@ -7391,11 +7666,12 @@ var Projects = class {
7391
7666
  * removed. Another spelling of a saved root, such as a symlink, removes the
7392
7667
  * root it resolves to, so a removal never leaves the approval in place.
7393
7668
  * Removing a root that is already gone succeeds.
7669
+ * Exact removal keeps a changed symlink from redirecting a reviewed saved key.
7394
7670
  */
7395
- remove(repository) {
7671
+ remove(repository, exact = false) {
7396
7672
  this.gitStates.clear();
7397
7673
  const deleted = (path) => this.database.orm.delete(projectRoots).where(eq(projectRoots.path, path)).run().changes;
7398
- if (!deleted(repository)) {
7674
+ if (!deleted(repository) && !exact) {
7399
7675
  try {
7400
7676
  deleted(realpathSync(repository));
7401
7677
  } catch {
@@ -7405,30 +7681,1108 @@ var Projects = class {
7405
7681
  this.onChange();
7406
7682
  return { repository };
7407
7683
  }
7408
- async resolve(path) {
7409
- this.refresh();
7410
- if (!isAbsolute2(path)) throw new Error("Use an absolute repository path");
7411
- const actual = await realpath3(path);
7412
- const approved = () => this.list().some((root) => {
7413
- if (root.kind === "repository") return root.repository === actual;
7414
- return within(root.repository, actual);
7415
- });
7416
- if (!approved()) {
7684
+ /** Rejects a folder no stored root approves. Reads the stored roots, which the CLI can change. */
7685
+ assertApproved(actual) {
7686
+ const approved = this.list().some(
7687
+ (root) => root.kind === "repository" ? root.repository === actual : within(root.repository, actual)
7688
+ );
7689
+ if (!approved) {
7417
7690
  throw new Error(
7418
7691
  "Repository outside allowed roots (register this repository or approve its parent)"
7419
7692
  );
7420
7693
  }
7694
+ }
7695
+ async resolve(path) {
7696
+ this.refresh();
7697
+ if (!isAbsolute2(path)) throw new Error("Use an absolute repository path");
7698
+ const actual = await realpath5(path);
7699
+ this.assertApproved(actual);
7421
7700
  const repository = await this.workspaces.repository(actual);
7422
- if (!approved()) {
7423
- throw new Error(
7424
- "Repository outside allowed roots (register this repository or approve its parent)"
7701
+ this.assertApproved(actual);
7702
+ return repository;
7703
+ }
7704
+ };
7705
+
7706
+ // node_modules/zod/index.js
7707
+ init_define_EXTENSION_BUILD_INFO();
7708
+
7709
+ // src/shared/time.ts
7710
+ init_define_EXTENSION_BUILD_INFO();
7711
+ var now = () => (/* @__PURE__ */ new Date()).toISOString();
7712
+
7713
+ // src/service/features/tasks/storage/schema.ts
7714
+ init_define_EXTENSION_BUILD_INFO();
7715
+ var bodyField = (field) => text().generatedAlwaysAs(sql.raw(`json_extract(body, '$.${field}')`), {
7716
+ mode: "virtual"
7717
+ });
7718
+ var tasks = sqliteTable(
7719
+ "tasks",
7720
+ {
7721
+ id: text().primaryKey(),
7722
+ owner: text().notNull(),
7723
+ body: text().notNull(),
7724
+ status: bodyField("status"),
7725
+ created_at: bodyField("created_at"),
7726
+ conversation_id: bodyField("conversation_id")
7727
+ },
7728
+ (t) => [
7729
+ index("tasks_owner_created").on(t.owner, t.created_at),
7730
+ index("tasks_owner_conversation").on(
7731
+ t.owner,
7732
+ t.conversation_id,
7733
+ t.created_at
7734
+ ),
7735
+ index("tasks_status").on(t.status)
7736
+ ]
7737
+ );
7738
+ var events = sqliteTable(
7739
+ "events",
7740
+ {
7741
+ id: integer().primaryKey({ autoIncrement: true }),
7742
+ task_id: text().notNull().references(() => tasks.id, { onDelete: "cascade" }),
7743
+ type: text().notNull(),
7744
+ timestamp: text().notNull(),
7745
+ data: text().notNull(),
7746
+ response_ref: text(),
7747
+ original_response: text(),
7748
+ /** Whether Chat shows the event, as `isChatEvent` decides. */
7749
+ chat: integer({ mode: "boolean" }).notNull().default(false)
7750
+ },
7751
+ (t) => [
7752
+ index("events_task").on(t.task_id, t.id),
7753
+ index("events_task_type").on(t.task_id, t.type, t.id),
7754
+ index("events_task_chat").on(t.task_id, t.chat, t.id),
7755
+ uniqueIndex("events_response").on(t.response_ref)
7756
+ ]
7757
+ );
7758
+ var taskRead = sqliteTable("task_read", {
7759
+ task_id: text().primaryKey().references(() => tasks.id, { onDelete: "cascade" }),
7760
+ through: integer().notNull(),
7761
+ unread: integer({ mode: "boolean" }).notNull()
7762
+ });
7763
+ var parentSeen = sqliteTable("task_parent_seen", {
7764
+ event_id: integer().primaryKey().references(() => events.id, { onDelete: "cascade" })
7765
+ });
7766
+ var taskArchive = sqliteTable("task_archive", {
7767
+ task_id: text().primaryKey().references(() => tasks.id, { onDelete: "cascade" }),
7768
+ archived_at: text().notNull()
7769
+ });
7770
+ var taskMessages = sqliteTable(
7771
+ "task_messages",
7772
+ {
7773
+ task_id: text().notNull().references(() => tasks.id, { onDelete: "cascade" }),
7774
+ seq: integer().notNull(),
7775
+ message_id: text().notNull(),
7776
+ message: text().notNull(),
7777
+ sender: text({ enum: ["user", "parent"] }).notNull()
7778
+ },
7779
+ (t) => [primaryKey({ columns: [t.task_id, t.seq] })]
7780
+ );
7781
+ var sendReceipts = sqliteTable(
7782
+ "task_send_receipts",
7783
+ {
7784
+ owner: text().notNull(),
7785
+ task_id: text().notNull().references(() => tasks.id, { onDelete: "cascade" }),
7786
+ sender: text().notNull(),
7787
+ request_id: text().notNull(),
7788
+ fingerprint: text().notNull(),
7789
+ message_id: text().notNull(),
7790
+ state: text().notNull()
7791
+ },
7792
+ (t) => [
7793
+ primaryKey({ columns: [t.owner, t.task_id, t.sender, t.request_id] })
7794
+ ]
7795
+ );
7796
+
7797
+ // src/service/features/tasks/storage/event-records.ts
7798
+ init_define_EXTENSION_BUILD_INFO();
7799
+
7800
+ // src/shared/events/decode.ts
7801
+ init_define_EXTENSION_BUILD_INFO();
7802
+
7803
+ // src/shared/providers/activity/presentation-contract.generated.ts
7804
+ init_define_EXTENSION_BUILD_INFO();
7805
+ var activityRateLimitWindowSchema = external_exports.object({
7806
+ id: external_exports.string(),
7807
+ label: external_exports.string(),
7808
+ utilization: external_exports.number(),
7809
+ resetsAt: external_exports.number().optional()
7810
+ });
7811
+ var activityStreamAppendSchema = external_exports.union([
7812
+ external_exports.object({
7813
+ field: external_exports.literal("text"),
7814
+ type: external_exports.literal("text"),
7815
+ text: external_exports.string()
7816
+ }),
7817
+ external_exports.object({
7818
+ field: external_exports.literal("thinking"),
7819
+ type: external_exports.literal("thinking"),
7820
+ text: external_exports.string()
7821
+ }),
7822
+ external_exports.object({
7823
+ field: external_exports.literal("partial_json"),
7824
+ type: external_exports.literal("input_json_delta"),
7825
+ text: external_exports.string()
7826
+ })
7827
+ ]);
7828
+ var activityContentSchema = external_exports.lazy(
7829
+ () => external_exports.union([external_exports.string(), activityContentBlockSchema])
7830
+ );
7831
+ var activityContentBlockSchema = external_exports.lazy(
7832
+ () => external_exports.union([
7833
+ external_exports.object({
7834
+ type: external_exports.literal("text"),
7835
+ text: external_exports.string()
7836
+ }),
7837
+ external_exports.object({
7838
+ type: external_exports.literal("thinking"),
7839
+ thinking: external_exports.string()
7840
+ }),
7841
+ external_exports.object({
7842
+ type: external_exports.literal("input_json_delta"),
7843
+ partial_json: external_exports.string()
7844
+ }),
7845
+ external_exports.object({
7846
+ type: external_exports.literal("tool_use"),
7847
+ id: external_exports.string(),
7848
+ name: external_exports.string(),
7849
+ input: external_exports.record(external_exports.string(), external_exports.unknown())
7850
+ }),
7851
+ external_exports.object({
7852
+ type: external_exports.literal("tool_result"),
7853
+ tool_use_id: external_exports.string(),
7854
+ content: external_exports.union([external_exports.string(), external_exports.array(activityContentSchema)]),
7855
+ is_error: external_exports.boolean().optional()
7856
+ }),
7857
+ external_exports.object({
7858
+ type: external_exports.literal("opaque"),
7859
+ data: external_exports.record(external_exports.string(), external_exports.unknown())
7860
+ })
7861
+ ])
7862
+ );
7863
+ var activityPresentationSchema = external_exports.lazy(
7864
+ () => external_exports.object({
7865
+ kind: external_exports.string().optional(),
7866
+ title: external_exports.string().optional(),
7867
+ summary: external_exports.string().optional(),
7868
+ summaryIsResponse: external_exports.boolean().optional(),
7869
+ statusTitle: external_exports.string().optional(),
7870
+ liveStatus: external_exports.boolean().optional(),
7871
+ quiet: external_exports.boolean().optional(),
7872
+ thinking: external_exports.boolean().optional(),
7873
+ failed: external_exports.boolean().optional(),
7874
+ messageId: external_exports.string().optional(),
7875
+ hasThinking: external_exports.boolean().optional(),
7876
+ rateLimitWindows: external_exports.array(activityRateLimitWindowSchema).optional(),
7877
+ statusState: external_exports.union([
7878
+ external_exports.literal("running"),
7879
+ external_exports.literal("completed"),
7880
+ external_exports.literal("failed"),
7881
+ external_exports.literal("info")
7882
+ ]).optional(),
7883
+ operation: external_exports.object({
7884
+ id: external_exports.string(),
7885
+ kind: external_exports.union([external_exports.literal("tool"), external_exports.literal("operation")]),
7886
+ title: external_exports.string(),
7887
+ summary: external_exports.string().optional(),
7888
+ started: external_exports.boolean().optional(),
7889
+ completed: external_exports.boolean().optional(),
7890
+ stopped: external_exports.boolean().optional()
7891
+ }).optional(),
7892
+ stream: external_exports.object({
7893
+ id: external_exports.string(),
7894
+ messageId: external_exports.string().optional(),
7895
+ started: external_exports.boolean().optional(),
7896
+ completed: external_exports.boolean().optional(),
7897
+ title: external_exports.string().optional(),
7898
+ content: external_exports.union([activityContentSchema, external_exports.array(activityContentSchema)]).optional(),
7899
+ details: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
7900
+ update: external_exports.object({
7901
+ index: external_exports.number(),
7902
+ block: activityContentBlockSchema.optional(),
7903
+ append: activityStreamAppendSchema.optional()
7904
+ }).optional()
7905
+ }).optional(),
7906
+ body: external_exports.object({
7907
+ role: external_exports.union([external_exports.literal("assistant"), external_exports.literal("user")]).optional(),
7908
+ content: external_exports.array(activityContentSchema).optional(),
7909
+ error: external_exports.union([external_exports.boolean(), external_exports.string()]).optional()
7910
+ }).optional()
7911
+ })
7912
+ );
7913
+
7914
+ // src/shared/events/event-contract.generated.ts
7915
+ init_define_EXTENSION_BUILD_INFO();
7916
+
7917
+ // src/shared/tasks/event-contract.generated.ts
7918
+ init_define_EXTENSION_BUILD_INFO();
7919
+ var emptyEventPayloadSchema = external_exports.record(external_exports.string(), external_exports.never());
7920
+ var taskStartedPayloadSchema = external_exports.object({
7921
+ turn: external_exports.number()
7922
+ });
7923
+ var taskTurnEndedPayloadSchema = external_exports.object({
7924
+ turn: external_exports.number(),
7925
+ outcome: external_exports.union([
7926
+ external_exports.literal("completed"),
7927
+ external_exports.literal("failed"),
7928
+ external_exports.literal("interrupted")
7929
+ ]),
7930
+ runtime_ms: external_exports.number(),
7931
+ cost_usd: external_exports.number()
7932
+ });
7933
+ var taskInstructionPayloadSchema = external_exports.object({
7934
+ message_id: external_exports.string(),
7935
+ message: external_exports.string(),
7936
+ from: external_exports.union([external_exports.literal("user"), external_exports.literal("parent")]),
7937
+ delivery: external_exports.union([
7938
+ external_exports.literal("steer"),
7939
+ external_exports.literal("queue"),
7940
+ external_exports.literal("interrupt")
7941
+ ])
7942
+ });
7943
+ var taskQueueChangedPayloadSchema = external_exports.object({
7944
+ queue: external_exports.array(
7945
+ external_exports.object({
7946
+ message_id: external_exports.string(),
7947
+ message: external_exports.string(),
7948
+ from: external_exports.union([external_exports.literal("user"), external_exports.literal("parent")])
7949
+ })
7950
+ ),
7951
+ paused: external_exports.boolean()
7952
+ });
7953
+ var taskSessionStartedPayloadSchema = external_exports.object({
7954
+ reason: external_exports.union([external_exports.literal("no_session"), external_exports.literal("session_unavailable")])
7955
+ });
7956
+ var taskWorktreeRecreatedPayloadSchema = external_exports.object({
7957
+ from: external_exports.union([external_exports.literal("branch"), external_exports.literal("base")])
7958
+ });
7959
+ var taskInterruptedPayloadSchema = external_exports.object({
7960
+ reason: external_exports.literal("service_restart").optional(),
7961
+ error: external_exports.string().optional()
7962
+ });
7963
+ var taskFailedPayloadSchema = external_exports.object({
7964
+ error: external_exports.string().optional(),
7965
+ error_code: external_exports.string().optional()
7966
+ });
7967
+ var taskWorktreeRemovedPayloadSchema = external_exports.object({
7968
+ path: external_exports.string().optional(),
7969
+ branch: external_exports.string().optional(),
7970
+ forced: external_exports.boolean().optional()
7971
+ });
7972
+ var taskBranchDeletedPayloadSchema = external_exports.object({
7973
+ branch: external_exports.string().optional()
7974
+ });
7975
+ var taskControlRequestedPayloadSchema = external_exports.object({
7976
+ status: external_exports.literal("interrupted")
7977
+ });
7978
+ var taskSteerTakenPayloadSchema = external_exports.object({
7979
+ message_id: external_exports.string()
7980
+ });
7981
+ var taskMessageRemovedPayloadSchema = external_exports.object({
7982
+ message_id: external_exports.string()
7983
+ });
7984
+ var taskStatusPayloadSchema = external_exports.object({
7985
+ error: external_exports.string().optional()
7986
+ });
7987
+ var taskEventPayloadMapSchema = external_exports.object({
7988
+ "task.started": taskStartedPayloadSchema,
7989
+ "task.turn_ended": taskTurnEndedPayloadSchema,
7990
+ "task.instruction": taskInstructionPayloadSchema,
7991
+ "task.queue_changed": taskQueueChangedPayloadSchema,
7992
+ "task.session_started": taskSessionStartedPayloadSchema,
7993
+ "task.worktree_recreated": taskWorktreeRecreatedPayloadSchema,
7994
+ "task.interrupted": taskInterruptedPayloadSchema,
7995
+ "task.failed": taskFailedPayloadSchema,
7996
+ "task.worktree_removed": taskWorktreeRemovedPayloadSchema,
7997
+ "task.branch_deleted": taskBranchDeletedPayloadSchema,
7998
+ "task.control_requested": taskControlRequestedPayloadSchema,
7999
+ "task.steer_taken": taskSteerTakenPayloadSchema,
8000
+ "task.message_removed": taskMessageRemovedPayloadSchema,
8001
+ "task.queued": emptyEventPayloadSchema,
8002
+ "task.completed": taskStatusPayloadSchema
8003
+ });
8004
+
8005
+ // src/shared/events/event-contract.generated.ts
8006
+ var eventEnvelopeSchema = external_exports.object({
8007
+ id: external_exports.number(),
8008
+ task_id: external_exports.string(),
8009
+ type: external_exports.string(),
8010
+ timestamp: external_exports.string(),
8011
+ data: external_exports.record(external_exports.string(), external_exports.unknown())
8012
+ });
8013
+ var toolStartedPayloadSchema = external_exports.object({
8014
+ id: external_exports.string().optional(),
8015
+ name: external_exports.string().optional(),
8016
+ input: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
8017
+ });
8018
+ var toolCompletedPayloadSchema = external_exports.object({
8019
+ id: external_exports.string().optional(),
8020
+ name: external_exports.string().optional(),
8021
+ input: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
8022
+ error: external_exports.boolean().optional(),
8023
+ content: external_exports.union([external_exports.string(), external_exports.array(activityContentSchema)]).optional()
8024
+ });
8025
+ var agentMessageFieldsSchema = external_exports.object({
8026
+ message_id: external_exports.string().optional(),
8027
+ parent_tool_use_id: external_exports.string().optional().nullable()
8028
+ });
8029
+ var agentMessagePayloadSchema = agentMessageFieldsSchema.extend({
8030
+ role: external_exports.literal("assistant"),
8031
+ text: external_exports.string(),
8032
+ content: external_exports.union([activityContentSchema, external_exports.array(activityContentSchema)]).optional()
8033
+ });
8034
+ var agentContentPayloadSchema = agentMessageFieldsSchema.extend({
8035
+ role: external_exports.union([external_exports.literal("assistant"), external_exports.literal("user")]),
8036
+ content: external_exports.union([activityContentSchema, external_exports.array(activityContentSchema)]),
8037
+ text: external_exports.string().optional()
8038
+ });
8039
+ var agentReplyPayloadSchema = external_exports.object({
8040
+ text: external_exports.string(),
8041
+ turn: external_exports.number()
8042
+ });
8043
+ var agentStartedPayloadSchema = external_exports.object({
8044
+ model: external_exports.string().optional(),
8045
+ tools: external_exports.array(external_exports.string()).optional()
8046
+ });
8047
+ var agentLimitedPayloadSchema = external_exports.object({
8048
+ setting: external_exports.union([external_exports.literal("permission_mode"), external_exports.literal("model")]),
8049
+ requested: external_exports.string(),
8050
+ effective: external_exports.string(),
8051
+ reason: external_exports.string()
8052
+ });
8053
+ var agentCompletedPayloadSchema = external_exports.object({
8054
+ cost_usd: external_exports.number().optional(),
8055
+ total_cost_usd: external_exports.number().optional(),
8056
+ duration_ms: external_exports.number().optional(),
8057
+ result: external_exports.string().optional(),
8058
+ subtype: external_exports.string().optional(),
8059
+ is_error: external_exports.boolean().optional(),
8060
+ errors: external_exports.array(external_exports.string()).optional(),
8061
+ usage: external_exports.object({
8062
+ input_tokens: external_exports.number().optional(),
8063
+ output_tokens: external_exports.number().optional(),
8064
+ cache_creation_input_tokens: external_exports.number().optional(),
8065
+ cache_read_input_tokens: external_exports.number().optional()
8066
+ }).optional()
8067
+ });
8068
+ var agentInputRequiredPayloadSchema = external_exports.object({
8069
+ request: external_exports.object({
8070
+ id: external_exports.string(),
8071
+ tool: external_exports.string(),
8072
+ kind: external_exports.union([external_exports.literal("question"), external_exports.literal("permission")]),
8073
+ input: external_exports.record(external_exports.string(), external_exports.unknown())
8074
+ }).optional()
8075
+ });
8076
+ var agentInputSubmittedPayloadSchema = external_exports.object({
8077
+ approved: external_exports.boolean()
8078
+ });
8079
+ var agentPermissionDecidedPayloadSchema = external_exports.object({
8080
+ tool: external_exports.string(),
8081
+ input: external_exports.record(external_exports.string(), external_exports.unknown()),
8082
+ approval_mode: external_exports.union([
8083
+ external_exports.literal("ask_user"),
8084
+ external_exports.literal("parent_agent"),
8085
+ external_exports.literal("auto_approve"),
8086
+ external_exports.literal("deny")
8087
+ ]),
8088
+ approved: external_exports.boolean(),
8089
+ authority: external_exports.literal("policy")
8090
+ });
8091
+ var agentInputDecisionPayloadSchema = external_exports.object({
8092
+ request_id: external_exports.string(),
8093
+ approved: external_exports.boolean(),
8094
+ authority: external_exports.union([external_exports.literal("user"), external_exports.literal("parent")])
8095
+ });
8096
+ var eventPayloadMapSchema = taskEventPayloadMapSchema.extend({
8097
+ "tool.started": toolStartedPayloadSchema,
8098
+ "tool.completed": toolCompletedPayloadSchema,
8099
+ "agent.message": agentMessagePayloadSchema,
8100
+ "agent.content": agentContentPayloadSchema,
8101
+ "agent.reply": agentReplyPayloadSchema,
8102
+ "agent.started": agentStartedPayloadSchema,
8103
+ "agent.limited": agentLimitedPayloadSchema,
8104
+ "agent.completed": agentCompletedPayloadSchema,
8105
+ "agent.input_required": agentInputRequiredPayloadSchema,
8106
+ "agent.input_submitted": agentInputSubmittedPayloadSchema,
8107
+ "agent.permission_decided": agentPermissionDecidedPayloadSchema,
8108
+ "agent.input_decision": agentInputDecisionPayloadSchema
8109
+ });
8110
+
8111
+ // src/shared/events/decode.ts
8112
+ var knownEventTypes = new Set(Object.keys(eventPayloadMapSchema.shape));
8113
+ function decodeEventView(type, data) {
8114
+ if (!data || typeof data !== "object" || Array.isArray(data)) {
8115
+ throw new Error("Event data must be an object");
8116
+ }
8117
+ if (!knownEventTypes.has(type)) {
8118
+ return {
8119
+ kind: "opaque",
8120
+ type,
8121
+ data
8122
+ };
8123
+ }
8124
+ const eventType = type;
8125
+ const schema = eventPayloadMapSchema.shape[eventType];
8126
+ const parsed = schema.safeParse(data);
8127
+ if (!parsed.success) {
8128
+ return { kind: "opaque", type, data };
8129
+ }
8130
+ return {
8131
+ kind: "known",
8132
+ type: eventType,
8133
+ data: parsed.data
8134
+ };
8135
+ }
8136
+ function decodedEvent(event) {
8137
+ const parsedPresentation = activityPresentationSchema.safeParse(
8138
+ event.data.activity
8139
+ );
8140
+ return {
8141
+ id: event.id,
8142
+ task_id: event.task_id,
8143
+ type: event.type,
8144
+ timestamp: event.timestamp,
8145
+ data: event.data,
8146
+ view: decodeEventView(event.type, event.data),
8147
+ ...parsedPresentation.success ? { presentation: parsedPresentation.data } : {}
8148
+ };
8149
+ }
8150
+
8151
+ // src/shared/tasks/conversation/chat.ts
8152
+ init_define_EXTENSION_BUILD_INFO();
8153
+
8154
+ // src/shared/events/payload.ts
8155
+ init_define_EXTENSION_BUILD_INFO();
8156
+ function eventPayload(event, type) {
8157
+ const view = event.view;
8158
+ if (view.kind !== "known" || view.type !== type) return void 0;
8159
+ return view.data;
8160
+ }
8161
+
8162
+ // src/shared/tasks/conversation/messages.ts
8163
+ init_define_EXTENSION_BUILD_INFO();
8164
+ var MESSAGE_EVENTS = [
8165
+ "task.started",
8166
+ "task.instruction",
8167
+ "agent.message",
8168
+ "agent.reply"
8169
+ ];
8170
+ function workerMessageId(e) {
8171
+ return eventPayload(e, "agent.message")?.message_id ?? `evt_${e.id}`;
8172
+ }
8173
+ function workerText(e) {
8174
+ const message2 = eventPayload(e, "agent.message");
8175
+ if (!message2 || message2.parent_tool_use_id) return void 0;
8176
+ return message2.text.trim() ? message2.text : void 0;
8177
+ }
8178
+ var same = (message2, reply) => {
8179
+ const a = message2.trim(), b = reply.trim();
8180
+ return a === b || a.endsWith(b);
8181
+ };
8182
+ function queueState(id, pending, queued) {
8183
+ if (pending.has(id)) return { state: "pending_steer" };
8184
+ if (queued.has(id)) return { state: "queued" };
8185
+ return {};
8186
+ }
8187
+ function conversation(task, events2) {
8188
+ const pending = new Set(task.pending_steers.map((m) => m.id));
8189
+ const queued = new Set(task.queue.map((m) => m.id));
8190
+ let turn = 1;
8191
+ const messages = [
8192
+ {
8193
+ id: "request",
8194
+ event_id: 0,
8195
+ timestamp: task.created_at,
8196
+ turn,
8197
+ from: task.created_by,
8198
+ kind: "request",
8199
+ text: task.description
8200
+ }
8201
+ ];
8202
+ for (const e of [...events2].sort((a, b) => a.id - b.id)) {
8203
+ const started = eventPayload(e, "task.started");
8204
+ if (started) turn = started.turn;
8205
+ const instruction = eventPayload(e, "task.instruction");
8206
+ if (instruction) {
8207
+ const id = instruction.message_id;
8208
+ messages.push({
8209
+ id,
8210
+ event_id: e.id,
8211
+ timestamp: e.timestamp,
8212
+ turn,
8213
+ from: instruction.from,
8214
+ kind: "message",
8215
+ text: instruction.message,
8216
+ delivery: instruction.delivery,
8217
+ ...queueState(id, pending, queued)
8218
+ });
8219
+ }
8220
+ if (eventPayload(e, "agent.message")) {
8221
+ const text2 = workerText(e);
8222
+ if (text2 === void 0) continue;
8223
+ const id = workerMessageId(e);
8224
+ const previous = messages.at(-1);
8225
+ if (previous?.id === id && previous.from === "worker") {
8226
+ previous.text = `${previous.text}
8227
+
8228
+ ${text2}`;
8229
+ previous.event_id = e.id;
8230
+ continue;
8231
+ }
8232
+ messages.push({
8233
+ id,
8234
+ event_id: e.id,
8235
+ timestamp: e.timestamp,
8236
+ turn,
8237
+ from: "worker",
8238
+ kind: "message",
8239
+ text: text2
8240
+ });
8241
+ }
8242
+ const reply = eventPayload(e, "agent.reply");
8243
+ if (reply) {
8244
+ const text2 = reply.text;
8245
+ const replyTurn = reply.turn;
8246
+ const last = messages.findLast(
8247
+ (m) => m.from === "worker" && m.turn === replyTurn
7425
8248
  );
8249
+ if (last && last.kind === "message" && same(last.text, text2)) {
8250
+ last.kind = "reply";
8251
+ last.event_id = e.id;
8252
+ continue;
8253
+ }
8254
+ messages.push({
8255
+ id: `reply_${e.id}`,
8256
+ event_id: e.id,
8257
+ timestamp: e.timestamp,
8258
+ turn: replyTurn,
8259
+ from: "worker",
8260
+ kind: "reply",
8261
+ text: text2
8262
+ });
7426
8263
  }
7427
- return repository;
7428
8264
  }
8265
+ return messages.sort((a, b) => a.event_id - b.event_id);
8266
+ }
8267
+
8268
+ // src/shared/tasks/conversation/chat.ts
8269
+ var CHAT_EVENTS = [
8270
+ "task.started",
8271
+ "task.instruction",
8272
+ "agent.message",
8273
+ "agent.reply",
8274
+ "task.turn_ended",
8275
+ "task.failed",
8276
+ "task.session_started",
8277
+ "task.worktree_recreated",
8278
+ "agent.limited",
8279
+ "agent.input_required"
8280
+ ];
8281
+ var isChatEvent = (type, data) => CHAT_EVENTS.includes(type) || type === "claude.activity" && (data.subtype === "compact_boundary" || data.compact_result === "failed");
8282
+ var isCompaction = (e) => {
8283
+ return e.presentation?.kind === "compact_boundary";
8284
+ };
8285
+ function note(e) {
8286
+ const base = {
8287
+ kind: "note",
8288
+ id: `evt_${e.id}`,
8289
+ event_id: e.id,
8290
+ timestamp: e.timestamp
8291
+ };
8292
+ const session = eventPayload(e, "task.session_started");
8293
+ if (session) {
8294
+ return {
8295
+ ...base,
8296
+ note: "session",
8297
+ text: session.reason === "no_session" ? "New session: the task had none to continue" : "New session: the earlier one couldn't continue"
8298
+ };
8299
+ }
8300
+ const worktree = eventPayload(e, "task.worktree_recreated");
8301
+ if (worktree) {
8302
+ return {
8303
+ ...base,
8304
+ note: "worktree",
8305
+ text: worktree.from === "base" ? "Worktree recreated from the base commit, since its branch was deleted" : "Worktree recreated from its branch"
8306
+ };
8307
+ }
8308
+ const limited = eventPayload(e, "agent.limited");
8309
+ if (limited) return { ...base, note: "limited", text: limited.reason };
8310
+ const failed = eventPayload(e, "task.failed");
8311
+ if (failed) {
8312
+ return {
8313
+ ...base,
8314
+ note: "failure",
8315
+ text: `Task failed: ${failureMessage(failed) ?? "Unknown error"}`
8316
+ };
8317
+ }
8318
+ if (isCompaction(e)) {
8319
+ return { ...base, note: "compaction", text: "Context compacted" };
8320
+ }
8321
+ if (e.type === "claude.activity" && e.presentation?.statusTitle === "Context compaction failed") {
8322
+ return { ...base, note: "failure", text: "Context compaction failed" };
8323
+ }
8324
+ return void 0;
8325
+ }
8326
+ function chatItems(task, events2) {
8327
+ const sorted = [...events2].sort((a, b) => a.id - b.id);
8328
+ const messages = conversation(task, sorted);
8329
+ const items = [];
8330
+ let next = 0;
8331
+ let failedOutcome;
8332
+ const flush = (until) => {
8333
+ for (let message2 = messages[next]; message2 && message2.event_id <= until; message2 = messages[++next]) {
8334
+ items.push({
8335
+ kind: "message",
8336
+ id: message2.id,
8337
+ event_id: message2.event_id,
8338
+ message: message2
8339
+ });
8340
+ }
8341
+ };
8342
+ for (const e of sorted) {
8343
+ const turnEnded = eventPayload(e, "task.turn_ended");
8344
+ if (turnEnded) {
8345
+ flush(e.id);
8346
+ const outcome = {
8347
+ kind: "outcome",
8348
+ id: `turn_${turnEnded.turn}_${e.id}`,
8349
+ event_id: e.id,
8350
+ timestamp: e.timestamp,
8351
+ turn: turnEnded.turn,
8352
+ outcome: turnEnded.outcome,
8353
+ runtime_ms: turnEnded.runtime_ms,
8354
+ cost_usd: turnEnded.cost_usd
8355
+ };
8356
+ items.push(outcome);
8357
+ failedOutcome = outcome.outcome === "failed" ? outcome : void 0;
8358
+ } else if (eventPayload(e, "task.failed")) {
8359
+ if (failedOutcome) {
8360
+ failedOutcome.error = failureMessage(eventPayload(e, "task.failed"));
8361
+ failedOutcome.event_id = e.id;
8362
+ } else {
8363
+ flush(e.id);
8364
+ items.push(note(e));
8365
+ }
8366
+ failedOutcome = void 0;
8367
+ } else {
8368
+ if (eventPayload(e, "task.instruction") !== void 0 || eventPayload(e, "task.queued") !== void 0 || eventPayload(e, "task.started") !== void 0) {
8369
+ failedOutcome = void 0;
8370
+ }
8371
+ const marker = note(e);
8372
+ if (marker) {
8373
+ flush(e.id);
8374
+ items.push(marker);
8375
+ }
8376
+ }
8377
+ }
8378
+ flush(Infinity);
8379
+ return items;
8380
+ }
8381
+
8382
+ // src/service/features/tasks/storage/event-records.ts
8383
+ var eventColumns = {
8384
+ id: events.id,
8385
+ task_id: events.task_id,
8386
+ type: events.type,
8387
+ timestamp: events.timestamp,
8388
+ data: events.data
8389
+ };
8390
+ function readOriginalResponse(database, id, responseRef) {
8391
+ const row = database.orm.select({ body: events.original_response }).from(events).where(and(eq(events.response_ref, responseRef), eq(events.task_id, id))).get();
8392
+ return row?.body ? JSON.parse(row.body) : void 0;
8393
+ }
8394
+ function splitOriginalResponse(payload) {
8395
+ const response = typeof payload.response_ref === "string" && payload.raw_response !== void 0 ? {
8396
+ id: payload.response_ref,
8397
+ body: JSON.stringify(payload.raw_response)
8398
+ } : void 0;
8399
+ const { raw_response: _original, ...data } = payload;
8400
+ return { data, response, serialized: JSON.stringify(data) };
8401
+ }
8402
+ function insertEvent(database, metrics, taskId, type, payload) {
8403
+ const timestamp = now();
8404
+ const stored = splitOriginalResponse(payload);
8405
+ const { id } = database.orm.insert(events).values({
8406
+ task_id: taskId,
8407
+ type,
8408
+ timestamp,
8409
+ data: stored.serialized,
8410
+ response_ref: stored.response?.id,
8411
+ original_response: stored.response?.body,
8412
+ chat: isChatEvent(type, stored.data)
8413
+ }).returning({ id: events.id }).get();
8414
+ metrics.committed(database, taskId, stored.serialized, stored.response?.body);
8415
+ return decodedEvent({
8416
+ id,
8417
+ task_id: taskId,
8418
+ type,
8419
+ timestamp,
8420
+ data: stored.data
8421
+ });
8422
+ }
8423
+
8424
+ // src/service/features/tasks/storage/stored.ts
8425
+ init_define_EXTENSION_BUILD_INFO();
8426
+
8427
+ // node_modules/drizzle-orm/zod/index.js
8428
+ init_define_EXTENSION_BUILD_INFO();
8429
+
8430
+ // node_modules/drizzle-orm/zod/column.js
8431
+ init_define_EXTENSION_BUILD_INFO();
8432
+ var literalSchema = external_exports.union([
8433
+ external_exports.string(),
8434
+ external_exports.number(),
8435
+ external_exports.boolean(),
8436
+ external_exports.null()
8437
+ ]);
8438
+ var jsonSchema = external_exports.union([
8439
+ literalSchema,
8440
+ external_exports.record(external_exports.string(), external_exports.any()),
8441
+ external_exports.array(external_exports.any())
8442
+ ]);
8443
+ var bufferSchema = external_exports.custom((v) => v instanceof Buffer);
8444
+ function columnToSchema(column, factory) {
8445
+ const z$1 = factory?.zodInstance ?? external_exports;
8446
+ const coerce = factory?.coerce ?? {};
8447
+ let schema;
8448
+ const dimensions = column.dimensions;
8449
+ if (typeof dimensions === "number" && dimensions > 0) return pgArrayColumnToSchema(column, dimensions, z$1, coerce);
8450
+ const { type, constraint } = extractExtendedColumnType(column);
8451
+ switch (type) {
8452
+ case "array":
8453
+ schema = arrayColumnToSchema(column, constraint, z$1);
8454
+ break;
8455
+ case "object":
8456
+ schema = objectColumnToSchema(column, constraint, z$1, coerce);
8457
+ break;
8458
+ case "number":
8459
+ schema = numberColumnToSchema(column, constraint, z$1, coerce);
8460
+ break;
8461
+ case "bigint":
8462
+ schema = bigintColumnToSchema(column, constraint, z$1, coerce);
8463
+ break;
8464
+ case "boolean":
8465
+ schema = coerce === true || coerce.boolean ? z$1.coerce.boolean() : z$1.boolean();
8466
+ break;
8467
+ case "string":
8468
+ schema = stringColumnToSchema(column, constraint, z$1, coerce);
8469
+ break;
8470
+ case "custom":
8471
+ schema = z$1.any();
8472
+ break;
8473
+ default:
8474
+ schema = z$1.any();
8475
+ }
8476
+ return schema;
8477
+ }
8478
+ function numberColumnToSchema(column, constraint, z, coerce) {
8479
+ let min2;
8480
+ let max2;
8481
+ let integer2 = false;
8482
+ switch (constraint) {
8483
+ case "int8":
8484
+ min2 = CONSTANTS.INT8_MIN;
8485
+ max2 = CONSTANTS.INT8_MAX;
8486
+ integer2 = true;
8487
+ break;
8488
+ case "uint8":
8489
+ min2 = 0;
8490
+ max2 = CONSTANTS.INT8_UNSIGNED_MAX;
8491
+ integer2 = true;
8492
+ break;
8493
+ case "int16":
8494
+ min2 = CONSTANTS.INT16_MIN;
8495
+ max2 = CONSTANTS.INT16_MAX;
8496
+ integer2 = true;
8497
+ break;
8498
+ case "uint16":
8499
+ min2 = 0;
8500
+ max2 = CONSTANTS.INT16_UNSIGNED_MAX;
8501
+ integer2 = true;
8502
+ break;
8503
+ case "int24":
8504
+ min2 = CONSTANTS.INT24_MIN;
8505
+ max2 = CONSTANTS.INT24_MAX;
8506
+ integer2 = true;
8507
+ break;
8508
+ case "uint24":
8509
+ min2 = 0;
8510
+ max2 = CONSTANTS.INT24_UNSIGNED_MAX;
8511
+ integer2 = true;
8512
+ break;
8513
+ case "int32":
8514
+ min2 = CONSTANTS.INT32_MIN;
8515
+ max2 = CONSTANTS.INT32_MAX;
8516
+ integer2 = true;
8517
+ break;
8518
+ case "uint32":
8519
+ min2 = 0;
8520
+ max2 = CONSTANTS.INT32_UNSIGNED_MAX;
8521
+ integer2 = true;
8522
+ break;
8523
+ case "int53":
8524
+ min2 = Number.MIN_SAFE_INTEGER;
8525
+ max2 = Number.MAX_SAFE_INTEGER;
8526
+ integer2 = true;
8527
+ break;
8528
+ case "uint53":
8529
+ min2 = 0;
8530
+ max2 = Number.MAX_SAFE_INTEGER;
8531
+ integer2 = true;
8532
+ break;
8533
+ case "float":
8534
+ min2 = CONSTANTS.INT24_MIN;
8535
+ max2 = CONSTANTS.INT24_MAX;
8536
+ break;
8537
+ case "ufloat":
8538
+ min2 = 0;
8539
+ max2 = CONSTANTS.INT24_UNSIGNED_MAX;
8540
+ break;
8541
+ case "double":
8542
+ min2 = CONSTANTS.INT48_MIN;
8543
+ max2 = CONSTANTS.INT48_MAX;
8544
+ break;
8545
+ case "udouble":
8546
+ min2 = 0;
8547
+ max2 = CONSTANTS.INT48_UNSIGNED_MAX;
8548
+ break;
8549
+ case "year":
8550
+ min2 = 1901;
8551
+ max2 = 2155;
8552
+ integer2 = true;
8553
+ break;
8554
+ case "unsigned":
8555
+ min2 = 0;
8556
+ max2 = Number.MAX_SAFE_INTEGER;
8557
+ break;
8558
+ default:
8559
+ min2 = Number.MIN_SAFE_INTEGER;
8560
+ max2 = Number.MAX_SAFE_INTEGER;
8561
+ }
8562
+ let schema = coerce === true || coerce?.number ? integer2 ? z.coerce.number().int() : z.coerce.number() : integer2 ? z.int() : z.number();
8563
+ schema = schema.gte(min2).lte(max2);
8564
+ return schema;
8565
+ }
8566
+ var bigintStringModeSchema = external_exports.string().regex(/^-?\d+$/).transform(BigInt).pipe(external_exports.bigint().gte(CONSTANTS.INT64_MIN).lte(CONSTANTS.INT64_MAX)).transform(String);
8567
+ var unsignedBigintStringModeSchema = external_exports.string().regex(/^\d+$/).transform(BigInt).pipe(external_exports.bigint().gte(0n).lte(CONSTANTS.INT64_MAX)).transform(String);
8568
+ function bigintColumnToSchema(column, constraint, z, coerce) {
8569
+ let min2;
8570
+ let max2;
8571
+ switch (constraint) {
8572
+ case "int64":
8573
+ min2 = CONSTANTS.INT64_MIN;
8574
+ max2 = CONSTANTS.INT64_MAX;
8575
+ break;
8576
+ case "uint64":
8577
+ min2 = 0n;
8578
+ max2 = CONSTANTS.INT64_UNSIGNED_MAX;
8579
+ }
8580
+ let schema = coerce === true || coerce?.bigint ? z.coerce.bigint() : z.bigint();
8581
+ if (min2 !== void 0) schema = schema.min(min2);
8582
+ if (max2 !== void 0) schema = schema.max(max2);
8583
+ return schema;
8584
+ }
8585
+ function pgArrayColumnToSchema(column, dimensions, z, coerce) {
8586
+ const [baseType, baseConstraint] = column.dataType.split(" ");
8587
+ let baseSchema;
8588
+ switch (baseType) {
8589
+ case "number":
8590
+ baseSchema = numberColumnToSchema(column, baseConstraint, z, coerce);
8591
+ break;
8592
+ case "bigint":
8593
+ baseSchema = bigintColumnToSchema(column, baseConstraint, z, coerce);
8594
+ break;
8595
+ case "boolean":
8596
+ baseSchema = coerce === true || coerce?.boolean ? z.coerce.boolean() : z.boolean();
8597
+ break;
8598
+ case "string":
8599
+ baseSchema = stringColumnToSchema(column, baseConstraint, z, coerce);
8600
+ break;
8601
+ case "object":
8602
+ baseSchema = objectColumnToSchema(column, baseConstraint, z, coerce);
8603
+ break;
8604
+ case "array":
8605
+ baseSchema = arrayColumnToSchema(column, baseConstraint, z);
8606
+ break;
8607
+ default:
8608
+ baseSchema = z.any();
8609
+ }
8610
+ let schema = z.array(baseSchema);
8611
+ for (let i = 1; i < dimensions; i++) schema = z.array(schema);
8612
+ return schema;
8613
+ }
8614
+ function arrayColumnToSchema(column, constraint, z) {
8615
+ switch (constraint) {
8616
+ case "geometry":
8617
+ case "point":
8618
+ return z.tuple([z.number(), z.number()]);
8619
+ case "line":
8620
+ return z.tuple([
8621
+ z.number(),
8622
+ z.number(),
8623
+ z.number()
8624
+ ]);
8625
+ case "vector":
8626
+ case "halfvector": {
8627
+ const length = column.length;
8628
+ return length ? z.array(z.number()).length(length) : z.array(z.number());
8629
+ }
8630
+ case "int64vector": {
8631
+ const length = column.length;
8632
+ return length ? z.array(z.bigint().min(CONSTANTS.INT64_MIN).max(CONSTANTS.INT64_MAX)).length(length) : z.array(z.bigint().min(CONSTANTS.INT64_MIN).max(CONSTANTS.INT64_MAX));
8633
+ }
8634
+ default:
8635
+ return z.array(z.any());
8636
+ }
8637
+ }
8638
+ function objectColumnToSchema(column, constraint, z, coerce) {
8639
+ switch (constraint) {
8640
+ case "buffer":
8641
+ return bufferSchema;
8642
+ case "date":
8643
+ return coerce === true || coerce?.date ? z.coerce.date() : z.date();
8644
+ case "geometry":
8645
+ case "point":
8646
+ return z.object({
8647
+ x: z.number(),
8648
+ y: z.number()
8649
+ });
8650
+ case "json":
8651
+ return jsonSchema;
8652
+ case "line":
8653
+ return z.object({
8654
+ a: z.number(),
8655
+ b: z.number(),
8656
+ c: z.number()
8657
+ });
8658
+ default:
8659
+ return z.looseObject({});
8660
+ }
8661
+ }
8662
+ function stringColumnToSchema(column, constraint, z, coerce) {
8663
+ const { name: columnName, length, isLengthExact } = column;
8664
+ let regex;
8665
+ if (constraint === "binary") regex = /^[01]*$/;
8666
+ if (constraint === "uuid") return z.uuid();
8667
+ if (constraint === "enum") {
8668
+ const enumValues = column.enumValues;
8669
+ if (!enumValues) throw new Error(`Column "${getTableName(getColumnTable(column))}"."${columnName}" is of 'enum' type, but lacks enum values`);
8670
+ return z.enum(enumValues);
8671
+ }
8672
+ if (constraint === "int64") return bigintStringModeSchema;
8673
+ if (constraint === "uint64") return unsignedBigintStringModeSchema;
8674
+ let schema = coerce === true || coerce?.string ? z.coerce.string() : z.string();
8675
+ schema = regex ? schema.regex(regex) : schema;
8676
+ return length && isLengthExact ? schema.length(length) : length ? schema.max(length) : schema;
8677
+ }
8678
+
8679
+ // node_modules/drizzle-orm/zod/schema.js
8680
+ init_define_EXTENSION_BUILD_INFO();
8681
+ function handleColumns(columns, refinements, conditions, factory) {
8682
+ const columnSchemas = {};
8683
+ for (const [key, selected] of Object.entries(columns)) {
8684
+ if (!is(selected, Column) && !is(selected, SQL) && !is(selected, SQL.Aliased) && typeof selected === "object") {
8685
+ columnSchemas[key] = handleColumns(isTable(selected) || isView(selected) ? getColumns(selected) : selected, refinements[key] ?? {}, conditions, factory);
8686
+ continue;
8687
+ }
8688
+ const refinement = refinements[key];
8689
+ if (refinement !== void 0 && typeof refinement !== "function") {
8690
+ columnSchemas[key] = refinement;
8691
+ continue;
8692
+ }
8693
+ const column = is(selected, Column) ? selected : void 0;
8694
+ const schema = column ? columnToSchema(column, factory) : external_exports.any();
8695
+ const refined = typeof refinement === "function" ? refinement(schema) : schema;
8696
+ if (conditions.never(column)) continue;
8697
+ else columnSchemas[key] = refined;
8698
+ if (column) {
8699
+ if (conditions.nullable(column)) columnSchemas[key] = columnSchemas[key].nullable();
8700
+ if (conditions.optional(column)) columnSchemas[key] = columnSchemas[key].optional();
8701
+ }
8702
+ }
8703
+ return external_exports.object(columnSchemas);
8704
+ }
8705
+ function handleEnum(enum_, factory) {
8706
+ return (factory?.zodInstance ?? external_exports).enum(enum_.enumValues);
8707
+ }
8708
+ var selectConditions = {
8709
+ never: () => false,
8710
+ optional: () => false,
8711
+ nullable: (column) => !column.notNull
8712
+ };
8713
+ var createSelectSchema = (entity, refine) => {
8714
+ if (isWithEnum(entity)) return handleEnum(entity);
8715
+ return handleColumns(getColumns(entity), refine ?? {}, selectConditions);
7429
8716
  };
7430
8717
 
8718
+ // src/shared/tasks/model.ts
8719
+ init_define_EXTENSION_BUILD_INFO();
8720
+
8721
+ // src/shared/attachments/attachment-error.ts
8722
+ init_define_EXTENSION_BUILD_INFO();
8723
+ var AttachmentError = class extends Error {
8724
+ name = "AttachmentError";
8725
+ };
8726
+
8727
+ // src/shared/attachments/model.ts
8728
+ init_define_EXTENSION_BUILD_INFO();
8729
+ var ATTACHMENT_LIMITS = {
8730
+ count: 20,
8731
+ summaryChars: 200,
8732
+ titleChars: 60,
8733
+ inlineChars: 8e3,
8734
+ referenceBytes: 2 * 1024 * 1024,
8735
+ taskBytes: 10 * 1024 * 1024,
8736
+ paths: 50,
8737
+ pathChars: 1024
8738
+ };
8739
+ var attachmentFormats = ["diff", "code", "markdown", "text"];
8740
+ var attachmentSources = ["inline", "diff", "file"];
8741
+ var summary = external_exports.string().trim().min(1).max(ATTACHMENT_LIMITS.summaryChars, "Keep the summary to one sentence.").describe(
8742
+ "One sentence on what the attachment is and why the worker needs it."
8743
+ );
8744
+ var title = external_exports.string().trim().min(1).max(ATTACHMENT_LIMITS.titleChars).optional().describe("A short label. Set it only when the generated one isn't clear.");
8745
+ var projectPath = external_exports.string().min(1).max(ATTACHMENT_LIMITS.pathChars);
8746
+ var inlineAttachment = external_exports.strictObject({
8747
+ source: external_exports.literal("inline"),
8748
+ summary,
8749
+ title,
8750
+ format: external_exports.enum(attachmentFormats),
8751
+ text: external_exports.string().min(1).max(
8752
+ ATTACHMENT_LIMITS.inlineChars,
8753
+ 'Inline text is limited to 8,000 characters. Attach project content by reference with { source: "file", path } or { source: "diff" }, or save the content to a project file and attach that.'
8754
+ ).describe("Short content that exists only in the chat."),
8755
+ path: projectPath.optional().describe("A label that picks highlighting. The service never reads it.")
8756
+ });
8757
+ var diffAttachment = external_exports.strictObject({
8758
+ source: external_exports.literal("diff"),
8759
+ summary,
8760
+ title,
8761
+ paths: external_exports.array(projectPath).min(1).max(ATTACHMENT_LIMITS.paths).optional().describe("Limit the diff to these project paths.")
8762
+ });
8763
+ var fileAttachment = external_exports.strictObject({
8764
+ source: external_exports.literal("file"),
8765
+ path: projectPath.describe("A file in the project folder."),
8766
+ summary,
8767
+ title,
8768
+ start_line: external_exports.number().int().positive().optional(),
8769
+ end_line: external_exports.number().int().positive().optional()
8770
+ }).refine(
8771
+ (a) => a.start_line === void 0 || a.end_line === void 0 || a.start_line <= a.end_line,
8772
+ { message: "start_line must not be after end_line", path: ["end_line"] }
8773
+ );
8774
+ var attachmentInputSchema = external_exports.discriminatedUnion("source", [
8775
+ inlineAttachment,
8776
+ diffAttachment,
8777
+ fileAttachment
8778
+ ]);
8779
+ var attachmentsSchema = external_exports.array(attachmentInputSchema).max(ATTACHMENT_LIMITS.count).optional().describe(
8780
+ 'Material the worker needs, which it reads from files. Prefer references for anything in the project, regardless of size: { source: "file", path, start_line?, end_line? }, or { source: "diff", paths? } for the uncommitted changes against HEAD including untracked files. Inline { source: "inline", format, text } is only for short content that exists only in this chat, such as decisions or notes. Every item needs a one-sentence summary.'
8781
+ );
8782
+ var ATTACHMENT_PAGE_BYTES = 512 * 1024;
8783
+
7431
8784
  // src/shared/tasks/reasoning.ts
8785
+ init_define_EXTENSION_BUILD_INFO();
7432
8786
  var reasoningLevels = [
7433
8787
  "none",
7434
8788
  "minimal",
@@ -7466,7 +8820,7 @@ var providerOptionsSchema = external_exports.record(
7466
8820
  );
7467
8821
  var startSchema = external_exports.object({
7468
8822
  provider_options: providerOptionsSchema.optional().describe(
7469
- "Provider-owned options, isolated under the selected provider ID and validated by that provider."
8823
+ "Provider-owned options, isolated under the selected provider ID and validated by that provider. Claude takes permission_mode, approval_decider and sandbox. sandbox true runs Bash in Claude Code's sandbox. Only the user can set it false when settings turn it on."
7470
8824
  ),
7471
8825
  approval_mode: approvalModeSchema.optional().describe(
7472
8826
  "Whole-execution approval policy for providers that support it. Model calls cannot increase approval authority."
@@ -7475,22 +8829,19 @@ var startSchema = external_exports.object({
7475
8829
  "Worker provider id from list_workers; only enabled providers can run."
7476
8830
  ),
7477
8831
  worker_profile: external_exports.enum(roles).default("reviewer").describe(
7478
- "reviewer, researcher and security_reviewer are read-only in either workspace. Other profiles can edit their workspace."
8832
+ "reviewer, researcher and security_reviewer start in plan mode, which asks before editing, unless provider_options.claude.permission_mode names another mode. Other profiles can edit their workspace."
7479
8833
  ),
7480
8834
  model: modelNameSchema.optional().describe(
7481
8835
  "Model ID or provider alias. Blank inherits configured defaults."
7482
8836
  ),
7483
- reasoning_effort: reasoningSchema.optional().describe("Reasoning effort; default inherits configured defaults."),
8837
+ reasoning_effort: reasoningSchema.optional().describe("Reasoning. The default inherits configured defaults."),
7484
8838
  description: external_exports.string().min(1).max(2e4).describe("The full task instructions and details for the worker."),
7485
8839
  repository: external_exports.string().min(1).describe(
7486
8840
  "Explicit absolute project folder from list_projects or get_current_project. Starting a task for the chat's unregistered Git root registers it when the user allows."
7487
8841
  ),
7488
8842
  revision: external_exports.string().default("HEAD"),
7489
8843
  conversation_id: external_exports.string().optional(),
7490
- depends_on: external_exports.array(external_exports.string()).max(50).default([]).describe("Task IDs that must finish before this task starts."),
7491
- context: external_exports.array(external_exports.string().max(2e4)).max(20).default([]).describe(
7492
- "Bounded excerpts the worker needs, such as a diff or file sections. Conversation history is not copied."
7493
- ),
8844
+ attachments: attachmentsSchema,
7494
8845
  workspace_strategy: external_exports.enum(["worktree", "current_repo"]).default("current_repo").describe(
7495
8846
  "current_repo uses the approved project folder directly, including uncommitted files, and requires revision HEAD. worktree creates an isolated checkout at revision without uncommitted files and needs a Git repository with at least one commit. Use it for isolated or parallel edits."
7496
8847
  ),
@@ -7504,6 +8855,13 @@ var startSchema = external_exports.object({
7504
8855
  max_tokens: external_exports.number().int().positive().optional()
7505
8856
  }).default({ max_runtime_minutes: null, max_cost_usd: null })
7506
8857
  });
8858
+ function assertNoLegacyContext(input) {
8859
+ if (input && typeof input === "object" && Object.hasOwn(input, "context")) {
8860
+ throw new AttachmentError(
8861
+ "context was replaced by attachments. Pass project content by reference and chat-only notes inline."
8862
+ );
8863
+ }
8864
+ }
7507
8865
  var statuses = [
7508
8866
  "queued",
7509
8867
  "starting",
@@ -7522,7 +8880,186 @@ function pendingInputKind(input) {
7522
8880
  return input.kind;
7523
8881
  }
7524
8882
 
8883
+ // src/service/platform/database/decode.ts
8884
+ init_define_EXTENSION_BUILD_INFO();
8885
+ function checkStored(schema, value, record) {
8886
+ const result = schema.safeParse(value);
8887
+ if (!result.success) {
8888
+ throw new Error(
8889
+ `Stored ${record} is malformed: ${external_exports.prettifyError(result.error)}`
8890
+ );
8891
+ }
8892
+ return result.data;
8893
+ }
8894
+ function decodeStored(schema, json, record) {
8895
+ let value;
8896
+ try {
8897
+ value = JSON.parse(json);
8898
+ } catch (error) {
8899
+ throw new Error(`Stored ${record} is not valid JSON`, { cause: error });
8900
+ }
8901
+ return checkStored(schema, value, record);
8902
+ }
8903
+
8904
+ // src/service/features/tasks/storage/stored.ts
8905
+ var eventRowSchema = createSelectSchema(events).omit({
8906
+ response_ref: true,
8907
+ original_response: true,
8908
+ chat: true
8909
+ });
8910
+ var eventDataSchema = external_exports.record(external_exports.string(), external_exports.unknown());
8911
+ var sender = external_exports.enum(["user", "parent"]);
8912
+ var message = external_exports.looseObject({
8913
+ id: external_exports.string(),
8914
+ message: external_exports.string(),
8915
+ from: sender
8916
+ });
8917
+ var storedTaskSchema = external_exports.looseObject({
8918
+ id: external_exports.string().min(1),
8919
+ owner: external_exports.string().min(1),
8920
+ title: external_exports.string(),
8921
+ description: external_exports.string(),
8922
+ provider: external_exports.string(),
8923
+ provider_options: providerOptionsSchema.optional(),
8924
+ approval_mode: approvalModeSchema.optional(),
8925
+ worker_profile: external_exports.enum(roles),
8926
+ repository: external_exports.string(),
8927
+ revision: external_exports.string(),
8928
+ workspace_strategy: external_exports.enum(["worktree", "current_repo"]),
8929
+ no_git: external_exports.literal(true).optional(),
8930
+ workspace_fallback: external_exports.enum(["no_git", "no_commits"]).optional(),
8931
+ context: external_exports.array(external_exports.string()).optional(),
8932
+ budget: external_exports.looseObject({
8933
+ max_runtime_minutes: external_exports.number().nullable(),
8934
+ max_cost_usd: external_exports.number().nullable(),
8935
+ max_tokens: external_exports.number().optional()
8936
+ }),
8937
+ budget_raised_for_turn: external_exports.looseObject({
8938
+ turn: external_exports.number().int().nonnegative(),
8939
+ cost: external_exports.literal(true).optional(),
8940
+ runtime: external_exports.literal(true).optional()
8941
+ }).optional(),
8942
+ created_by: sender,
8943
+ status: external_exports.enum(statuses),
8944
+ error_code: external_exports.string().optional(),
8945
+ created_at: external_exports.string(),
8946
+ updated_at: external_exports.string(),
8947
+ pending_input: external_exports.looseObject({
8948
+ id: external_exports.string(),
8949
+ tool: external_exports.string(),
8950
+ kind: external_exports.enum(["question", "permission"]),
8951
+ input: external_exports.record(external_exports.string(), external_exports.unknown())
8952
+ }).optional(),
8953
+ profile_instructions: external_exports.string().optional(),
8954
+ instructions_sent: external_exports.number().int().nonnegative(),
8955
+ pending_steers: external_exports.array(message),
8956
+ queue: external_exports.array(
8957
+ message.extend({
8958
+ delivery: external_exports.enum(deliveries),
8959
+ recorded: external_exports.boolean().optional()
8960
+ })
8961
+ ),
8962
+ turn: external_exports.number().int().nonnegative(),
8963
+ runtime_ms: external_exports.number().nonnegative()
8964
+ });
8965
+ function decodeTask(id, body) {
8966
+ return decodeStored(storedTaskSchema, body, `task ${id}`);
8967
+ }
8968
+ function decodeEvent(row) {
8969
+ const stored = checkStored(eventRowSchema, row, `event ${row.id}`);
8970
+ const event = {
8971
+ ...stored,
8972
+ data: decodeStored(eventDataSchema, stored.data, `event ${stored.id}`)
8973
+ };
8974
+ return decodedEvent(event);
8975
+ }
8976
+
8977
+ // src/service/features/tasks/storage/task-rows.ts
8978
+ init_define_EXTENSION_BUILD_INFO();
8979
+
8980
+ // src/shared/tasks/conversation/unread.ts
8981
+ init_define_EXTENSION_BUILD_INFO();
8982
+ var READ_EVENTS = [
8983
+ "agent.message",
8984
+ "agent.reply",
8985
+ "task.turn_ended",
8986
+ "task.failed",
8987
+ "agent.input_required"
8988
+ ];
8989
+ var isUnread = (latest, mark) => Boolean(mark?.unread) || latest > (mark?.through ?? 0);
8990
+
8991
+ // src/service/features/tasks/storage/task-rows.ts
8992
+ var archivedFilters = ["exclude", "include", "only"];
8993
+ var archived = sql`exists (select 1 from ${taskArchive} where ${taskArchive.task_id} = ${tasks.id})`;
8994
+ var readEventTypes = sql.join(
8995
+ READ_EVENTS.map((type) => sql`${type}`),
8996
+ sql`, `
8997
+ );
8998
+ var readCompleted = sql`${tasks.status} = 'completed' and coalesce((select max(read_event.id) from ${events} read_event where read_event.task_id = ${tasks.id} and read_event.type in (${readEventTypes})), 0) <= coalesce((select iif(${taskRead.unread}, -1, ${taskRead.through}) from ${taskRead} where ${taskRead.task_id} = ${tasks.id}), 0)`;
8999
+ function taskFilters(owner, filters) {
9000
+ const matching = and(
9001
+ filters.conversation === void 0 ? void 0 : eq(tasks.conversation_id, filters.conversation),
9002
+ filters.repository === void 0 ? void 0 : eq(
9003
+ sql`json_extract(${tasks.body}, '$.repository')`,
9004
+ filters.repository
9005
+ ),
9006
+ filters.archived === "only" ? archived : void 0,
9007
+ filters.archived === "exclude" ? not(archived) : void 0,
9008
+ filters.ids === void 0 ? void 0 : inArray(tasks.id, [...filters.ids])
9009
+ );
9010
+ return and(
9011
+ eq(tasks.owner, owner),
9012
+ matching && filters.include?.length ? or(inArray(tasks.id, filters.include), matching) : matching
9013
+ );
9014
+ }
9015
+ function readCompletedFlags(orm, where, order) {
9016
+ return orm.select({
9017
+ id: tasks.id,
9018
+ repository: sql`json_extract(${tasks.body}, '$.repository')`,
9019
+ readCompleted: sql`${readCompleted}`.mapWith(Boolean)
9020
+ }).from(tasks).where(where).orderBy(order).all();
9021
+ }
9022
+ function taskExists(orm, id) {
9023
+ return !!orm.select({ id: tasks.id }).from(tasks).where(eq(tasks.id, id)).get();
9024
+ }
9025
+ function readTasks(orm, where, order, limit) {
9026
+ const query = orm.select({ id: tasks.id, body: tasks.body }).from(tasks).where(where).orderBy(...order ? [order] : []);
9027
+ return (limit === void 0 ? query : query.limit(limit)).all().map((row) => decodeTask(row.id, row.body));
9028
+ }
9029
+ function newestEvent(orm, types) {
9030
+ const latest = alias(events, "latest");
9031
+ const id = orm.select({ id: max(latest.id) }).from(latest).where(and(eq(latest.task_id, tasks.id), inArray(latest.type, types)));
9032
+ return sql`(${id})`;
9033
+ }
9034
+ function readStates(orm, where) {
9035
+ const rows = orm.select({
9036
+ id: tasks.id,
9037
+ through: taskRead.through,
9038
+ unread: taskRead.unread,
9039
+ latest: newestEvent(orm, READ_EVENTS)
9040
+ }).from(tasks).leftJoin(taskRead, eq(taskRead.task_id, tasks.id)).where(where).all();
9041
+ return new Map(
9042
+ rows.map((row) => {
9043
+ const mark = row.through === null ? void 0 : { through: row.through, unread: Boolean(row.unread) };
9044
+ return [
9045
+ row.id,
9046
+ {
9047
+ unread: isUnread(row.latest ?? 0, mark),
9048
+ through: mark?.through ?? 0
9049
+ }
9050
+ ];
9051
+ })
9052
+ );
9053
+ }
9054
+ function latestEvents(orm, where, type) {
9055
+ const rows = orm.select(eventColumns).from(tasks).innerJoin(events, eq(events.id, newestEvent(orm, [type]))).where(where).all();
9056
+ return new Map(rows.map((row) => [row.task_id, decodeEvent(row)]));
9057
+ }
9058
+
7525
9059
  export {
9060
+ isBudgetFailure,
9061
+ failureMessage,
9062
+ PolicyRejectedError,
7526
9063
  errorCategory,
7527
9064
  JsonlWriter,
7528
9065
  configureLogging,
@@ -7533,26 +9070,15 @@ export {
7533
9070
  logError,
7534
9071
  flushLogs,
7535
9072
  entityKind,
7536
- is,
7537
9073
  DrizzleQueryError,
7538
- isTable,
7539
- getTableName,
7540
- Column,
7541
- getColumnTable,
7542
- isView,
7543
- SQL,
7544
9074
  sql,
7545
9075
  jitCompatCheck,
7546
- getColumns,
7547
- isWithEnum,
7548
- CONSTANTS,
7549
- extractExtendedColumnType,
7550
9076
  DefaultLogger,
7551
9077
  NoopLogger,
7552
9078
  eq,
7553
9079
  and,
7554
- or,
7555
9080
  gt,
9081
+ gte,
7556
9082
  lt,
7557
9083
  lte,
7558
9084
  inArray,
@@ -7560,6 +9086,7 @@ export {
7560
9086
  notExists,
7561
9087
  asc,
7562
9088
  desc,
9089
+ count,
7563
9090
  max,
7564
9091
  defaultPort,
7565
9092
  installRoot,
@@ -7568,11 +9095,12 @@ export {
7568
9095
  packageVersion,
7569
9096
  dataDirectory,
7570
9097
  databasePath,
7571
- git,
9098
+ gitBytes,
7572
9099
  gitRepositoryRoot,
7573
9100
  gitWorkTreeRoot,
7574
9101
  WORKTREE_NEEDS_GIT,
7575
9102
  gitState,
9103
+ pathSymlinks,
7576
9104
  within,
7577
9105
  Workspaces,
7578
9106
  castToText,
@@ -7584,8 +9112,6 @@ export {
7584
9112
  integer,
7585
9113
  text,
7586
9114
  sqliteTable,
7587
- index,
7588
- uniqueIndex,
7589
9115
  primaryKey,
7590
9116
  SQLiteDialect,
7591
9117
  SQLiteAsyncDatabase,
@@ -7596,16 +9122,46 @@ export {
7596
9122
  assertPlainFolderAllowed,
7597
9123
  Projects,
7598
9124
  reasoningLevels,
9125
+ AttachmentError,
9126
+ ATTACHMENT_LIMITS,
9127
+ attachmentFormats,
9128
+ attachmentSources,
9129
+ ATTACHMENT_PAGE_BYTES,
7599
9130
  roles,
7600
9131
  modelNameSchema,
7601
9132
  reasoningSchema,
7602
9133
  approvalModeSchema,
7603
9134
  approvalDeciderSchema,
7604
- providerOptionsSchema,
7605
9135
  startSchema,
7606
- statuses,
9136
+ assertNoLegacyContext,
7607
9137
  deliveries,
7608
9138
  budgetRaiseSchema,
7609
- pendingInputKind
7610
- };
7611
- //# sourceMappingURL=chunk-MOWBM7MZ.js.map
9139
+ pendingInputKind,
9140
+ eventPayload,
9141
+ now,
9142
+ createSelectSchema,
9143
+ checkStored,
9144
+ decodeStored,
9145
+ tasks,
9146
+ events,
9147
+ taskRead,
9148
+ parentSeen,
9149
+ taskArchive,
9150
+ taskMessages,
9151
+ sendReceipts,
9152
+ MESSAGE_EVENTS,
9153
+ conversation,
9154
+ chatItems,
9155
+ eventColumns,
9156
+ readOriginalResponse,
9157
+ insertEvent,
9158
+ decodeEvent,
9159
+ archivedFilters,
9160
+ taskFilters,
9161
+ readCompletedFlags,
9162
+ taskExists,
9163
+ readTasks,
9164
+ readStates,
9165
+ latestEvents
9166
+ };
9167
+ //# sourceMappingURL=chunk-36LESPFG.js.map