@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.
package/dist/cline.js CHANGED
@@ -31,7 +31,8 @@ function startBackgroundSeed(repoDir, opts = {}) {
31
31
  ],
32
32
  {
33
33
  detached: true,
34
- stdio: "ignore"
34
+ stdio: "ignore",
35
+ windowsHide: true
35
36
  }
36
37
  );
37
38
  child.on("error", () => {
@@ -71,14 +72,36 @@ function getProjectRootFromGit(directory) {
71
72
  const commonDir = execFileSync(
72
73
  "git",
73
74
  ["rev-parse", "--path-format=absolute", "--git-common-dir"],
74
- { cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
75
+ {
76
+ cwd: directory,
77
+ encoding: "utf-8",
78
+ stdio: ["ignore", "pipe", "ignore"],
79
+ timeout: 1e3,
80
+ windowsHide: true
81
+ }
75
82
  ).trim();
76
83
  if (!commonDir) return null;
77
- return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
84
+ if (basename(commonDir) === ".git") return dirname2(commonDir);
85
+ if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
86
+ return dirname2(commonDir);
87
+ }
88
+ return commonDir;
78
89
  } catch {
79
90
  return null;
80
91
  }
81
92
  }
93
+ function isBareRepository(commonDir) {
94
+ try {
95
+ return execFileSync("git", ["-C", commonDir, "rev-parse", "--is-bare-repository"], {
96
+ encoding: "utf-8",
97
+ stdio: ["ignore", "pipe", "ignore"],
98
+ timeout: 1e3,
99
+ env: { ...process.env, GIT_DIR: void 0, GIT_WORK_TREE: void 0 }
100
+ }).trim() === "true";
101
+ } catch {
102
+ return false;
103
+ }
104
+ }
82
105
  function projectNameOf(directory, sessionRoot) {
83
106
  return gitProjectName(directory, true, sessionRoot);
84
107
  }
@@ -319,7 +342,7 @@ var PAGE_TAXONOMY = [
319
342
  },
320
343
  {
321
344
  name: "Initiatives and enhancements",
322
- 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.",
345
+ 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.",
323
346
  tags: ["knowledge:feature-work"]
324
347
  }
325
348
  ];
@@ -328,9 +351,10 @@ function pagesFor(project) {
328
351
  return PAGE_TAXONOMY.map((page) => ({ ...page, source_query: page.source_query + scope }));
329
352
  }
330
353
  var PAGE_MAX_TOKENS = 4096;
354
+ var PAGE_TAGS_MATCH = "all";
331
355
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
332
356
  function buildPageTrigger(cfg = {}) {
333
- const base = { fact_types: PAGE_FACT_TYPES };
357
+ const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
334
358
  switch (cfg.pageTriggerType) {
335
359
  case "cron":
336
360
  return { ...base, refresh_cron: cfg.pageTriggerCron };
@@ -840,11 +864,20 @@ var HindsightClient = class {
840
864
  return;
841
865
  }
842
866
  if (r.status !== 409) created++;
843
- } else if (hit.description !== page.source_query) {
867
+ } else {
868
+ const sourceDrift = hit.description !== page.source_query;
869
+ const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
870
+ if (!sourceDrift && !triggerDrift) continue;
871
+ const patch = {};
872
+ if (sourceDrift) {
873
+ patch.source_query = page.source_query;
874
+ patch.tags = page.tags;
875
+ }
876
+ if (triggerDrift) patch.trigger = pageTrigger;
844
877
  const r = await this.req(
845
878
  "PATCH",
846
879
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
847
- { source_query: page.source_query, tags: page.tags }
880
+ patch
848
881
  );
849
882
  if ([404, 405, 501].includes(r.status)) {
850
883
  this.knowledgePagesSupported = false;
@@ -865,10 +898,17 @@ var HindsightClient = class {
865
898
  return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
866
899
  }
867
900
  /**
868
- * Active-path capture: register a major feature as a per-initiative page + a tagged marker memory.
869
- * New initiative → creates a page under the Initiatives folder tagged `relatedPageId:<pageId>`.
901
+ * Active-path capture: register a major feature as a per-initiative page + a marker memory.
902
+ * New initiative → creates a page under the Initiatives folder.
870
903
  * Update (relatesToPageId) → no new page; only a marker accruing to the existing page, so an
871
904
  * enhancement or a mid-work plan change lands on the initiative it belongs to.
905
+ *
906
+ * The marker carries its page id in two places, neither of them a tag (#3641):
907
+ * `metadata.relatedPageId` for provenance (visible on the document, and to a reflect loop that
908
+ * expands one), and a `[[page:<id>]]` link in the retain CONTEXT, which is the only one of the
909
+ * three channels a page synthesis actually reads — reflect's search results keep `context` and
910
+ * `tags` but strip `metadata` (`_UNREAD_RESULT_FIELDS`), and the id has no business in a tag
911
+ * vocabulary that exists to be matched with exact set-ops.
872
912
  */
873
913
  async captureInitiative(args) {
874
914
  let pageId = args.relatesToPageId;
@@ -891,20 +931,11 @@ var HindsightClient = class {
891
931
  const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
892
932
  const content = `${verb}: ${args.title}. ${args.summary}`;
893
933
  const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
894
- const tags = [
895
- .../* @__PURE__ */ new Set([
896
- ...args.stamp?.tags ?? [],
897
- "knowledge:feature-work",
898
- `relatedPageId:${pageId}`
899
- ])
900
- ];
901
- if (Object.keys(args.stamp?.metadata ?? {}).length) {
902
- await this.retain(content, "initiative marker", markerId, tags, "document", {
903
- metadata: args.stamp?.metadata
904
- });
905
- } else {
906
- await this.retain(content, "initiative marker", markerId, tags, "document");
907
- }
934
+ const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
935
+ const context = `initiative marker for [[page:${pageId}]]`;
936
+ await this.retain(content, context, markerId, tags, "document", {
937
+ metadata: { ...args.stamp?.metadata ?? {}, relatedPageId: pageId }
938
+ });
908
939
  return { page_id: pageId };
909
940
  }
910
941
  /** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
@@ -1225,7 +1256,11 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
1225
1256
  function hasRustToolchain() {
1226
1257
  if (process.platform !== "darwin") return true;
1227
1258
  try {
1228
- execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
1259
+ execFileSync2("cargo", ["--version"], {
1260
+ stdio: "pipe",
1261
+ timeout: 1e4,
1262
+ windowsHide: true
1263
+ });
1229
1264
  return true;
1230
1265
  } catch {
1231
1266
  return false;
@@ -1233,7 +1268,11 @@ function hasRustToolchain() {
1233
1268
  }
1234
1269
  function hasUvx() {
1235
1270
  try {
1236
- execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
1271
+ execFileSync2("uvx", ["--version"], {
1272
+ stdio: "pipe",
1273
+ timeout: 1e4,
1274
+ windowsHide: true
1275
+ });
1237
1276
  return true;
1238
1277
  } catch {
1239
1278
  return false;
@@ -1265,7 +1304,11 @@ function detectLlm(env = process.env) {
1265
1304
  }
1266
1305
  function onPath(bin) {
1267
1306
  try {
1268
- execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
1307
+ execFileSync2("which", [bin], {
1308
+ stdio: "pipe",
1309
+ timeout: 5e3,
1310
+ windowsHide: true
1311
+ });
1269
1312
  return true;
1270
1313
  } catch {
1271
1314
  return false;
@@ -1276,7 +1319,8 @@ function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
1276
1319
  const starter = join5(dirname4(fileURLToPath2(import.meta.url)), "daemon-start.js");
1277
1320
  const child = spawnFn("node", [starter, "--harness", harness], {
1278
1321
  detached: true,
1279
- stdio: "ignore"
1322
+ stdio: "ignore",
1323
+ windowsHide: true
1280
1324
  });
1281
1325
  child.on("error", () => {
1282
1326
  });
@@ -15851,7 +15895,11 @@ import { execFileSync as execFileSync4 } from "child_process";
15851
15895
  import { execFileSync as execFileSync3 } from "child_process";
15852
15896
  import { resolve } from "path";
15853
15897
  function git(repo, ...args) {
15854
- return execFileSync3("git", ["-C", repo, ...args], { encoding: "utf8", maxBuffer: 1 << 28 });
15898
+ return execFileSync3("git", ["-C", repo, ...args], {
15899
+ encoding: "utf8",
15900
+ maxBuffer: 1 << 28,
15901
+ windowsHide: true
15902
+ });
15855
15903
  }
15856
15904
  function repoNameOf(repo) {
15857
15905
  return projectNameOf(resolve(repo));
@@ -15899,9 +15947,9 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP fo
15899
15947
  - 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>").
15900
15948
  - 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.
15901
15949
  - 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).`;
15902
- 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";
15950
+ 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";
15903
15951
  function toolGuide(opts) {
15904
- return (opts?.reflectOnNewGoals ? REFLECT_ON_GOALS : "") + TOOL_GUIDE;
15952
+ return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE;
15905
15953
  }
15906
15954
  function buildKnowledgePreamble(pages, opts) {
15907
15955
  const body = pages.length ? `Knowledge pages currently in this repository:
@@ -16106,6 +16154,7 @@ function startCodebaseSurvey(repoDir, opts = {}) {
16106
16154
  cwd: repoDir,
16107
16155
  detached: true,
16108
16156
  stdio: "ignore",
16157
+ windowsHide: true,
16109
16158
  env: plan.env
16110
16159
  });
16111
16160
  child.on("error", () => {
@@ -16122,7 +16171,8 @@ var DEEPEN_DIFF_TARGET = 300;
16122
16171
  function commitCount(repoDir) {
16123
16172
  try {
16124
16173
  const out = execFileSync4("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
16125
- encoding: "utf8"
16174
+ encoding: "utf8",
16175
+ windowsHide: true
16126
16176
  });
16127
16177
  return Number(out.trim()) || 0;
16128
16178
  } catch {
@@ -16631,7 +16681,10 @@ async function gitSyncNote(args) {
16631
16681
  try {
16632
16682
  const { execFileSync: execFileSync5 } = await import("child_process");
16633
16683
  const n = Number(
16634
- execFileSync5("git", ["-C", cwd, "rev-list", "--count", "HEAD"], { encoding: "utf8" }).trim()
16684
+ execFileSync5("git", ["-C", cwd, "rev-list", "--count", "HEAD"], {
16685
+ encoding: "utf8",
16686
+ windowsHide: true
16687
+ }).trim()
16635
16688
  );
16636
16689
  if (n > 0) target = Math.min(DEEPEN_DIFF_TARGET, n);
16637
16690
  } catch {
@@ -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):
@@ -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
  }
@@ -160,7 +182,8 @@ function startBackgroundSeed(repoDir, opts = {}) {
160
182
  ],
161
183
  {
162
184
  detached: true,
163
- stdio: "ignore"
185
+ stdio: "ignore",
186
+ windowsHide: true
164
187
  }
165
188
  );
166
189
  child.on("error", () => {
@@ -304,7 +327,7 @@ var PAGE_TAXONOMY = [
304
327
  },
305
328
  {
306
329
  name: "Initiatives and enhancements",
307
- 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.",
330
+ 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.",
308
331
  tags: ["knowledge:feature-work"]
309
332
  }
310
333
  ];
@@ -313,9 +336,10 @@ function pagesFor(project) {
313
336
  return PAGE_TAXONOMY.map((page) => ({ ...page, source_query: page.source_query + scope }));
314
337
  }
315
338
  var PAGE_MAX_TOKENS = 4096;
339
+ var PAGE_TAGS_MATCH = "all";
316
340
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
317
341
  function buildPageTrigger(cfg = {}) {
318
- const base = { fact_types: PAGE_FACT_TYPES };
342
+ const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
319
343
  switch (cfg.pageTriggerType) {
320
344
  case "cron":
321
345
  return { ...base, refresh_cron: cfg.pageTriggerCron };
@@ -825,11 +849,20 @@ var HindsightClient = class {
825
849
  return;
826
850
  }
827
851
  if (r.status !== 409) created++;
828
- } else if (hit.description !== page.source_query) {
852
+ } else {
853
+ const sourceDrift = hit.description !== page.source_query;
854
+ const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
855
+ if (!sourceDrift && !triggerDrift) continue;
856
+ const patch = {};
857
+ if (sourceDrift) {
858
+ patch.source_query = page.source_query;
859
+ patch.tags = page.tags;
860
+ }
861
+ if (triggerDrift) patch.trigger = pageTrigger;
829
862
  const r = await this.req(
830
863
  "PATCH",
831
864
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
832
- { source_query: page.source_query, tags: page.tags }
865
+ patch
833
866
  );
834
867
  if ([404, 405, 501].includes(r.status)) {
835
868
  this.knowledgePagesSupported = false;
@@ -850,10 +883,17 @@ var HindsightClient = class {
850
883
  return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
851
884
  }
852
885
  /**
853
- * Active-path capture: register a major feature as a per-initiative page + a tagged marker memory.
854
- * New initiative → creates a page under the Initiatives folder tagged `relatedPageId:<pageId>`.
886
+ * Active-path capture: register a major feature as a per-initiative page + a marker memory.
887
+ * New initiative → creates a page under the Initiatives folder.
855
888
  * Update (relatesToPageId) → no new page; only a marker accruing to the existing page, so an
856
889
  * enhancement or a mid-work plan change lands on the initiative it belongs to.
890
+ *
891
+ * The marker carries its page id in two places, neither of them a tag (#3641):
892
+ * `metadata.relatedPageId` for provenance (visible on the document, and to a reflect loop that
893
+ * expands one), and a `[[page:<id>]]` link in the retain CONTEXT, which is the only one of the
894
+ * three channels a page synthesis actually reads — reflect's search results keep `context` and
895
+ * `tags` but strip `metadata` (`_UNREAD_RESULT_FIELDS`), and the id has no business in a tag
896
+ * vocabulary that exists to be matched with exact set-ops.
857
897
  */
858
898
  async captureInitiative(args) {
859
899
  let pageId = args.relatesToPageId;
@@ -876,20 +916,11 @@ var HindsightClient = class {
876
916
  const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
877
917
  const content = `${verb}: ${args.title}. ${args.summary}`;
878
918
  const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
879
- const tags = [
880
- .../* @__PURE__ */ new Set([
881
- ...args.stamp?.tags ?? [],
882
- "knowledge:feature-work",
883
- `relatedPageId:${pageId}`
884
- ])
885
- ];
886
- if (Object.keys(args.stamp?.metadata ?? {}).length) {
887
- await this.retain(content, "initiative marker", markerId, tags, "document", {
888
- metadata: args.stamp?.metadata
889
- });
890
- } else {
891
- await this.retain(content, "initiative marker", markerId, tags, "document");
892
- }
919
+ const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
920
+ const context = `initiative marker for [[page:${pageId}]]`;
921
+ await this.retain(content, context, markerId, tags, "document", {
922
+ metadata: { ...args.stamp?.metadata ?? {}, relatedPageId: pageId }
923
+ });
893
924
  return { page_id: pageId };
894
925
  }
895
926
  /** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
@@ -1199,9 +1230,9 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP fo
1199
1230
  - 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>").
1200
1231
  - 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.
1201
1232
  - 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).`;
1202
- 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";
1233
+ 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";
1203
1234
  function toolGuide(opts) {
1204
- return (opts?.reflectOnNewGoals ? REFLECT_ON_GOALS : "") + TOOL_GUIDE;
1235
+ return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE;
1205
1236
  }
1206
1237
  function buildKnowledgePreamble(pages, opts) {
1207
1238
  const body = pages.length ? `Knowledge pages currently in this repository:
@@ -1285,7 +1316,11 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
1285
1316
  function hasRustToolchain() {
1286
1317
  if (process.platform !== "darwin") return true;
1287
1318
  try {
1288
- execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
1319
+ execFileSync2("cargo", ["--version"], {
1320
+ stdio: "pipe",
1321
+ timeout: 1e4,
1322
+ windowsHide: true
1323
+ });
1289
1324
  return true;
1290
1325
  } catch {
1291
1326
  return false;
@@ -1293,7 +1328,11 @@ function hasRustToolchain() {
1293
1328
  }
1294
1329
  function hasUvx() {
1295
1330
  try {
1296
- execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
1331
+ execFileSync2("uvx", ["--version"], {
1332
+ stdio: "pipe",
1333
+ timeout: 1e4,
1334
+ windowsHide: true
1335
+ });
1297
1336
  return true;
1298
1337
  } catch {
1299
1338
  return false;
@@ -1325,7 +1364,11 @@ function detectLlm(env = process.env) {
1325
1364
  }
1326
1365
  function onPath(bin) {
1327
1366
  try {
1328
- execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
1367
+ execFileSync2("which", [bin], {
1368
+ stdio: "pipe",
1369
+ timeout: 5e3,
1370
+ windowsHide: true
1371
+ });
1329
1372
  return true;
1330
1373
  } catch {
1331
1374
  return false;
@@ -1336,7 +1379,8 @@ function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
1336
1379
  const starter = join6(dirname5(fileURLToPath2(import.meta.url)), "daemon-start.js");
1337
1380
  const child = spawnFn("node", [starter, "--harness", harness], {
1338
1381
  detached: true,
1339
- stdio: "ignore"
1382
+ stdio: "ignore",
1383
+ windowsHide: true
1340
1384
  });
1341
1385
  child.on("error", () => {
1342
1386
  });
@@ -1535,7 +1579,11 @@ import { readFileSync as readFileSync6 } from "fs";
1535
1579
  import { execFileSync as execFileSync3 } from "child_process";
1536
1580
  import { resolve } from "path";
1537
1581
  function git(repo, ...args) {
1538
- return execFileSync3("git", ["-C", repo, ...args], { encoding: "utf8", maxBuffer: 1 << 28 });
1582
+ return execFileSync3("git", ["-C", repo, ...args], {
1583
+ encoding: "utf8",
1584
+ maxBuffer: 1 << 28,
1585
+ windowsHide: true
1586
+ });
1539
1587
  }
1540
1588
  function gitHeadSha(dir) {
1541
1589
  try {
@@ -1746,6 +1794,7 @@ function startCodebaseSurvey(repoDir, opts = {}) {
1746
1794
  cwd: repoDir,
1747
1795
  detached: true,
1748
1796
  stdio: "ignore",
1797
+ windowsHide: true,
1749
1798
  env: plan.env
1750
1799
  });
1751
1800
  child.on("error", () => {
@@ -1812,7 +1861,10 @@ async function gitSyncNote(args) {
1812
1861
  try {
1813
1862
  const { execFileSync: execFileSync5 } = await import("child_process");
1814
1863
  const n = Number(
1815
- execFileSync5("git", ["-C", cwd, "rev-list", "--count", "HEAD"], { encoding: "utf8" }).trim()
1864
+ execFileSync5("git", ["-C", cwd, "rev-list", "--count", "HEAD"], {
1865
+ encoding: "utf8",
1866
+ windowsHide: true
1867
+ }).trim()
1816
1868
  );
1817
1869
  if (n > 0) target = Math.min(DEEPEN_DIFF_TARGET, n);
1818
1870
  } catch {