zapagent 1.14.13 → 1.14.15

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 (44) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +7 -3
  3. package/src/agent/buildAgentRuntime.ts +6 -1
  4. package/src/agent/goalPresentation.ts +43 -0
  5. package/src/agent/promptDiagnostics.ts +8 -1
  6. package/src/commands/dispatcher.ts +9 -3
  7. package/src/commands/status.ts +7 -32
  8. package/src/config.ts +7 -2
  9. package/src/goal-command.ts +12 -7
  10. package/src/goal-host.ts +2 -1
  11. package/src/goal-runner.ts +36 -6
  12. package/src/goal-session.ts +99 -0
  13. package/src/headless/goalPhase.ts +38 -9
  14. package/src/headless/runHeadless.ts +6 -2
  15. package/src/hooks/useAgentRunner.ts +48 -1
  16. package/src/hooks/useTurnDispatcher.ts +8 -0
  17. package/src/index.tsx +19 -3
  18. package/src/prompts/context.ts +4 -3
  19. package/src/prompts/registry.ts +4 -3
  20. package/src/prompts/required-sections.ts +26 -0
  21. package/src/prompts/sections/agents-md.ts +24 -11
  22. package/src/prompts/sections/concise.ts +2 -2
  23. package/src/prompts/sections/file-reading.ts +2 -2
  24. package/src/prompts/sections/identity.ts +2 -2
  25. package/src/prompts/sections/plan-discipline.ts +2 -2
  26. package/src/prompts/sections/safety.ts +1 -1
  27. package/src/prompts/sections/skills.ts +4 -3
  28. package/src/prompts/sections/system.ts +4 -3
  29. package/src/prompts/sections/tasks.ts +1 -1
  30. package/src/ui/slash-palette.tsx +1 -1
  31. package/zapsdk/agent/events.ts +3 -0
  32. package/zapsdk/agent/loop.ts +33 -62
  33. package/zapsdk/agent/output-text.ts +34 -0
  34. package/zapsdk/agent/prompt-output-guard.ts +138 -0
  35. package/zapsdk/agent/streaming-tool-executor.ts +16 -8
  36. package/zapsdk/agent/subagent-assembly.ts +1 -0
  37. package/zapsdk/builtin-tools/subagent.ts +4 -2
  38. package/zapsdk/merge/copy.ts +13 -4
  39. package/zapsdk/runtime/recovery-controller.ts +1 -0
  40. package/zapsdk/runtime/state-tracker.ts +2 -0
  41. package/zapsdk/runtime/state-types.ts +1 -0
  42. package/zapsdk/workspace/copy.ts +29 -4
  43. package/zapsdk/workspace/manager.ts +34 -3
  44. package/zapsdk/workspace/types.ts +2 -0
@@ -1,11 +1,12 @@
1
1
  import { execFile } from "node:child_process";
2
- import { randomUUID } from "node:crypto";
2
+ import { createHash, randomUUID } from "node:crypto";
3
3
  import {
4
4
  copyFile,
5
5
  lstat,
6
6
  mkdir,
7
7
  mkdtemp,
8
8
  realpath,
9
+ readFile,
9
10
  readlink,
10
11
  rm,
11
12
  symlink,
@@ -142,6 +143,8 @@ export class WorkspaceManager {
142
143
  private mode: "isolated-git" | "isolated-copy" = "isolated-git";
143
144
  private templatePath?: string;
144
145
  private baseOid?: string;
146
+ private sourceLinksHash?: string;
147
+ private sourceLinks: Record<string, string> = Object.create(null);
145
148
  private initializePromise?: Promise<void>;
146
149
  private artifacts = new Map<string, AgentArtifact>();
147
150
  private leases = new Map<string, WorkspaceLease>();
@@ -233,6 +236,7 @@ export class WorkspaceManager {
233
236
  repoPath,
234
237
  baseOid: this.baseOid,
235
238
  batchPath: this.batchRoot,
239
+ ...(this.sourceLinksHash ? { sourceLinksHash: this.sourceLinksHash } : {}),
236
240
  ...(privateGit ? { privateGit } : {}),
237
241
  };
238
242
  this.leases.set(lease.workspaceId, lease);
@@ -499,6 +503,19 @@ export class WorkspaceManager {
499
503
  this.batchRoot = realBatch;
500
504
  this.templatePath = snapshotPath;
501
505
  this.baseOid = input.leases[0].baseOid;
506
+ const sourceLinksHash = input.leases[0].sourceLinksHash;
507
+ if (input.leases.some(lease => lease.sourceLinksHash !== sourceLinksHash)) throw new Error("Source link baseline identity mismatch");
508
+ if (copy && sourceLinksHash) {
509
+ const sourceLinksPath = join(realBatch, "source-links.json");
510
+ const info = await lstat(sourceLinksPath);
511
+ if (!info.isFile() || info.isSymbolicLink() || info.size > 16 * 1024 * 1024) throw new Error("Unsafe source link baseline");
512
+ const bytes = await readFile(sourceLinksPath);
513
+ if (createHash("sha256").update(bytes).digest("hex") !== sourceLinksHash) throw new Error("Source link baseline was modified");
514
+ const links = JSON.parse(bytes.toString("utf8"));
515
+ const baseline = await scanCopyTree(snapshotPath);
516
+ if (!links || Array.isArray(links) || typeof links !== "object" || Object.entries(links).some(([path, target]) => baseline[path]?.kind !== "symlink" || typeof target !== "string")) throw new Error("Invalid source link baseline");
517
+ this.sourceLinks = links; this.sourceLinksHash = sourceLinksHash;
518
+ }
502
519
  this.initializePromise = Promise.resolve();
503
520
  for (const lease of input.leases) this.leases.set(lease.workspaceId, { ...lease });
504
521
  for (const artifact of input.artifacts) this.artifacts.set(artifact.artifactId, { ...artifact });
@@ -525,6 +542,10 @@ export class WorkspaceManager {
525
542
  return this.templatePath;
526
543
  }
527
544
 
545
+ originalSourceLink(path: string): string | undefined {
546
+ return Object.hasOwn(this.sourceLinks, path) ? this.sourceLinks[path] : undefined;
547
+ }
548
+
528
549
  rootRepoPath(): string {
529
550
  if (!this.repoRoot) throw new Error("Workspace snapshot is not initialized");
530
551
  return this.repoRoot;
@@ -557,6 +578,7 @@ export class WorkspaceManager {
557
578
  this.workspaceTempRoot = undefined;
558
579
  this.templatePath = undefined;
559
580
  this.baseOid = undefined;
581
+ this.sourceLinksHash = undefined; this.sourceLinks = Object.create(null);
560
582
  this.initializePromise = undefined;
561
583
  this.artifacts.clear();
562
584
  this.leases.clear();
@@ -575,6 +597,7 @@ export class WorkspaceManager {
575
597
  this.workspaceTempRoot = undefined;
576
598
  this.templatePath = undefined;
577
599
  this.baseOid = undefined;
600
+ this.sourceLinksHash = undefined; this.sourceLinks = Object.create(null);
578
601
  this.repoRoot = undefined;
579
602
  this.initializePromise = undefined;
580
603
  throw error;
@@ -631,9 +654,17 @@ export class WorkspaceManager {
631
654
  if (copyTreeOid(before) !== copyTreeOid(after)) throw new Error("Parent workspace changed during child Git capture");
632
655
  this.copyWithPrivateGit = { ownerDirectory, snapshotRepository: join(history, "repository.git") };
633
656
  }
634
- const tree = await scanCopyTree(this.repoRoot, true);
657
+ const links: Record<string, string> = Object.create(null);
658
+ const tree = await scanCopyTree(this.repoRoot, true, true, true, undefined, undefined, links);
635
659
  await materializeCopyTree(this.repoRoot, this.templatePath, tree);
636
- if (copyTreeOid(await scanCopyTree(this.repoRoot, true)) !== copyTreeOid(tree)) throw new Error("Copy workspace changed during snapshot");
660
+ const afterLinks: Record<string, string> = Object.create(null);
661
+ if (copyTreeOid(await scanCopyTree(this.repoRoot, true, true, true, undefined, undefined, afterLinks)) !== copyTreeOid(tree)
662
+ || JSON.stringify(links) !== JSON.stringify(afterLinks)) throw new Error("Copy workspace changed during snapshot");
663
+ if (Object.keys(links).length) {
664
+ const json = JSON.stringify(links);
665
+ await writeFile(join(this.batchRoot!, "source-links.json"), json, { flag: "wx", mode: 0o600 });
666
+ this.sourceLinks = links; this.sourceLinksHash = createHash("sha256").update(json).digest("hex");
667
+ }
637
668
  this.baseOid = copyTreeOid(tree);
638
669
  return;
639
670
  }
@@ -15,6 +15,8 @@ export interface WorkspaceLease {
15
15
  repoPath?: string;
16
16
  baseOid?: string;
17
17
  batchPath?: string;
18
+ /** Host-owned raw source-link baseline, outside every writable clone. */
19
+ sourceLinksHash?: string;
18
20
  /** Host-created private metadata, excluded from delivered file artifacts. */
19
21
  privateGit?: PrivateGitBinding;
20
22
  }