kodingo-cli 1.1.13 → 1.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.
package/dist/cli.js CHANGED
@@ -19,6 +19,7 @@ const sync_dependencies_1 = require("./commands/sync-dependencies");
19
19
  const security_scan_1 = require("./commands/security-scan");
20
20
  const init_1 = require("./commands/init");
21
21
  const build_1 = require("./commands/build");
22
+ const plan_1 = require("./commands/plan");
22
23
  const install_hook_1 = require("./commands/install-hook");
23
24
  const update_1 = require("./commands/update");
24
25
  const sync_1 = require("./commands/sync");
@@ -39,7 +40,7 @@ program
39
40
  .argument("<task>", "what to build or fix")
40
41
  .option("--repo <path>", "repo path (defaults to the current repo)")
41
42
  .option("--max-turns <n>", "override the agent loop's turn budget")
42
- .option("--scope <small|substantial>", "manual scope estimate sizing the initial token budget (stands in for Plan mode, not built yet)")
43
+ .option("--scope <small|substantial>", "manual scope estimate sizing the initial token budget — overrides the scope from a prior `kodingo plan` run against this repo, if any")
43
44
  .action(async (task, options) => {
44
45
  if (options.scope && options.scope !== "small" && options.scope !== "substantial") {
45
46
  console.error(`✖ --scope must be "small" or "substantial", got "${options.scope}".`);
@@ -52,6 +53,19 @@ program
52
53
  ...(options.scope ? { scope: options.scope } : {}),
53
54
  });
54
55
  });
56
+ // ── plan ──────────────────────────────────────────────────────────────────────
57
+ program
58
+ .command("plan")
59
+ .description("Run Kortex Plan's local, observation-only agent loop against this repo (test-driver for kodingo-agent)")
60
+ .argument("<task>", "what to plan")
61
+ .option("--repo <path>", "repo path (defaults to the current repo)")
62
+ .option("--max-turns <n>", "override the agent loop's turn budget")
63
+ .action(async (task, options) => {
64
+ await (0, plan_1.planCommand)(String(task), {
65
+ ...(options.repo ? { repo: String(options.repo) } : {}),
66
+ ...(options.maxTurns ? { maxTurns: Number.parseInt(String(options.maxTurns), 10) } : {}),
67
+ });
68
+ });
55
69
  // ── update ────────────────────────────────────────────────────────────────────
56
70
  program
57
71
  .command("update")
@@ -118,6 +118,18 @@ async function buildCommand(input, options = {}) {
118
118
  return;
119
119
  }
120
120
  const apiBaseUrl = apiConfig.apiUrl.replace(/\/$/, "");
121
+ // A real `kodingo plan` run against this same repo left a one-shot scope
122
+ // estimate behind — use it unless a human explicitly passed --scope,
123
+ // which always wins. Consumed (cleared) here so a stale plan from a
124
+ // different task never silently sizes a later, unrelated build.
125
+ let scope = options.scope;
126
+ const existingWs = (0, persistence_config_1.readWorkspaceConfig)(repoRoot);
127
+ if (!scope && existingWs?.lastPlan) {
128
+ scope = existingWs.lastPlan.scope;
129
+ console.log(`Using scope:${scope} from the last \`kodingo plan\` run against this repo (${existingWs.lastPlan.createdAt}).`);
130
+ const { lastPlan: _consumed, ...rest } = existingWs;
131
+ (0, persistence_config_1.writeWorkspaceConfig)(repoRoot, rest);
132
+ }
121
133
  // Bring-your-own, if configured (~/.kodingo/byo-model.json — same file
122
134
  // kodingo-vscode already uses) — never logged, only forwarded.
123
135
  const byoModelConfig = (0, kodingo_agent_1.getByoModelConfig)();
@@ -150,13 +162,17 @@ async function buildCommand(input, options = {}) {
150
162
  "Explore before you edit: read files, grep for symbols, and look around as needed — looking is just " +
151
163
  "another turn, you can call tools as many times as it takes to actually understand the real code " +
152
164
  "before changing it. Only use edit_file for surgical, minimal changes to existing files; use " +
153
- "write_file only for brand-new files. Before reporting done, verify your change with run_command.",
165
+ "write_file only for brand-new files. Before reporting done, verify your change with run_command. " +
166
+ "If you discover mid-task that a prior plan, assumption, or existing memory was meaningfully wrong — " +
167
+ "a file assumed to exist that doesn't, an existing pattern that's actually different from what was " +
168
+ "documented — call propose_memory_correction to record it for human review. Only for real, meaningful " +
169
+ "corrections, not routine exploration findings.",
154
170
  },
155
171
  { role: "user", content: input },
156
172
  ];
157
173
  const result = await (0, kodingo_agent_1.runAgentLoop)({
158
174
  cwd: repoRoot,
159
- tools: (0, kodingo_agent_1.createDefaultToolSet)(),
175
+ tools: (0, kodingo_agent_1.createDefaultToolSet)({ memoryCorrection: { apiBaseUrl, projectToken: apiConfig.token } }),
160
176
  initialMessages,
161
177
  modelPort,
162
178
  reporter: (0, kodingo_agent_1.createTerminalReporter)(),
@@ -164,7 +180,7 @@ async function buildCommand(input, options = {}) {
164
180
  // not a silent hard kill. See kodingo-agent's terminalCheckpointPort.
165
181
  checkpointPort: (0, kodingo_agent_1.createTerminalCheckpointPort)(),
166
182
  budgets: {
167
- ...(0, kodingo_agent_1.resolveBudgetForScope)(options.scope),
183
+ ...(0, kodingo_agent_1.resolveBudgetForScope)(scope),
168
184
  ...(options.maxTurns ? { maxTurns: options.maxTurns } : {}),
169
185
  },
170
186
  });
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ /**
3
+ * kodingo plan
4
+ *
5
+ * Runs Kortex Plan's real local agentic loop (kodingo-agent) against the
6
+ * current repo — observation only (read_file, grep, list_directory, glob,
7
+ * query_memory), never edit_file/write_file/run_command. Same real
8
+ * test-driver identity as `kodingo build` (see build.ts's own header
9
+ * comment): this exercises kodingo-agent's Plan tool set headlessly, not a
10
+ * polished second UX.
11
+ *
12
+ * On success, the real structured output (scope, filesLikelyInvolved,
13
+ * openQuestions) is written to this repo's workspace config as a one-shot
14
+ * handoff — `kodingo build` reads and consumes it to size its own budget,
15
+ * so a plain `kodingo build "<task>"` run after a `kodingo plan` run for
16
+ * the same repo picks up a real scope estimate without a manual --scope flag.
17
+ */
18
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
22
+ desc = { enumerable: true, get: function() { return m[k]; } };
23
+ }
24
+ Object.defineProperty(o, k2, desc);
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
30
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
31
+ }) : function(o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar = (this && this.__importStar) || (function () {
35
+ var ownKeys = function(o) {
36
+ ownKeys = Object.getOwnPropertyNames || function (o) {
37
+ var ar = [];
38
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
39
+ return ar;
40
+ };
41
+ return ownKeys(o);
42
+ };
43
+ return function (mod) {
44
+ if (mod && mod.__esModule) return mod;
45
+ var result = {};
46
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
47
+ __setModuleDefault(result, mod);
48
+ return result;
49
+ };
50
+ })();
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.planCommand = planCommand;
53
+ const fs = __importStar(require("fs"));
54
+ const path = __importStar(require("path"));
55
+ const kodingo_agent_1 = require("kodingo-agent");
56
+ const persistence_config_1 = require("../utils/persistence-config");
57
+ function findRepoRoot(startPath) {
58
+ let current = startPath;
59
+ while (true) {
60
+ if (fs.existsSync(path.join(current, ".git")))
61
+ return current;
62
+ const parent = path.dirname(current);
63
+ if (parent === current)
64
+ return startPath;
65
+ current = parent;
66
+ }
67
+ }
68
+ function resolveApiConfig(repoRoot) {
69
+ const config = (0, persistence_config_1.readConfig)();
70
+ const ws = (0, persistence_config_1.readWorkspaceConfig)(repoRoot);
71
+ const apiUrl = ws?.apiUrl ?? config.apiUrl;
72
+ const token = ws?.token ?? config.token;
73
+ if (!apiUrl || !token)
74
+ return null;
75
+ return { apiUrl, token };
76
+ }
77
+ async function planCommand(input, options = {}) {
78
+ const repoRoot = options.repo ? path.resolve(options.repo) : findRepoRoot(process.cwd());
79
+ const apiConfig = resolveApiConfig(repoRoot);
80
+ if (!apiConfig) {
81
+ console.error(`✖ No Kodingo project connected for ${repoRoot}. Run \`kodingo init\` in this repo first.`);
82
+ process.exitCode = 1;
83
+ return;
84
+ }
85
+ // Plan only ever reads — the trust prompt exists for Build's write/execute
86
+ // capability, so Plan doesn't need to ask for it, but it still respects an
87
+ // existing "always allow" grant by not double-prompting within it either way.
88
+ if (!(0, kodingo_agent_1.isProjectTrusted)(repoRoot)) {
89
+ console.log(`Note: ${repoRoot} isn't marked trusted yet — Plan only reads, so this runs regardless, but \`kodingo build\` will still ask.`);
90
+ }
91
+ const apiBaseUrl = apiConfig.apiUrl.replace(/\/$/, "");
92
+ const byoModelConfig = (0, kodingo_agent_1.getByoModelConfig)();
93
+ if (byoModelConfig) {
94
+ console.log(`Using bring-your-own model${byoModelConfig.label ? ` (${byoModelConfig.label})` : ""} — no shared quota consumed.`);
95
+ }
96
+ console.log(`Starting Kortex Plan against ${repoRoot} ...`);
97
+ const startRes = await fetch(`${apiBaseUrl}/build/agent-start`, {
98
+ method: "POST",
99
+ headers: { "Content-Type": "application/json", "X-Kodingo-Token": apiConfig.token },
100
+ body: JSON.stringify({
101
+ input,
102
+ repo: path.basename(repoRoot),
103
+ mode: "plan",
104
+ ...(byoModelConfig ? { modelConfig: byoModelConfig } : {}),
105
+ }),
106
+ });
107
+ const startBody = (await startRes.json());
108
+ if (!startRes.ok || !startBody.sessionId) {
109
+ console.error(`✖ Could not start Plan session: ${startBody.error ?? startRes.status}`);
110
+ process.exitCode = 1;
111
+ return;
112
+ }
113
+ const sessionId = startBody.sessionId;
114
+ console.log(`Session: ${sessionId}`);
115
+ const modelPort = (0, kodingo_agent_1.createHttpModelCallPort)({ apiBaseUrl, projectToken: apiConfig.token, sessionId });
116
+ const initialMessages = [
117
+ {
118
+ role: "system",
119
+ content: "You are Kortex Plan, working directly against the developer's real local repository. Your job is to " +
120
+ "produce a real, grounded plan for the task below — not a guess. You have NO ability to edit files or " +
121
+ "run commands — observation only.\n\n" +
122
+ "Explore in this order, narrow before wide, memory before raw content — this is enforced, not just " +
123
+ "advice: read_file will be mechanically rejected unless you've already either (a) called query_memory " +
124
+ "with a query naming that file, or (b) called list_directory/glob so it actually appears in the results. " +
125
+ "1) Start from query_memory with a question shaped by the task itself (e.g. 'how does rate limiting work " +
126
+ "in this codebase'). If the answer is genuinely sufficient, reason from it directly — a well-maintained " +
127
+ "project should let you produce a grounded plan with little or no raw file reading at all; that's the " +
128
+ "point, not a shortcut you're avoiding. 2) If insufficient, either ask a different, more specific memory " +
129
+ "question, or fall back to real exploration — that fallback is legitimate and expected for anything " +
130
+ "memory doesn't cover yet. 3) When falling back, start with list_directory/glob — file names and " +
131
+ "structure only, never full contents at this stage. 4) Once a specific file looks relevant, query memory " +
132
+ "again scoped to that file ('what do we know about authRoutes.js') before reading it — memory may cover " +
133
+ "it even if your broader query didn't. 5) Only then read_file, as a genuine last resort.\n\n" +
134
+ "If something is genuinely ambiguous and you can't proceed confidently without knowing the answer, use " +
135
+ "ask_clarifying_question — sparingly, only for real blockers, not things you could resolve yourself by " +
136
+ "reading more code. Before calling submit_plan, double-check your own draft against the real codebase: " +
137
+ "re-verify that every file path you're about to list under filesLikelyInvolved actually exists and is " +
138
+ "really relevant — submit_plan will mechanically reject any path that doesn't really exist. Give an " +
139
+ "honest scope estimate: 'small' for a narrow, single-file change; 'substantial' for a real multi-file " +
140
+ "feature. Your planMarkdown has two real destinations — sent straight to Build, or downloaded and taken " +
141
+ "somewhere else entirely with zero further involvement from Kortex — so write it as a genuinely complete, " +
142
+ "standalone document: real file paths, specific locations within them, real reasoning for each change.",
143
+ },
144
+ { role: "user", content: input },
145
+ ];
146
+ const { tools, drainBackgroundWork } = (0, kodingo_agent_1.createPlanToolSet)({
147
+ queryMemory: { apiBaseUrl, projectToken: apiConfig.token },
148
+ modelPort,
149
+ clarificationPort: (0, kodingo_agent_1.createTerminalClarificationPort)(),
150
+ });
151
+ const result = await (0, kodingo_agent_1.runAgentLoop)({
152
+ cwd: repoRoot,
153
+ tools,
154
+ initialMessages,
155
+ modelPort,
156
+ reporter: (0, kodingo_agent_1.createTerminalReporter)(),
157
+ checkpointPort: (0, kodingo_agent_1.createTerminalCheckpointPort)(),
158
+ drainBackgroundWork,
159
+ // Plan's whole job is thorough exploration BEFORE any task-specific
160
+ // scope is known, so it needs real headroom by default, not the flat
161
+ // 40-turn default — confirmed directly: a real Plan run against Pulse
162
+ // hit budget_exceeded at exactly 40 turns of pure reading (689,805
163
+ // tokens, well under the token budget) without ever reaching
164
+ // submit_plan. Using the same "substantial" floor Build gets for a
165
+ // real multi-file task, not the bare default.
166
+ budgets: {
167
+ ...(0, kodingo_agent_1.resolveBudgetForScope)("substantial"),
168
+ ...(options.maxTurns ? { maxTurns: options.maxTurns } : {}),
169
+ },
170
+ });
171
+ try {
172
+ await fetch(`${apiBaseUrl}/build/${sessionId}/agent-complete`, {
173
+ method: "POST",
174
+ headers: { "Content-Type": "application/json", "X-Kodingo-Token": apiConfig.token },
175
+ body: JSON.stringify({ status: result.status, message: result.error }),
176
+ });
177
+ }
178
+ catch {
179
+ // Best-effort — the loop's own outcome already printed to the terminal regardless.
180
+ }
181
+ if (result.status !== "completed" || !result.structuredOutput) {
182
+ console.error(`✖ Plan did not complete: ${result.status}${result.error ? ` — ${result.error}` : ""}`);
183
+ process.exitCode = 1;
184
+ return;
185
+ }
186
+ const output = result.structuredOutput;
187
+ console.log(`\n${output.planMarkdown}\n`);
188
+ console.log(`Scope: ${output.scope}`);
189
+ console.log(`Files likely involved: ${output.filesLikelyInvolved.join(", ") || "(none)"}`);
190
+ if (output.openQuestions.length > 0) {
191
+ console.log(`Open questions:\n${output.openQuestions.map((q) => ` - ${q}`).join("\n")}`);
192
+ }
193
+ // One-shot handoff: kodingo build reads and clears this on its next run
194
+ // against the same repo, sizing its own budget without a manual --scope.
195
+ const existingWs = (0, persistence_config_1.readWorkspaceConfig)(repoRoot);
196
+ (0, persistence_config_1.writeWorkspaceConfig)(repoRoot, {
197
+ mode: "cloud",
198
+ apiUrl: apiConfig.apiUrl,
199
+ token: apiConfig.token,
200
+ ...existingWs,
201
+ lastPlan: {
202
+ scope: output.scope,
203
+ planMarkdown: output.planMarkdown,
204
+ filesLikelyInvolved: output.filesLikelyInvolved,
205
+ openQuestions: output.openQuestions,
206
+ createdAt: new Date().toISOString(),
207
+ },
208
+ });
209
+ console.log(`\n✔ Saved as this repo's last plan — \`kodingo build\` will use scope:${output.scope} automatically on its next run here.`);
210
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kodingo-cli",
3
- "version": "1.1.13",
3
+ "version": "1.2.0",
4
4
  "description": "Kodingo CLI",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -25,7 +25,7 @@
25
25
  "@typescript-eslint/types": "^8.61.1",
26
26
  "@typescript-eslint/typescript-estree": "^8.61.1",
27
27
  "commander": "^12.1.0",
28
- "kodingo-agent": "^0.1.3",
28
+ "kodingo-agent": "^0.2.0",
29
29
  "kodingo-core": "^0.2.1",
30
30
  "open": "^11.0.0",
31
31
  "simple-git": "^3.30.0",