@vectorize-io/hindsight-coding-agents 0.1.1 → 0.2.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.
@@ -31008,6 +31008,12 @@ function resolveConfig(raw = {}) {
31008
31008
  surveyBudgetUsd: raw.surveyBudgetUsd || 2,
31009
31009
  surveyRefreshCommits: raw.surveyRefreshCommits ?? 20,
31010
31010
  gitIngest: ["message", "full", "none"].includes(raw.gitIngest) ? raw.gitIngest : "message",
31011
+ // Hostile input is a config typo, not an attack: keep only string entries so a stray number or
31012
+ // nested object cannot reach the API as a tag and fail the whole retain.
31013
+ retainTags: Array.isArray(raw.retainTags) ? raw.retainTags.filter((t) => typeof t === "string" && t.trim() !== "") : [],
31014
+ retainMetadata: raw.retainMetadata && typeof raw.retainMetadata === "object" ? Object.fromEntries(
31015
+ Object.entries(raw.retainMetadata).filter(([, v]) => typeof v === "string")
31016
+ ) : {},
31011
31017
  banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
31012
31018
  logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info"
31013
31019
  };
@@ -31061,7 +31067,10 @@ var ENV_KEYS = {
31061
31067
  surveyBudgetUsd: "HINDSIGHT_SURVEY_BUDGET_USD",
31062
31068
  surveyRefreshCommits: "HINDSIGHT_SURVEY_REFRESH_COMMITS",
31063
31069
  logLevel: "HINDSIGHT_LOG_LEVEL",
31064
- gitIngest: "HINDSIGHT_GIT_INGEST"
31070
+ gitIngest: "HINDSIGHT_GIT_INGEST",
31071
+ // Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
31072
+ // a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
31073
+ retainTags: "HINDSIGHT_RETAIN_TAGS"
31065
31074
  };
31066
31075
  var ENV_BOOLEANS = /* @__PURE__ */ new Set([
31067
31076
  "dynamicBankId",
@@ -31072,6 +31081,7 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
31072
31081
  "autoSeed",
31073
31082
  "codebaseSurvey"
31074
31083
  ]);
31084
+ var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
31075
31085
  var ENV_NUMBERS = /* @__PURE__ */ new Set([
31076
31086
  "apiPort",
31077
31087
  "daemonIdleTimeout",
@@ -31089,6 +31099,9 @@ function readEnvConfig(env = process.env) {
31089
31099
  if (value === void 0 || value.trim() === "") continue;
31090
31100
  if (ENV_BOOLEANS.has(key)) {
31091
31101
  out[key] = ["1", "true", "yes", "on"].includes(value.trim().toLowerCase());
31102
+ } else if (ENV_LISTS.has(key)) {
31103
+ const items = value.split(",").map((v) => v.trim()).filter(Boolean);
31104
+ if (items.length) out[key] = items;
31092
31105
  } else if (ENV_NUMBERS.has(key)) {
31093
31106
  const n = Number(value);
31094
31107
  if (Number.isFinite(n)) out[key] = n;
@@ -31138,9 +31151,25 @@ function resolvePartial(cfg, patch) {
31138
31151
  import { execFileSync } from "child_process";
31139
31152
  import { homedir as homedir2 } from "os";
31140
31153
  import { basename, dirname as dirname2, join as join3, normalize, sep } from "path";
31154
+
31155
+ // src/core/template.ts
31156
+ var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
31157
+ function applyTemplate(template, resolvers, what) {
31158
+ return template.replace(PLACEHOLDER, (_, name) => {
31159
+ const resolve2 = resolvers[name];
31160
+ if (!resolve2) {
31161
+ console.error(
31162
+ `hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
31163
+ );
31164
+ return "unknown";
31165
+ }
31166
+ return resolve2();
31167
+ });
31168
+ }
31169
+
31170
+ // src/core/bank.ts
31141
31171
  var DEFAULT_BANK_NAME = "coding";
31142
31172
  var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
31143
- var PLACEHOLDER = /\{([a-zA-Z]+)\}/g;
31144
31173
  function getProjectRootFromGit(directory) {
31145
31174
  if (!directory) return null;
31146
31175
  try {
@@ -31189,16 +31218,7 @@ function deriveBankId(config2, directory, harness = "coding") {
31189
31218
  channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
31190
31219
  user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
31191
31220
  };
31192
- return (config2.bankIdTemplate || DEFAULT_TEMPLATE).replace(PLACEHOLDER, (_, name) => {
31193
- const r = resolvers[name];
31194
- if (!r) {
31195
- console.error(
31196
- `hindsight: unknown bankIdTemplate placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
31197
- );
31198
- return "unknown";
31199
- }
31200
- return r();
31201
- });
31221
+ return applyTemplate(config2.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
31202
31222
  }
31203
31223
 
31204
31224
  // src/core/missions.ts
@@ -31322,11 +31342,32 @@ var CODING_BANK_TEMPLATE = {
31322
31342
  entities_allow_free_form: true
31323
31343
  }
31324
31344
  };
31345
+ var CODING_BANK_STRUCTURE = {
31346
+ version: "1",
31347
+ bank: {
31348
+ retain_strategies: RETAIN_STRATEGIES,
31349
+ entity_labels: [KNOWLEDGE_LABELS]
31350
+ }
31351
+ };
31325
31352
 
31326
31353
  // src/core/util.ts
31327
31354
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
31355
+ function semverGte(version2, min) {
31356
+ const parts = (v) => {
31357
+ const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
31358
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
31359
+ };
31360
+ const a = version2 ? parts(version2) : void 0;
31361
+ const b = parts(min);
31362
+ if (!a || !b) return false;
31363
+ for (let i = 0; i < 3; i++) {
31364
+ if (a[i] !== b[i]) return a[i] > b[i];
31365
+ }
31366
+ return true;
31367
+ }
31328
31368
 
31329
31369
  // src/core/hindsight.ts
31370
+ var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
31330
31371
  var KnowledgePagesUnavailableError = class extends Error {
31331
31372
  code = "knowledge_pages_unavailable";
31332
31373
  constructor() {
@@ -31335,6 +31376,7 @@ var KnowledgePagesUnavailableError = class extends Error {
31335
31376
  }
31336
31377
  };
31337
31378
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
31379
+ var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
31338
31380
  var HindsightClient = class {
31339
31381
  apiUrl;
31340
31382
  apiToken;
@@ -31343,6 +31385,8 @@ var HindsightClient = class {
31343
31385
  // async operation ids collected by retain(), for drain()
31344
31386
  /** Tri-state capability probe: unknown until the first page request, then cached. */
31345
31387
  knowledgePagesSupported;
31388
+ /** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
31389
+ idempotentRetain;
31346
31390
  log;
31347
31391
  constructor(o) {
31348
31392
  this.apiUrl = o.apiUrl.replace(/\/$/, "");
@@ -31371,7 +31415,8 @@ var HindsightClient = class {
31371
31415
  throw new Error(`${method} ${url2} -> ${r.status} ${await r.text()}`);
31372
31416
  return r;
31373
31417
  }
31374
- /** Retain one memory. Async by default: enqueue extraction server-side and collect its op-id for drain(). */
31418
+ /** Retain one memory. ALWAYS async: enqueue extraction server-side and collect its op-id for
31419
+ * drain(). Nothing in this plugin can afford to block a coding agent's hook on extraction. */
31375
31420
  async retain(content, context, documentId, tags, strategy, opts = {}) {
31376
31421
  const item = {
31377
31422
  content,
@@ -31382,14 +31427,36 @@ var HindsightClient = class {
31382
31427
  };
31383
31428
  if (opts.timestamp) item.timestamp = opts.timestamp;
31384
31429
  if (opts.metadata) item.metadata = opts.metadata;
31385
- const isAsync2 = opts.async !== false;
31386
- const r = await this.req("POST", this.bankUrl("/memories"), { items: [item], async: isAsync2 });
31387
- if (isAsync2) {
31388
- try {
31389
- const j = await r.json();
31390
- if (j.operation_id) this.opIds.push(j.operation_id);
31391
- } catch {
31392
- }
31430
+ if (opts.updateMode) item.update_mode = opts.updateMode;
31431
+ const body = { items: [item], async: true };
31432
+ if (opts.operationId) body.operation_id = opts.operationId;
31433
+ const r = await this.req("POST", this.bankUrl("/memories"), body);
31434
+ try {
31435
+ const j = await r.json();
31436
+ if (j.operation_id) this.opIds.push(j.operation_id);
31437
+ } catch {
31438
+ }
31439
+ }
31440
+ /**
31441
+ * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
31442
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
31443
+ * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
31444
+ */
31445
+ async supportsIdempotentRetain() {
31446
+ if (this.idempotentRetain === void 0) {
31447
+ this.idempotentRetain = await this.probeIdempotentRetain();
31448
+ this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
31449
+ }
31450
+ return this.idempotentRetain;
31451
+ }
31452
+ async probeIdempotentRetain() {
31453
+ try {
31454
+ const r = await this.req("GET", `${this.apiUrl}/version`);
31455
+ if (!r.ok) return false;
31456
+ const j = await r.json();
31457
+ return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
31458
+ } catch {
31459
+ return false;
31393
31460
  }
31394
31461
  }
31395
31462
  /**
@@ -31426,12 +31493,39 @@ var HindsightClient = class {
31426
31493
  await this.req("DELETE", this.bankUrl());
31427
31494
  this.log(`[bank] reset ${this.bank}`);
31428
31495
  }
31429
- await this.req("POST", this.bankUrl("/import"), CODING_BANK_TEMPLATE);
31496
+ const seeded = opts.reset ? false : await this.hasBankMissions();
31497
+ await this.req(
31498
+ "POST",
31499
+ this.bankUrl("/import"),
31500
+ seeded ? CODING_BANK_STRUCTURE : CODING_BANK_TEMPLATE
31501
+ );
31430
31502
  this.log(
31431
- `[bank] template applied to ${this.bank}: missions, entity_labels {knowledge}, strategies {git, gitlog, conversation, document}`
31503
+ seeded ? `[bank] structure applied to ${this.bank}: entity_labels {knowledge}, strategies {git, gitlog, conversation, document} \u2014 missions left as configured` : `[bank] template applied to ${this.bank}: missions, entity_labels {knowledge}, strategies {git, gitlog, conversation, document}`
31432
31504
  );
31433
31505
  await this.seedPages();
31434
31506
  }
31507
+ /**
31508
+ * Whether this bank already carries bank-level mission overrides — ours from an earlier seed, or
31509
+ * the user's own edit. Either way they are not ours to overwrite.
31510
+ *
31511
+ * Reads the bank-scoped OVERRIDES, not the resolved config, so inherited global defaults don't
31512
+ * read as "already set". A missing bank, or a deployment with the bank-config API switched off,
31513
+ * answers false: there is nothing to preserve, and without that API a user cannot set per-bank
31514
+ * missions in the first place.
31515
+ */
31516
+ async hasBankMissions() {
31517
+ try {
31518
+ const r = await this.req("GET", this.bankUrl("/config"));
31519
+ if (!r.ok) return false;
31520
+ const j = await r.json();
31521
+ return MISSION_FIELDS.some((f) => {
31522
+ const v = j.overrides?.[f];
31523
+ return typeof v === "string" && v.trim() !== "";
31524
+ });
31525
+ } catch {
31526
+ return false;
31527
+ }
31528
+ }
31435
31529
  /** Delete one document (cascades its memory units/links). Used by deepen's self-cleanup. */
31436
31530
  async deleteDocument(documentId) {
31437
31531
  await this.req("DELETE", this.bankUrl(`/documents/${encodeURIComponent(documentId)}`));
@@ -31677,8 +31771,7 @@ var HindsightClient = class {
31677
31771
  "initiative marker",
31678
31772
  markerId,
31679
31773
  ["knowledge:feature-work", `relatedPageId:${pageId}`],
31680
- "document",
31681
- { async: true }
31774
+ "document"
31682
31775
  );
31683
31776
  return { page_id: pageId };
31684
31777
  }
@@ -31937,7 +32030,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
31937
32030
  docId,
31938
32031
  ["source:upload", ...opts.harness ? [`harness:${opts.harness}`] : []],
31939
32032
  "document",
31940
- { async: true, metadata: opts.harness ? { harness: opts.harness } : void 0 }
32033
+ { metadata: opts.harness ? { harness: opts.harness } : void 0 }
31941
32034
  );
31942
32035
  return { ok: true, doc_id: docId };
31943
32036
  })
@@ -31947,7 +32040,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
31947
32040
 
31948
32041
  // src/mcp-server.ts
31949
32042
  function selectTools(cfg, client, bankId) {
31950
- return cfg.disabled ? [] : buildKnowledgeTools(client, bankId, { repoDir: process.cwd() });
32043
+ return cfg.disabled ? [] : buildKnowledgeTools(client, bankId, { repoDir: process.cwd(), harness: cfg.harness });
31951
32044
  }
31952
32045
  async function main() {
31953
32046
  const cwd = process.env.HINDSIGHT_MCP_PROJECT_CWD || process.cwd();
package/dist/status.js CHANGED
@@ -4,9 +4,25 @@
4
4
  import { execFileSync } from "child_process";
5
5
  import { homedir } from "os";
6
6
  import { basename, dirname, join, normalize, sep } from "path";
7
+
8
+ // src/core/template.ts
9
+ var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
10
+ function applyTemplate(template, resolvers, what) {
11
+ return template.replace(PLACEHOLDER, (_, name) => {
12
+ const resolve2 = resolvers[name];
13
+ if (!resolve2) {
14
+ console.error(
15
+ `hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
16
+ );
17
+ return "unknown";
18
+ }
19
+ return resolve2();
20
+ });
21
+ }
22
+
23
+ // src/core/bank.ts
7
24
  var DEFAULT_BANK_NAME = "coding";
8
25
  var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
9
- var PLACEHOLDER = /\{([a-zA-Z]+)\}/g;
10
26
  function getProjectRootFromGit(directory) {
11
27
  if (!directory) return null;
12
28
  try {
@@ -55,16 +71,7 @@ function deriveBankId(config, directory, harness = "coding") {
55
71
  channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
56
72
  user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
57
73
  };
58
- return (config.bankIdTemplate || DEFAULT_TEMPLATE).replace(PLACEHOLDER, (_, name) => {
59
- const r = resolvers[name];
60
- if (!r) {
61
- console.error(
62
- `hindsight: unknown bankIdTemplate placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
63
- );
64
- return "unknown";
65
- }
66
- return r();
67
- });
74
+ return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
68
75
  }
69
76
 
70
77
  // src/core/config.ts
@@ -118,6 +125,12 @@ function resolveConfig(raw = {}) {
118
125
  surveyBudgetUsd: raw.surveyBudgetUsd || 2,
119
126
  surveyRefreshCommits: raw.surveyRefreshCommits ?? 20,
120
127
  gitIngest: ["message", "full", "none"].includes(raw.gitIngest) ? raw.gitIngest : "message",
128
+ // Hostile input is a config typo, not an attack: keep only string entries so a stray number or
129
+ // nested object cannot reach the API as a tag and fail the whole retain.
130
+ retainTags: Array.isArray(raw.retainTags) ? raw.retainTags.filter((t) => typeof t === "string" && t.trim() !== "") : [],
131
+ retainMetadata: raw.retainMetadata && typeof raw.retainMetadata === "object" ? Object.fromEntries(
132
+ Object.entries(raw.retainMetadata).filter(([, v]) => typeof v === "string")
133
+ ) : {},
121
134
  banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
122
135
  logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info"
123
136
  };
@@ -171,7 +184,10 @@ var ENV_KEYS = {
171
184
  surveyBudgetUsd: "HINDSIGHT_SURVEY_BUDGET_USD",
172
185
  surveyRefreshCommits: "HINDSIGHT_SURVEY_REFRESH_COMMITS",
173
186
  logLevel: "HINDSIGHT_LOG_LEVEL",
174
- gitIngest: "HINDSIGHT_GIT_INGEST"
187
+ gitIngest: "HINDSIGHT_GIT_INGEST",
188
+ // Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
189
+ // a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
190
+ retainTags: "HINDSIGHT_RETAIN_TAGS"
175
191
  };
176
192
  var ENV_BOOLEANS = /* @__PURE__ */ new Set([
177
193
  "dynamicBankId",
@@ -182,6 +198,7 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
182
198
  "autoSeed",
183
199
  "codebaseSurvey"
184
200
  ]);
201
+ var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
185
202
  var ENV_NUMBERS = /* @__PURE__ */ new Set([
186
203
  "apiPort",
187
204
  "daemonIdleTimeout",
@@ -199,6 +216,9 @@ function readEnvConfig(env = process.env) {
199
216
  if (value === void 0 || value.trim() === "") continue;
200
217
  if (ENV_BOOLEANS.has(key)) {
201
218
  out[key] = ["1", "true", "yes", "on"].includes(value.trim().toLowerCase());
219
+ } else if (ENV_LISTS.has(key)) {
220
+ const items = value.split(",").map((v) => v.trim()).filter(Boolean);
221
+ if (items.length) out[key] = items;
202
222
  } else if (ENV_NUMBERS.has(key)) {
203
223
  const n = Number(value);
204
224
  if (Number.isFinite(n)) out[key] = n;
@@ -365,11 +385,32 @@ var CODING_BANK_TEMPLATE = {
365
385
  entities_allow_free_form: true
366
386
  }
367
387
  };
388
+ var CODING_BANK_STRUCTURE = {
389
+ version: "1",
390
+ bank: {
391
+ retain_strategies: RETAIN_STRATEGIES,
392
+ entity_labels: [KNOWLEDGE_LABELS]
393
+ }
394
+ };
368
395
 
369
396
  // src/core/util.ts
370
397
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
398
+ function semverGte(version, min) {
399
+ const parts = (v) => {
400
+ const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
401
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
402
+ };
403
+ const a = version ? parts(version) : void 0;
404
+ const b = parts(min);
405
+ if (!a || !b) return false;
406
+ for (let i = 0; i < 3; i++) {
407
+ if (a[i] !== b[i]) return a[i] > b[i];
408
+ }
409
+ return true;
410
+ }
371
411
 
372
412
  // src/core/hindsight.ts
413
+ var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
373
414
  var KnowledgePagesUnavailableError = class extends Error {
374
415
  code = "knowledge_pages_unavailable";
375
416
  constructor() {
@@ -378,6 +419,7 @@ var KnowledgePagesUnavailableError = class extends Error {
378
419
  }
379
420
  };
380
421
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
422
+ var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
381
423
  var HindsightClient = class {
382
424
  apiUrl;
383
425
  apiToken;
@@ -386,6 +428,8 @@ var HindsightClient = class {
386
428
  // async operation ids collected by retain(), for drain()
387
429
  /** Tri-state capability probe: unknown until the first page request, then cached. */
388
430
  knowledgePagesSupported;
431
+ /** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
432
+ idempotentRetain;
389
433
  log;
390
434
  constructor(o) {
391
435
  this.apiUrl = o.apiUrl.replace(/\/$/, "");
@@ -414,7 +458,8 @@ var HindsightClient = class {
414
458
  throw new Error(`${method} ${url} -> ${r.status} ${await r.text()}`);
415
459
  return r;
416
460
  }
417
- /** Retain one memory. Async by default: enqueue extraction server-side and collect its op-id for drain(). */
461
+ /** Retain one memory. ALWAYS async: enqueue extraction server-side and collect its op-id for
462
+ * drain(). Nothing in this plugin can afford to block a coding agent's hook on extraction. */
418
463
  async retain(content, context, documentId, tags, strategy, opts = {}) {
419
464
  const item = {
420
465
  content,
@@ -425,14 +470,36 @@ var HindsightClient = class {
425
470
  };
426
471
  if (opts.timestamp) item.timestamp = opts.timestamp;
427
472
  if (opts.metadata) item.metadata = opts.metadata;
428
- const isAsync = opts.async !== false;
429
- const r = await this.req("POST", this.bankUrl("/memories"), { items: [item], async: isAsync });
430
- if (isAsync) {
431
- try {
432
- const j = await r.json();
433
- if (j.operation_id) this.opIds.push(j.operation_id);
434
- } catch {
435
- }
473
+ if (opts.updateMode) item.update_mode = opts.updateMode;
474
+ const body = { items: [item], async: true };
475
+ if (opts.operationId) body.operation_id = opts.operationId;
476
+ const r = await this.req("POST", this.bankUrl("/memories"), body);
477
+ try {
478
+ const j = await r.json();
479
+ if (j.operation_id) this.opIds.push(j.operation_id);
480
+ } catch {
481
+ }
482
+ }
483
+ /**
484
+ * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
485
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
486
+ * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
487
+ */
488
+ async supportsIdempotentRetain() {
489
+ if (this.idempotentRetain === void 0) {
490
+ this.idempotentRetain = await this.probeIdempotentRetain();
491
+ this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
492
+ }
493
+ return this.idempotentRetain;
494
+ }
495
+ async probeIdempotentRetain() {
496
+ try {
497
+ const r = await this.req("GET", `${this.apiUrl}/version`);
498
+ if (!r.ok) return false;
499
+ const j = await r.json();
500
+ return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
501
+ } catch {
502
+ return false;
436
503
  }
437
504
  }
438
505
  /**
@@ -469,12 +536,39 @@ var HindsightClient = class {
469
536
  await this.req("DELETE", this.bankUrl());
470
537
  this.log(`[bank] reset ${this.bank}`);
471
538
  }
472
- await this.req("POST", this.bankUrl("/import"), CODING_BANK_TEMPLATE);
539
+ const seeded = opts.reset ? false : await this.hasBankMissions();
540
+ await this.req(
541
+ "POST",
542
+ this.bankUrl("/import"),
543
+ seeded ? CODING_BANK_STRUCTURE : CODING_BANK_TEMPLATE
544
+ );
473
545
  this.log(
474
- `[bank] template applied to ${this.bank}: missions, entity_labels {knowledge}, strategies {git, gitlog, conversation, document}`
546
+ seeded ? `[bank] structure applied to ${this.bank}: entity_labels {knowledge}, strategies {git, gitlog, conversation, document} \u2014 missions left as configured` : `[bank] template applied to ${this.bank}: missions, entity_labels {knowledge}, strategies {git, gitlog, conversation, document}`
475
547
  );
476
548
  await this.seedPages();
477
549
  }
550
+ /**
551
+ * Whether this bank already carries bank-level mission overrides — ours from an earlier seed, or
552
+ * the user's own edit. Either way they are not ours to overwrite.
553
+ *
554
+ * Reads the bank-scoped OVERRIDES, not the resolved config, so inherited global defaults don't
555
+ * read as "already set". A missing bank, or a deployment with the bank-config API switched off,
556
+ * answers false: there is nothing to preserve, and without that API a user cannot set per-bank
557
+ * missions in the first place.
558
+ */
559
+ async hasBankMissions() {
560
+ try {
561
+ const r = await this.req("GET", this.bankUrl("/config"));
562
+ if (!r.ok) return false;
563
+ const j = await r.json();
564
+ return MISSION_FIELDS.some((f) => {
565
+ const v = j.overrides?.[f];
566
+ return typeof v === "string" && v.trim() !== "";
567
+ });
568
+ } catch {
569
+ return false;
570
+ }
571
+ }
478
572
  /** Delete one document (cascades its memory units/links). Used by deepen's self-cleanup. */
479
573
  async deleteDocument(documentId) {
480
574
  await this.req("DELETE", this.bankUrl(`/documents/${encodeURIComponent(documentId)}`));
@@ -720,8 +814,7 @@ var HindsightClient = class {
720
814
  "initiative marker",
721
815
  markerId,
722
816
  ["knowledge:feature-work", `relatedPageId:${pageId}`],
723
- "document",
724
- { async: true }
817
+ "document"
725
818
  );
726
819
  return { page_id: pageId };
727
820
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectorize-io/hindsight-coding-agents",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/vectorize-io/hindsight.git",