@shodocan/opencode-hindsight 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -540,6 +540,30 @@ This is useful when you want to:
540
540
  - **Organize memories using your own naming scheme**
541
541
  - **Integrate with existing Hindsight banks** from other tools
542
542
 
543
+ ### Bank Names from Environment Variables
544
+
545
+ Bank fields can reference environment variables when the entire configured value is a variable reference. Supported forms are `$VAR` and `${VAR}`, where variable names use shell-style identifiers matching `[A-Za-z_][A-Za-z0-9_]*`:
546
+
547
+ ```jsonc
548
+ {
549
+ "userBank": "$OPENCODE_USER_BANK",
550
+ "projectBank": "$OPENCODE_PROJECT_BANK",
551
+ "agentProjectBanks": {
552
+ "review-*": "$OPENCODE_REVIEW_BANK"
553
+ },
554
+ "runtimeProjectBanks": {
555
+ "reviews": "${OPENCODE_REVIEW_BANK}"
556
+ }
557
+ }
558
+ ```
559
+
560
+ Rules:
561
+
562
+ - Only full-value references are expanded; unsupported or partial env-reference syntax remains literal. `"proj-$OPENCODE_REVIEW_BANK"` remains literal.
563
+ - Missing or empty environment variables are treated as unset.
564
+ - For `agentProjectBanks` and `runtimeProjectBanks`, entries with missing or empty env refs are dropped.
565
+ - Expansion happens when the plugin loads configuration, so restart OpenCode after changing these variables.
566
+
543
567
  ### Agent-Aware Project Bank Routing
544
568
 
545
569
  Subagents can use different project banks without changing OpenCode core. Configure `agentProjectBanks` with exact names or `*` glob patterns:
package/dist/config.d.ts CHANGED
@@ -1,9 +1,16 @@
1
+ /**
2
+ * Sanitize one configured bank value. Full-value environment references of
3
+ * the form `$VAR` and `${VAR}` are expanded from the plugin process env.
4
+ * Partial interpolation is intentionally unsupported and remains literal.
5
+ */
6
+ export declare function sanitizeBankValue(value: unknown, env?: Record<string, string | undefined>): string | undefined;
1
7
  /**
2
8
  * Sanitize a bank-name map from config: reject arrays, drop entries with
3
- * non-string keys/values, and strip leading/trailing whitespace. Returns an
4
- * empty object when absent or not a plain object.
9
+ * non-string keys/values, strip leading/trailing whitespace, and expand
10
+ * full-value env refs in values. Returns an empty object when absent or not a
11
+ * plain object.
5
12
  */
6
- export declare function sanitizeBankMap(map: Record<string, string> | undefined): Record<string, string>;
13
+ export declare function sanitizeBankMap(map: unknown, env?: Record<string, string | undefined>): Record<string, string>;
7
14
  export declare const CONFIG: {
8
15
  baseUrl: string;
9
16
  similarityThreshold: number;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AA6GA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAS/F;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;CAmBlB,CAAC;AAEF,wBAAgB,YAAY,IAAI,OAAO,CAEtC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AA+GA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,MAAM,GAAG,SAAS,CAYpB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,EACZ,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWxB;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;CAmBlB,CAAC;AAEF,wBAAgB,YAAY,IAAI,OAAO,CAEtC"}
package/dist/index.js CHANGED
@@ -14049,6 +14049,7 @@ function loadConfig() {
14049
14049
  return {};
14050
14050
  }
14051
14051
  var fileConfig = loadConfig();
14052
+ var ENV_REF_RE = /^\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})$/;
14052
14053
  function getBaseUrl() {
14053
14054
  if (process.env.HINDSIGHT_BASE_URL)
14054
14055
  return process.env.HINDSIGHT_BASE_URL;
@@ -14056,13 +14057,30 @@ function getBaseUrl() {
14056
14057
  return fileConfig.baseUrl;
14057
14058
  return "http://localhost:8888";
14058
14059
  }
14059
- function sanitizeBankMap(map2) {
14060
+ function sanitizeBankValue(value, env = process.env) {
14061
+ if (typeof value !== "string")
14062
+ return;
14063
+ const trimmed = value.trim();
14064
+ if (!trimmed)
14065
+ return;
14066
+ const match = trimmed.match(ENV_REF_RE);
14067
+ if (!match)
14068
+ return trimmed;
14069
+ const envName = match[1] ?? match[2];
14070
+ if (!envName)
14071
+ return;
14072
+ const envValue = env[envName]?.trim();
14073
+ return envValue || undefined;
14074
+ }
14075
+ function sanitizeBankMap(map2, env = process.env) {
14060
14076
  if (!map2 || typeof map2 !== "object" || Array.isArray(map2))
14061
14077
  return {};
14062
14078
  const out = {};
14063
14079
  for (const [key, value] of Object.entries(map2)) {
14064
- if (typeof key === "string" && typeof value === "string" && key.trim() && value.trim()) {
14065
- out[key.trim()] = value.trim();
14080
+ const cleanKey = key.trim();
14081
+ const cleanValue = sanitizeBankValue(value, env);
14082
+ if (cleanKey && cleanValue) {
14083
+ out[cleanKey] = cleanValue;
14066
14084
  }
14067
14085
  }
14068
14086
  return out;
@@ -14075,8 +14093,8 @@ var CONFIG = {
14075
14093
  maxProfileItems: fileConfig.maxProfileItems ?? DEFAULTS.maxProfileItems,
14076
14094
  injectProfile: fileConfig.injectProfile ?? DEFAULTS.injectProfile,
14077
14095
  bankPrefix: fileConfig.bankPrefix ?? DEFAULTS.bankPrefix,
14078
- userBank: fileConfig.userBank,
14079
- projectBank: fileConfig.projectBank,
14096
+ userBank: sanitizeBankValue(fileConfig.userBank),
14097
+ projectBank: sanitizeBankValue(fileConfig.projectBank),
14080
14098
  maxTokens: fileConfig.maxTokens ?? DEFAULTS.maxTokens,
14081
14099
  budget: fileConfig.budget ?? DEFAULTS.budget,
14082
14100
  keywordPatterns: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shodocan/opencode-hindsight",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "OpenCode plugin that gives coding agents persistent memory using Hindsight",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",