@vectorize-io/hindsight-coding-agents 0.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.
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/core/config.ts
4
+ import { readFileSync } from "fs";
5
+ import { homedir } from "os";
6
+ import { join as join2 } from "path";
7
+
8
+ // src/core/seed.ts
9
+ import { spawn as realSpawn } from "child_process";
10
+ import { dirname, join } from "path";
11
+ import { fileURLToPath } from "url";
12
+ var DEFAULT_SEED_LIMIT = 300;
13
+ function startBackgroundSeed(repoDir, opts = {}) {
14
+ try {
15
+ const spawnFn = opts.spawn ?? realSpawn;
16
+ const enginePath = opts.enginePath ?? join(dirname(fileURLToPath(import.meta.url)), "deepen.js");
17
+ const limit = opts.limit ?? DEFAULT_SEED_LIMIT;
18
+ const child = spawnFn(
19
+ "node",
20
+ [
21
+ enginePath,
22
+ "--repo",
23
+ repoDir,
24
+ "--gitlog-limit",
25
+ String(limit),
26
+ ...opts.harness ? ["--harness", opts.harness] : []
27
+ ],
28
+ {
29
+ detached: true,
30
+ stdio: "ignore"
31
+ }
32
+ );
33
+ child.on("error", () => {
34
+ });
35
+ child.unref();
36
+ } catch {
37
+ }
38
+ }
39
+ function seedControl(command2, args) {
40
+ if (command2 === "seed") {
41
+ startBackgroundSeed(args.repo, { limit: args.limit, spawn: args.spawn });
42
+ return {
43
+ ok: true,
44
+ message: `\u{1F9E0} Hindsight is learning this repo \u2192 memory bank \u201C${args.bankId}\u201D`
45
+ };
46
+ }
47
+ return { ok: false, message: "usage: hindsight-seed seed --repo <dir>" };
48
+ }
49
+
50
+ // src/core/config.ts
51
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join2(homedir(), ".hindsight", "coding-agent.json");
52
+ function resolveConfig(raw = {}) {
53
+ return {
54
+ apiUrl: raw.apiUrl ?? "https://api.hindsight.vectorize.io",
55
+ apiToken: raw.apiToken || void 0,
56
+ bankId: raw.bankId,
57
+ dynamicBankId: raw.dynamicBankId,
58
+ bankIdTemplate: raw.bankIdTemplate,
59
+ mapPathToBank: raw.mapPathToBank,
60
+ resolveWorktrees: raw.resolveWorktrees,
61
+ harness: raw.harness ?? "opencode",
62
+ disabled: raw.disabled ?? false,
63
+ retainSessions: raw.retainSessions ?? true,
64
+ // opencode: write back by default (parity with hook-harness Stop)
65
+ retainEveryTurns: raw.retainEveryTurns || 1,
66
+ reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
67
+ autoReflect: raw.autoReflect ?? true,
68
+ pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
69
+ autoSeed: raw.autoSeed ?? true,
70
+ seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
71
+ codebaseSurvey: raw.codebaseSurvey ?? true,
72
+ surveyModel: raw.surveyModel || "haiku",
73
+ surveyBudgetUsd: raw.surveyBudgetUsd || 2,
74
+ surveyRefreshCommits: raw.surveyRefreshCommits ?? 20,
75
+ gitIngest: ["message", "full", "none"].includes(raw.gitIngest) ? raw.gitIngest : "message",
76
+ banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
77
+ logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info"
78
+ };
79
+ }
80
+ function readRaw(path) {
81
+ try {
82
+ return JSON.parse(readFileSync(path, "utf8"));
83
+ } catch (e) {
84
+ if (e?.code !== "ENOENT") {
85
+ console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
86
+ }
87
+ return {};
88
+ }
89
+ }
90
+ function mergeRaw(a, b) {
91
+ const { harnesses: _drop, ...flat } = b;
92
+ return { ...a, ...flat, banks: { ...a.banks ?? {}, ...b.banks ?? {} } };
93
+ }
94
+ function applyLayer(raw, layer, harness) {
95
+ let out = mergeRaw(raw, layer);
96
+ const perHarness = harness ? layer.harnesses?.[harness] : void 0;
97
+ if (perHarness) out = mergeRaw(out, perHarness);
98
+ return out;
99
+ }
100
+ function loadConfig(opts = {}) {
101
+ const o = typeof opts === "string" ? { path: opts } : opts;
102
+ return resolveConfig(applyLayer({}, readRaw(o.path ?? CONFIG_PATH), o.harness));
103
+ }
104
+
105
+ // src/core/bank.ts
106
+ import { execFileSync } from "child_process";
107
+ import { homedir as homedir2 } from "os";
108
+ import { basename, dirname as dirname2, join as join3, normalize, sep } from "path";
109
+ var DEFAULT_BANK_NAME = "coding";
110
+ var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
111
+ var PLACEHOLDER = /\{([a-zA-Z]+)\}/g;
112
+ function getProjectRootFromGit(directory) {
113
+ if (!directory) return null;
114
+ try {
115
+ const commonDir = execFileSync(
116
+ "git",
117
+ ["rev-parse", "--path-format=absolute", "--git-common-dir"],
118
+ { cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
119
+ ).trim();
120
+ if (!commonDir) return null;
121
+ return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ function gitProjectName(directory, resolveWorktrees) {
127
+ if (resolveWorktrees) {
128
+ const root = getProjectRootFromGit(directory);
129
+ if (root) return basename(root);
130
+ }
131
+ return directory ? basename(directory) : "unknown";
132
+ }
133
+ function mapLookup(map, directory) {
134
+ const cwd = normalize(directory);
135
+ let best;
136
+ for (const [dir, bank] of Object.entries(map)) {
137
+ const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir2(), dir.slice(1)) : dir;
138
+ const p = normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
139
+ if (cwd === p || cwd.startsWith(p + sep)) {
140
+ if (!best || p.length > best.len) best = { len: p.length, bank };
141
+ }
142
+ }
143
+ return best?.bank;
144
+ }
145
+ function deriveBankId(config, directory, harness = "coding") {
146
+ const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
147
+ if (mapped) return mapped;
148
+ const dynamic = config.dynamicBankId ?? !config.bankId;
149
+ if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
150
+ const resolvers = {
151
+ harness: () => harness,
152
+ project: () => directory ? basename(directory) : "unknown",
153
+ gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
154
+ channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
155
+ user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
156
+ };
157
+ return (config.bankIdTemplate || DEFAULT_TEMPLATE).replace(PLACEHOLDER, (_, name) => {
158
+ const r = resolvers[name];
159
+ if (!r) {
160
+ console.error(
161
+ `hindsight: unknown bankIdTemplate placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
162
+ );
163
+ return "unknown";
164
+ }
165
+ return r();
166
+ });
167
+ }
168
+
169
+ // src/hindsight-seed.ts
170
+ function arg(name) {
171
+ const i = process.argv.indexOf(`--${name}`);
172
+ return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : void 0;
173
+ }
174
+ var command = process.argv[2] || "";
175
+ var repo = arg("repo") || process.cwd();
176
+ var cfg = loadConfig({ harness: "claude-code" });
177
+ var bankId = deriveBankId(cfg, repo, "claude-code");
178
+ var result = seedControl(command, { repo, bankId });
179
+ console.log(result.message);
180
+ process.exit(result.ok ? 0 : 1);
@@ -0,0 +1,5 @@
1
+ import * as _opencode_ai_plugin from '@opencode-ai/plugin';
2
+
3
+ declare const HindsightCodingAgentsPlugin: _opencode_ai_plugin.Plugin;
4
+
5
+ export { HindsightCodingAgentsPlugin, HindsightCodingAgentsPlugin as default };