@vectorize-io/hindsight-coding-agents 0.4.0 → 0.4.2

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.
@@ -33,14 +33,36 @@ function getProjectRootFromGit(directory) {
33
33
  const commonDir = execFileSync(
34
34
  "git",
35
35
  ["rev-parse", "--path-format=absolute", "--git-common-dir"],
36
- { cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
36
+ {
37
+ cwd: directory,
38
+ encoding: "utf-8",
39
+ stdio: ["ignore", "pipe", "ignore"],
40
+ timeout: 1e3,
41
+ windowsHide: true
42
+ }
37
43
  ).trim();
38
44
  if (!commonDir) return null;
39
- return basename(commonDir) === ".git" ? dirname(commonDir) : commonDir;
45
+ if (basename(commonDir) === ".git") return dirname(commonDir);
46
+ if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
47
+ return dirname(commonDir);
48
+ }
49
+ return commonDir;
40
50
  } catch {
41
51
  return null;
42
52
  }
43
53
  }
54
+ function isBareRepository(commonDir) {
55
+ try {
56
+ return execFileSync("git", ["-C", commonDir, "rev-parse", "--is-bare-repository"], {
57
+ encoding: "utf-8",
58
+ stdio: ["ignore", "pipe", "ignore"],
59
+ timeout: 1e3,
60
+ env: { ...process.env, GIT_DIR: void 0, GIT_WORK_TREE: void 0 }
61
+ }).trim() === "true";
62
+ } catch {
63
+ return false;
64
+ }
65
+ }
44
66
  function projectNameOf(directory, sessionRoot) {
45
67
  return gitProjectName(directory, true, sessionRoot);
46
68
  }
@@ -292,7 +314,7 @@ var PAGE_TAXONOMY = [
292
314
  },
293
315
  {
294
316
  name: "Initiatives and enhancements",
295
- source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory carries a tag of the form `relatedPageId:<id>`, include a Markdown link `[[page:<id>]]` to that page in the summary, so each initiative links to its detailed page.",
317
+ source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory's context carries a `[[page:<id>]]` link, repeat that link in the summary of what it describes, so each initiative links to its detailed page.",
296
318
  tags: ["knowledge:feature-work"]
297
319
  }
298
320
  ];
@@ -301,9 +323,10 @@ function pagesFor(project) {
301
323
  return PAGE_TAXONOMY.map((page) => ({ ...page, source_query: page.source_query + scope }));
302
324
  }
303
325
  var PAGE_MAX_TOKENS = 4096;
326
+ var PAGE_TAGS_MATCH = "all";
304
327
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
305
328
  function buildPageTrigger(cfg = {}) {
306
- const base = { fact_types: PAGE_FACT_TYPES };
329
+ const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
307
330
  switch (cfg.pageTriggerType) {
308
331
  case "cron":
309
332
  return { ...base, refresh_cron: cfg.pageTriggerCron };
@@ -813,11 +836,20 @@ var HindsightClient = class {
813
836
  return;
814
837
  }
815
838
  if (r.status !== 409) created++;
816
- } else if (hit.description !== page.source_query) {
839
+ } else {
840
+ const sourceDrift = hit.description !== page.source_query;
841
+ const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
842
+ if (!sourceDrift && !triggerDrift) continue;
843
+ const patch = {};
844
+ if (sourceDrift) {
845
+ patch.source_query = page.source_query;
846
+ patch.tags = page.tags;
847
+ }
848
+ if (triggerDrift) patch.trigger = pageTrigger;
817
849
  const r = await this.req(
818
850
  "PATCH",
819
851
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
820
- { source_query: page.source_query, tags: page.tags }
852
+ patch
821
853
  );
822
854
  if ([404, 405, 501].includes(r.status)) {
823
855
  this.knowledgePagesSupported = false;
@@ -838,10 +870,17 @@ var HindsightClient = class {
838
870
  return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
839
871
  }
840
872
  /**
841
- * Active-path capture: register a major feature as a per-initiative page + a tagged marker memory.
842
- * New initiative → creates a page under the Initiatives folder tagged `relatedPageId:<pageId>`.
873
+ * Active-path capture: register a major feature as a per-initiative page + a marker memory.
874
+ * New initiative → creates a page under the Initiatives folder.
843
875
  * Update (relatesToPageId) → no new page; only a marker accruing to the existing page, so an
844
876
  * enhancement or a mid-work plan change lands on the initiative it belongs to.
877
+ *
878
+ * The marker carries its page id in two places, neither of them a tag (#3641):
879
+ * `metadata.relatedPageId` for provenance (visible on the document, and to a reflect loop that
880
+ * expands one), and a `[[page:<id>]]` link in the retain CONTEXT, which is the only one of the
881
+ * three channels a page synthesis actually reads — reflect's search results keep `context` and
882
+ * `tags` but strip `metadata` (`_UNREAD_RESULT_FIELDS`), and the id has no business in a tag
883
+ * vocabulary that exists to be matched with exact set-ops.
845
884
  */
846
885
  async captureInitiative(args) {
847
886
  let pageId = args.relatesToPageId;
@@ -864,20 +903,11 @@ var HindsightClient = class {
864
903
  const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
865
904
  const content = `${verb}: ${args.title}. ${args.summary}`;
866
905
  const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
867
- const tags = [
868
- .../* @__PURE__ */ new Set([
869
- ...args.stamp?.tags ?? [],
870
- "knowledge:feature-work",
871
- `relatedPageId:${pageId}`
872
- ])
873
- ];
874
- if (Object.keys(args.stamp?.metadata ?? {}).length) {
875
- await this.retain(content, "initiative marker", markerId, tags, "document", {
876
- metadata: args.stamp?.metadata
877
- });
878
- } else {
879
- await this.retain(content, "initiative marker", markerId, tags, "document");
880
- }
906
+ const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
907
+ const context = `initiative marker for [[page:${pageId}]]`;
908
+ await this.retain(content, context, markerId, tags, "document", {
909
+ metadata: { ...args.stamp?.metadata ?? {}, relatedPageId: pageId }
910
+ });
881
911
  return { page_id: pageId };
882
912
  }
883
913
  /** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
@@ -1386,7 +1416,11 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
1386
1416
  function hasRustToolchain() {
1387
1417
  if (process.platform !== "darwin") return true;
1388
1418
  try {
1389
- execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
1419
+ execFileSync2("cargo", ["--version"], {
1420
+ stdio: "pipe",
1421
+ timeout: 1e4,
1422
+ windowsHide: true
1423
+ });
1390
1424
  return true;
1391
1425
  } catch {
1392
1426
  return false;
@@ -1394,7 +1428,11 @@ function hasRustToolchain() {
1394
1428
  }
1395
1429
  function hasUvx() {
1396
1430
  try {
1397
- execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
1431
+ execFileSync2("uvx", ["--version"], {
1432
+ stdio: "pipe",
1433
+ timeout: 1e4,
1434
+ windowsHide: true
1435
+ });
1398
1436
  return true;
1399
1437
  } catch {
1400
1438
  return false;
@@ -1426,7 +1464,11 @@ function detectLlm(env = process.env) {
1426
1464
  }
1427
1465
  function onPath(bin) {
1428
1466
  try {
1429
- execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
1467
+ execFileSync2("which", [bin], {
1468
+ stdio: "pipe",
1469
+ timeout: 5e3,
1470
+ windowsHide: true
1471
+ });
1430
1472
  return true;
1431
1473
  } catch {
1432
1474
  return false;
@@ -1437,7 +1479,8 @@ function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
1437
1479
  const starter = join6(dirname5(fileURLToPath2(import.meta.url)), "daemon-start.js");
1438
1480
  const child = spawnFn("node", [starter, "--harness", harness], {
1439
1481
  detached: true,
1440
- stdio: "ignore"
1482
+ stdio: "ignore",
1483
+ windowsHide: true
1441
1484
  });
1442
1485
  child.on("error", () => {
1443
1486
  });
@@ -592,7 +592,11 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
592
592
  function hasRustToolchain() {
593
593
  if (process.platform !== "darwin") return true;
594
594
  try {
595
- execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
595
+ execFileSync2("cargo", ["--version"], {
596
+ stdio: "pipe",
597
+ timeout: 1e4,
598
+ windowsHide: true
599
+ });
596
600
  return true;
597
601
  } catch {
598
602
  return false;
@@ -600,7 +604,11 @@ function hasRustToolchain() {
600
604
  }
601
605
  function hasUvx() {
602
606
  try {
603
- execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
607
+ execFileSync2("uvx", ["--version"], {
608
+ stdio: "pipe",
609
+ timeout: 1e4,
610
+ windowsHide: true
611
+ });
604
612
  return true;
605
613
  } catch {
606
614
  return false;
@@ -632,7 +640,11 @@ function detectLlm(env = process.env) {
632
640
  }
633
641
  function onPath(bin) {
634
642
  try {
635
- execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
643
+ execFileSync2("which", [bin], {
644
+ stdio: "pipe",
645
+ timeout: 5e3,
646
+ windowsHide: true
647
+ });
636
648
  return true;
637
649
  } catch {
638
650
  return false;
package/dist/deepen.js CHANGED
@@ -36,14 +36,36 @@ function getProjectRootFromGit(directory) {
36
36
  const commonDir = execFileSync(
37
37
  "git",
38
38
  ["rev-parse", "--path-format=absolute", "--git-common-dir"],
39
- { cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
39
+ {
40
+ cwd: directory,
41
+ encoding: "utf-8",
42
+ stdio: ["ignore", "pipe", "ignore"],
43
+ timeout: 1e3,
44
+ windowsHide: true
45
+ }
40
46
  ).trim();
41
47
  if (!commonDir) return null;
42
- return basename(commonDir) === ".git" ? dirname(commonDir) : commonDir;
48
+ if (basename(commonDir) === ".git") return dirname(commonDir);
49
+ if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
50
+ return dirname(commonDir);
51
+ }
52
+ return commonDir;
43
53
  } catch {
44
54
  return null;
45
55
  }
46
56
  }
57
+ function isBareRepository(commonDir) {
58
+ try {
59
+ return execFileSync("git", ["-C", commonDir, "rev-parse", "--is-bare-repository"], {
60
+ encoding: "utf-8",
61
+ stdio: ["ignore", "pipe", "ignore"],
62
+ timeout: 1e3,
63
+ env: { ...process.env, GIT_DIR: void 0, GIT_WORK_TREE: void 0 }
64
+ }).trim() === "true";
65
+ } catch {
66
+ return false;
67
+ }
68
+ }
47
69
  function projectNameOf(directory, sessionRoot) {
48
70
  return gitProjectName(directory, true, sessionRoot);
49
71
  }
@@ -237,7 +259,7 @@ var PAGE_TAXONOMY = [
237
259
  },
238
260
  {
239
261
  name: "Initiatives and enhancements",
240
- source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory carries a tag of the form `relatedPageId:<id>`, include a Markdown link `[[page:<id>]]` to that page in the summary, so each initiative links to its detailed page.",
262
+ source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory's context carries a `[[page:<id>]]` link, repeat that link in the summary of what it describes, so each initiative links to its detailed page.",
241
263
  tags: ["knowledge:feature-work"]
242
264
  }
243
265
  ];
@@ -246,9 +268,10 @@ function pagesFor(project) {
246
268
  return PAGE_TAXONOMY.map((page) => ({ ...page, source_query: page.source_query + scope }));
247
269
  }
248
270
  var PAGE_MAX_TOKENS = 4096;
271
+ var PAGE_TAGS_MATCH = "all";
249
272
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
250
273
  function buildPageTrigger(cfg2 = {}) {
251
- const base = { fact_types: PAGE_FACT_TYPES };
274
+ const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
252
275
  switch (cfg2.pageTriggerType) {
253
276
  case "cron":
254
277
  return { ...base, refresh_cron: cfg2.pageTriggerCron };
@@ -758,11 +781,20 @@ var HindsightClient = class {
758
781
  return;
759
782
  }
760
783
  if (r.status !== 409) created++;
761
- } else if (hit.description !== page.source_query) {
784
+ } else {
785
+ const sourceDrift = hit.description !== page.source_query;
786
+ const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
787
+ if (!sourceDrift && !triggerDrift) continue;
788
+ const patch = {};
789
+ if (sourceDrift) {
790
+ patch.source_query = page.source_query;
791
+ patch.tags = page.tags;
792
+ }
793
+ if (triggerDrift) patch.trigger = pageTrigger;
762
794
  const r = await this.req(
763
795
  "PATCH",
764
796
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
765
- { source_query: page.source_query, tags: page.tags }
797
+ patch
766
798
  );
767
799
  if ([404, 405, 501].includes(r.status)) {
768
800
  this.knowledgePagesSupported = false;
@@ -783,10 +815,17 @@ var HindsightClient = class {
783
815
  return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
784
816
  }
785
817
  /**
786
- * Active-path capture: register a major feature as a per-initiative page + a tagged marker memory.
787
- * New initiative → creates a page under the Initiatives folder tagged `relatedPageId:<pageId>`.
818
+ * Active-path capture: register a major feature as a per-initiative page + a marker memory.
819
+ * New initiative → creates a page under the Initiatives folder.
788
820
  * Update (relatesToPageId) → no new page; only a marker accruing to the existing page, so an
789
821
  * enhancement or a mid-work plan change lands on the initiative it belongs to.
822
+ *
823
+ * The marker carries its page id in two places, neither of them a tag (#3641):
824
+ * `metadata.relatedPageId` for provenance (visible on the document, and to a reflect loop that
825
+ * expands one), and a `[[page:<id>]]` link in the retain CONTEXT, which is the only one of the
826
+ * three channels a page synthesis actually reads — reflect's search results keep `context` and
827
+ * `tags` but strip `metadata` (`_UNREAD_RESULT_FIELDS`), and the id has no business in a tag
828
+ * vocabulary that exists to be matched with exact set-ops.
790
829
  */
791
830
  async captureInitiative(args) {
792
831
  let pageId = args.relatesToPageId;
@@ -809,20 +848,11 @@ var HindsightClient = class {
809
848
  const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
810
849
  const content = `${verb}: ${args.title}. ${args.summary}`;
811
850
  const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
812
- const tags = [
813
- .../* @__PURE__ */ new Set([
814
- ...args.stamp?.tags ?? [],
815
- "knowledge:feature-work",
816
- `relatedPageId:${pageId}`
817
- ])
818
- ];
819
- if (Object.keys(args.stamp?.metadata ?? {}).length) {
820
- await this.retain(content, "initiative marker", markerId, tags, "document", {
821
- metadata: args.stamp?.metadata
822
- });
823
- } else {
824
- await this.retain(content, "initiative marker", markerId, tags, "document");
825
- }
851
+ const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
852
+ const context = `initiative marker for [[page:${pageId}]]`;
853
+ await this.retain(content, context, markerId, tags, "document", {
854
+ metadata: { ...args.stamp?.metadata ?? {}, relatedPageId: pageId }
855
+ });
826
856
  return { page_id: pageId };
827
857
  }
828
858
  /** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
@@ -1209,7 +1239,11 @@ import { resolve } from "path";
1209
1239
  var US = "";
1210
1240
  var RS = "";
1211
1241
  function git(repo, ...args) {
1212
- return execFileSync2("git", ["-C", repo, ...args], { encoding: "utf8", maxBuffer: 1 << 28 });
1242
+ return execFileSync2("git", ["-C", repo, ...args], {
1243
+ encoding: "utf8",
1244
+ maxBuffer: 1 << 28,
1245
+ windowsHide: true
1246
+ });
1213
1247
  }
1214
1248
  function repoNameOf(repo) {
1215
1249
  return projectNameOf(resolve(repo));
@@ -1640,7 +1674,7 @@ async function main() {
1640
1674
  const shas = execFileSync4(
1641
1675
  "git",
1642
1676
  ["-C", REPO, "rev-list", `-n`, String(DEEPEN_DIFF_TARGET), "HEAD"],
1643
- { encoding: "utf8" }
1677
+ { encoding: "utf8", windowsHide: true }
1644
1678
  ).trim().split("\n").filter(Boolean).filter((sha) => !gitIds.has(`git:${sha}`)).slice(0, DIFF_BATCH);
1645
1679
  if (shas.length) {
1646
1680
  const repoName = repoNameOf(REPO);
@@ -33,14 +33,36 @@ function getProjectRootFromGit(directory) {
33
33
  const commonDir = execFileSync(
34
34
  "git",
35
35
  ["rev-parse", "--path-format=absolute", "--git-common-dir"],
36
- { cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
36
+ {
37
+ cwd: directory,
38
+ encoding: "utf-8",
39
+ stdio: ["ignore", "pipe", "ignore"],
40
+ timeout: 1e3,
41
+ windowsHide: true
42
+ }
37
43
  ).trim();
38
44
  if (!commonDir) return null;
39
- return basename(commonDir) === ".git" ? dirname(commonDir) : commonDir;
45
+ if (basename(commonDir) === ".git") return dirname(commonDir);
46
+ if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
47
+ return dirname(commonDir);
48
+ }
49
+ return commonDir;
40
50
  } catch {
41
51
  return null;
42
52
  }
43
53
  }
54
+ function isBareRepository(commonDir) {
55
+ try {
56
+ return execFileSync("git", ["-C", commonDir, "rev-parse", "--is-bare-repository"], {
57
+ encoding: "utf-8",
58
+ stdio: ["ignore", "pipe", "ignore"],
59
+ timeout: 1e3,
60
+ env: { ...process.env, GIT_DIR: void 0, GIT_WORK_TREE: void 0 }
61
+ }).trim() === "true";
62
+ } catch {
63
+ return false;
64
+ }
65
+ }
44
66
  var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
45
67
  function nearestExistingDir(directory) {
46
68
  let current2 = directory;
@@ -157,7 +179,8 @@ function startBackgroundSeed(repoDir, opts = {}) {
157
179
  ],
158
180
  {
159
181
  detached: true,
160
- stdio: "ignore"
182
+ stdio: "ignore",
183
+ windowsHide: true
161
184
  }
162
185
  );
163
186
  child.on("error", () => {
@@ -315,7 +338,7 @@ var PAGE_TAXONOMY = [
315
338
  },
316
339
  {
317
340
  name: "Initiatives and enhancements",
318
- source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory carries a tag of the form `relatedPageId:<id>`, include a Markdown link `[[page:<id>]]` to that page in the summary, so each initiative links to its detailed page.",
341
+ source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory's context carries a `[[page:<id>]]` link, repeat that link in the summary of what it describes, so each initiative links to its detailed page.",
319
342
  tags: ["knowledge:feature-work"]
320
343
  }
321
344
  ];
@@ -324,9 +347,10 @@ function pagesFor(project) {
324
347
  return PAGE_TAXONOMY.map((page) => ({ ...page, source_query: page.source_query + scope }));
325
348
  }
326
349
  var PAGE_MAX_TOKENS = 4096;
350
+ var PAGE_TAGS_MATCH = "all";
327
351
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
328
352
  function buildPageTrigger(cfg = {}) {
329
- const base = { fact_types: PAGE_FACT_TYPES };
353
+ const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
330
354
  switch (cfg.pageTriggerType) {
331
355
  case "cron":
332
356
  return { ...base, refresh_cron: cfg.pageTriggerCron };
@@ -836,11 +860,20 @@ var HindsightClient = class {
836
860
  return;
837
861
  }
838
862
  if (r.status !== 409) created++;
839
- } else if (hit.description !== page.source_query) {
863
+ } else {
864
+ const sourceDrift = hit.description !== page.source_query;
865
+ const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
866
+ if (!sourceDrift && !triggerDrift) continue;
867
+ const patch = {};
868
+ if (sourceDrift) {
869
+ patch.source_query = page.source_query;
870
+ patch.tags = page.tags;
871
+ }
872
+ if (triggerDrift) patch.trigger = pageTrigger;
840
873
  const r = await this.req(
841
874
  "PATCH",
842
875
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
843
- { source_query: page.source_query, tags: page.tags }
876
+ patch
844
877
  );
845
878
  if ([404, 405, 501].includes(r.status)) {
846
879
  this.knowledgePagesSupported = false;
@@ -861,10 +894,17 @@ var HindsightClient = class {
861
894
  return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
862
895
  }
863
896
  /**
864
- * Active-path capture: register a major feature as a per-initiative page + a tagged marker memory.
865
- * New initiative → creates a page under the Initiatives folder tagged `relatedPageId:<pageId>`.
897
+ * Active-path capture: register a major feature as a per-initiative page + a marker memory.
898
+ * New initiative → creates a page under the Initiatives folder.
866
899
  * Update (relatesToPageId) → no new page; only a marker accruing to the existing page, so an
867
900
  * enhancement or a mid-work plan change lands on the initiative it belongs to.
901
+ *
902
+ * The marker carries its page id in two places, neither of them a tag (#3641):
903
+ * `metadata.relatedPageId` for provenance (visible on the document, and to a reflect loop that
904
+ * expands one), and a `[[page:<id>]]` link in the retain CONTEXT, which is the only one of the
905
+ * three channels a page synthesis actually reads — reflect's search results keep `context` and
906
+ * `tags` but strip `metadata` (`_UNREAD_RESULT_FIELDS`), and the id has no business in a tag
907
+ * vocabulary that exists to be matched with exact set-ops.
868
908
  */
869
909
  async captureInitiative(args) {
870
910
  let pageId = args.relatesToPageId;
@@ -887,20 +927,11 @@ var HindsightClient = class {
887
927
  const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
888
928
  const content = `${verb}: ${args.title}. ${args.summary}`;
889
929
  const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
890
- const tags = [
891
- .../* @__PURE__ */ new Set([
892
- ...args.stamp?.tags ?? [],
893
- "knowledge:feature-work",
894
- `relatedPageId:${pageId}`
895
- ])
896
- ];
897
- if (Object.keys(args.stamp?.metadata ?? {}).length) {
898
- await this.retain(content, "initiative marker", markerId, tags, "document", {
899
- metadata: args.stamp?.metadata
900
- });
901
- } else {
902
- await this.retain(content, "initiative marker", markerId, tags, "document");
903
- }
930
+ const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
931
+ const context = `initiative marker for [[page:${pageId}]]`;
932
+ await this.retain(content, context, markerId, tags, "document", {
933
+ metadata: { ...args.stamp?.metadata ?? {}, relatedPageId: pageId }
934
+ });
904
935
  return { page_id: pageId };
905
936
  }
906
937
  /** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
@@ -1239,9 +1270,9 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP fo
1239
1270
  - hindsight_reflect(query) \u2014 when pages are too shallow and you need the WHY: deep reasoning over the repo's full memory for the past decision and exact values that explain a behavior or bug (slower \u2014 use deliberately, and credit results with a blockquote header "> \u{1F9E0} **From Hindsight memory** \u2014 <summary>").
1240
1271
  - hindsight_capture_initiative(title, summary) \u2014 right after the user approves a plan or finishes brainstorming a new feature/capability and you are about to start implementing (BEFORE you write any code), call this to record it as a tracked page; then call it AGAIN with relates_to_page_id set to that page whenever the goal, scope, or rationale materially changes mid-work, so the page tracks the current plan and not the opening one. Skip bug fixes, small tweaks, chores, and trivial course-corrections.
1241
1272
  - hindsight_ingest_document(title, content) \u2014 save an external document or durable notes/findings you want remembered (not the current conversation \u2014 that is captured automatically at session end).`;
1242
- var REFLECT_ON_GOALS = "- The user just set a NEW task or goal \u2192 call hindsight_reflect with that goal FIRST, before planning: no memory is injected automatically in this configuration, so this call is the only way past decisions, constraints, and failed attempts relevant to the goal reach you.\n";
1273
+ var PAGES_FIRST_ON_GOALS = "- The user just set a NEW task or goal \u2192 search the knowledge pages FIRST with hindsight_search_knowledge_pages. No synthesis is injected automatically in this configuration; call hindsight_reflect only when those pages are too shallow and deeper reasoning is needed.\n";
1243
1274
  function toolGuide(opts) {
1244
- return (opts?.reflectOnNewGoals ? REFLECT_ON_GOALS : "") + TOOL_GUIDE;
1275
+ return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE;
1245
1276
  }
1246
1277
  function buildRosterRefresh(pages, opts) {
1247
1278
  const rosterBlock = pages.length ? `Current Hindsight knowledge pages (may have changed):