@carboncode/cli 0.1.2 → 0.1.5

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.
@@ -2,7 +2,7 @@
2
2
  import { createRequire as __cr } from 'node:module'; if (typeof globalThis.require === 'undefined') { globalThis.require = __cr(import.meta.url); }
3
3
  import {
4
4
  chatCommand
5
- } from "./chunk-CZCPIK5K.js";
5
+ } from "./chunk-HWYTH42F.js";
6
6
  import "./chunk-CXVWUPA3.js";
7
7
  import "./chunk-JMBMLOBP.js";
8
8
  import "./chunk-RSQMO6CF.js";
@@ -48,4 +48,4 @@ import "./chunk-TUK7OWJA.js";
48
48
  export {
49
49
  chatCommand
50
50
  };
51
- //# sourceMappingURL=chat-636MFZ7W.js.map
51
+ //# sourceMappingURL=chat-UTY5WLP3.js.map
@@ -60800,7 +60800,7 @@ run \`carboncode setup\` to remove this entry, or fix the underlying issue (miss
60800
60800
  if (dashboardRef.current) return dashboardRef.current.url;
60801
60801
  if (dashboardStartingRef.current) return dashboardStartingRef.current;
60802
60802
  const startup = (async () => {
60803
- const { startDashboardServer } = await import("./server-5WVJQUOR.js");
60803
+ const { startDashboardServer } = await import("./server-73KDDDDD.js");
60804
60804
  const handle = await startDashboardServer(
60805
60805
  {
60806
60806
  mode: "attached",
@@ -63124,4 +63124,4 @@ async function chatCommand(opts) {
63124
63124
  export {
63125
63125
  chatCommand
63126
63126
  };
63127
- //# sourceMappingURL=chunk-CZCPIK5K.js.map
63127
+ //# sourceMappingURL=chunk-HWYTH42F.js.map
@@ -2,7 +2,7 @@
2
2
  import { createRequire as __cr } from 'node:module'; if (typeof globalThis.require === 'undefined') { globalThis.require = __cr(import.meta.url); }
3
3
  import {
4
4
  chatCommand
5
- } from "./chunk-CZCPIK5K.js";
5
+ } from "./chunk-HWYTH42F.js";
6
6
  import "./chunk-CXVWUPA3.js";
7
7
  import "./chunk-JMBMLOBP.js";
8
8
  import "./chunk-RSQMO6CF.js";
@@ -151,4 +151,4 @@ async function codeCommand(opts = {}) {
151
151
  export {
152
152
  codeCommand
153
153
  };
154
- //# sourceMappingURL=code-TBC3K5AZ.js.map
154
+ //# sourceMappingURL=code-I3TP5QVR.js.map
package/dist/cli/index.js CHANGED
@@ -3244,7 +3244,7 @@ program2.action(async (opts) => {
3244
3244
  await setupCommand({ forceKeyStep: true });
3245
3245
  return;
3246
3246
  }
3247
- const { codeCommand } = await import("./code-TBC3K5AZ.js");
3247
+ const { codeCommand } = await import("./code-I3TP5QVR.js");
3248
3248
  await codeCommand({ dir: process.cwd(), forceResume: !!opts.continue });
3249
3249
  });
3250
3250
  program2.command("setup").description(t("cli.setup")).action(async () => {
@@ -3260,7 +3260,7 @@ program2.command("code [dir]").description(t("cli.code")).option("-m, --model <i
3260
3260
  ).action(async (dir, opts) => {
3261
3261
  const profiling = await maybeStartCpuProfile(opts.profile);
3262
3262
  try {
3263
- const { codeCommand } = await import("./code-TBC3K5AZ.js");
3263
+ const { codeCommand } = await import("./code-I3TP5QVR.js");
3264
3264
  await codeCommand({
3265
3265
  dir,
3266
3266
  model: opts.model,
@@ -3309,7 +3309,7 @@ program2.command("chat").description(t("cli.chat")).option("-m, --model <id>", t
3309
3309
  (msg) => process.stderr.write(`${msg}
3310
3310
  `)
3311
3311
  );
3312
- const { chatCommand } = await import("./chat-636MFZ7W.js");
3312
+ const { chatCommand } = await import("./chat-UTY5WLP3.js");
3313
3313
  const chatBase = opts.system ?? defaultSystemPrompt(defaults.model);
3314
3314
  const chatCwd = process.cwd();
3315
3315
  const chatRebuildSystem = () => applyMemoryStack(chatBase, chatCwd);
@@ -724,8 +724,19 @@ ${stagedStdout}` : "");
724
724
 
725
725
  // src/server/api/health.ts
726
726
  import { existsSync as existsSync2, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
727
+ import { join as join5 } from "path";
728
+
729
+ // src/server/context.ts
727
730
  import { homedir } from "os";
728
- import { join as join4 } from "path";
731
+ import { basename, dirname as dirname2, join as join4 } from "path";
732
+ function resolveCarboncodeHome(configPath) {
733
+ if (!configPath.trim()) return join4(homedir(), ".carboncode");
734
+ const configDir = dirname2(configPath);
735
+ if (basename(configDir).toLowerCase() === ".carboncode") return configDir;
736
+ return join4(configDir, ".carboncode");
737
+ }
738
+
739
+ // src/server/api/health.ts
729
740
  function dirSize(path) {
730
741
  if (!existsSync2(path)) return { path, exists: false, fileCount: 0, totalBytes: 0 };
731
742
  let fileCount = 0;
@@ -733,7 +744,7 @@ function dirSize(path) {
733
744
  try {
734
745
  const entries = readdirSync2(path);
735
746
  for (const name of entries) {
736
- const full = join4(path, name);
747
+ const full = join5(path, name);
737
748
  try {
738
749
  const s = statSync2(full);
739
750
  if (s.isFile()) {
@@ -744,7 +755,7 @@ function dirSize(path) {
744
755
  const inner = readdirSync2(full);
745
756
  for (const child of inner) {
746
757
  try {
747
- const cs = statSync2(join4(full, child));
758
+ const cs = statSync2(join5(full, child));
748
759
  if (cs.isFile()) {
749
760
  fileCount++;
750
761
  totalBytes += cs.size;
@@ -763,15 +774,24 @@ function dirSize(path) {
763
774
  }
764
775
  return { path, exists: true, fileCount, totalBytes };
765
776
  }
777
+ function countSessionFiles(path) {
778
+ if (!existsSync2(path)) return 0;
779
+ try {
780
+ return readdirSync2(path).filter(
781
+ (file) => file.endsWith(".jsonl") && !file.endsWith(".events.jsonl")
782
+ ).length;
783
+ } catch {
784
+ return 0;
785
+ }
786
+ }
766
787
  async function handleHealth(method, _rest, _body, ctx) {
767
788
  if (method !== "GET") {
768
789
  return { status: 405, body: { error: "GET only" } };
769
790
  }
770
- const home = homedir();
771
- const carboncodeHome = join4(home, ".carboncode");
772
- const sessionsStat = dirSize(join4(carboncodeHome, "sessions"));
773
- const memoryStat = dirSize(join4(carboncodeHome, "memory"));
774
- const semanticStat = dirSize(join4(carboncodeHome, "semantic"));
791
+ const carboncodeHome = resolveCarboncodeHome(ctx.configPath);
792
+ const sessionsStat = dirSize(join5(carboncodeHome, "sessions"));
793
+ const memoryStat = dirSize(join5(carboncodeHome, "memory"));
794
+ const semanticStat = dirSize(join5(carboncodeHome, "semantic"));
775
795
  let usageBytes = 0;
776
796
  if (existsSync2(ctx.usageLogPath)) {
777
797
  try {
@@ -779,7 +799,6 @@ async function handleHealth(method, _rest, _body, ctx) {
779
799
  } catch {
780
800
  }
781
801
  }
782
- const sessions = listSessions();
783
802
  return {
784
803
  status: 200,
785
804
  body: {
@@ -788,7 +807,7 @@ async function handleHealth(method, _rest, _body, ctx) {
788
807
  carboncodeHome,
789
808
  sessions: {
790
809
  path: sessionsStat.path,
791
- count: sessions.length,
810
+ count: countSessionFiles(sessionsStat.path),
792
811
  totalBytes: sessionsStat.totalBytes
793
812
  },
794
813
  memory: {
@@ -813,7 +832,7 @@ async function handleHealth(method, _rest, _body, ctx) {
813
832
 
814
833
  // src/server/api/hooks.ts
815
834
  import { existsSync as existsSync4, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
816
- import { dirname as dirname2 } from "path";
835
+ import { dirname as dirname3 } from "path";
817
836
 
818
837
  // src/server/api/hooks-events.ts
819
838
  import { existsSync as existsSync3 } from "fs";
@@ -865,7 +884,7 @@ function readSettingsFile(path) {
865
884
  function writeSettingsFile(path, hooksBlock) {
866
885
  const existing = readSettingsFile(path);
867
886
  existing.hooks = hooksBlock;
868
- mkdirSync(dirname2(path), { recursive: true });
887
+ mkdirSync(dirname3(path), { recursive: true });
869
888
  writeFileSync(path, `${JSON.stringify(existing, null, 2)}
870
889
  `, "utf8");
871
890
  }
@@ -1422,16 +1441,15 @@ import {
1422
1441
  unlinkSync,
1423
1442
  writeFileSync as writeFileSync2
1424
1443
  } from "fs";
1425
- import { homedir as homedir2 } from "os";
1426
- import { basename, dirname as dirname3, join as join5, resolve as resolvePath } from "path";
1444
+ import { basename as basename2, dirname as dirname4, join as join6, resolve as resolvePath } from "path";
1427
1445
  function projectHash(rootDir) {
1428
1446
  return createHash("sha1").update(resolvePath(rootDir)).digest("hex").slice(0, 16);
1429
1447
  }
1430
- function globalMemoryDir() {
1431
- return join5(homedir2(), ".carboncode", "memory", "global");
1448
+ function globalMemoryDir(carboncodeHome) {
1449
+ return join6(carboncodeHome, "memory", "global");
1432
1450
  }
1433
- function projectMemoryDir(rootDir) {
1434
- return join5(homedir2(), ".carboncode", "memory", projectHash(rootDir));
1451
+ function projectMemoryDir(carboncodeHome, rootDir) {
1452
+ return join6(carboncodeHome, "memory", projectHash(rootDir));
1435
1453
  }
1436
1454
  function parseBody6(raw) {
1437
1455
  if (!raw) return {};
@@ -1447,7 +1465,7 @@ function listMemoryFiles(dir) {
1447
1465
  if (!existsSync5(dir)) return [];
1448
1466
  try {
1449
1467
  return readdirSync3(dir).filter((f) => f.endsWith(".md")).map((f) => {
1450
- const stat = statSync3(join5(dir, f));
1468
+ const stat = statSync3(join6(dir, f));
1451
1469
  return {
1452
1470
  name: f.replace(/\.md$/, ""),
1453
1471
  size: stat.size,
@@ -1460,11 +1478,12 @@ function listMemoryFiles(dir) {
1460
1478
  }
1461
1479
  async function handleMemory(method, rest, body, ctx) {
1462
1480
  const cwd = ctx.getCurrentCwd?.();
1463
- const globalDir = globalMemoryDir();
1464
- const projectMemDir = cwd ? projectMemoryDir(cwd) : "";
1481
+ const carboncodeHome = resolveCarboncodeHome(ctx.configPath);
1482
+ const globalDir = globalMemoryDir(carboncodeHome);
1483
+ const projectMemDir = cwd ? projectMemoryDir(carboncodeHome, cwd) : "";
1465
1484
  if (method === "GET" && rest.length === 0) {
1466
1485
  const existingProjectMemory = cwd ? findProjectMemoryPath(cwd) : null;
1467
- const projectMemoryPath = existingProjectMemory ?? (cwd ? join5(cwd, PROJECT_MEMORY_FILE) : null);
1486
+ const projectMemoryPath = existingProjectMemory ?? (cwd ? join6(cwd, PROJECT_MEMORY_FILE) : null);
1468
1487
  const projectMemoryExists = existingProjectMemory !== null;
1469
1488
  return {
1470
1489
  status: 200,
@@ -1472,7 +1491,7 @@ async function handleMemory(method, rest, body, ctx) {
1472
1491
  project: {
1473
1492
  path: projectMemoryPath,
1474
1493
  exists: projectMemoryExists,
1475
- file: projectMemoryPath ? basename(projectMemoryPath) : PROJECT_MEMORY_FILE
1494
+ file: projectMemoryPath ? basename2(projectMemoryPath) : PROJECT_MEMORY_FILE
1476
1495
  },
1477
1496
  global: {
1478
1497
  path: globalDir,
@@ -1497,7 +1516,7 @@ async function handleMemory(method, rest, body, ctx) {
1497
1516
  if ((scope === "global" || scope === "project-mem") && name && SAFE_NAME.test(name)) {
1498
1517
  const dir = scope === "global" ? globalDir : projectMemDir;
1499
1518
  if (!dir) return { status: 503, body: { error: "no project root for project-mem" } };
1500
- const path = join5(dir, `${name}.md`);
1519
+ const path = join6(dir, `${name}.md`);
1501
1520
  if (!existsSync5(path)) return { status: 404, body: { error: "not found" } };
1502
1521
  return { status: 200, body: { path, body: readFileSync4(path, "utf8") } };
1503
1522
  }
@@ -1511,7 +1530,7 @@ async function handleMemory(method, rest, body, ctx) {
1511
1530
  if (scope === "project") {
1512
1531
  if (!cwd) return { status: 503, body: { error: "no active project" } };
1513
1532
  const path = resolveProjectMemoryWritePath(cwd);
1514
- mkdirSync2(dirname3(path), { recursive: true });
1533
+ mkdirSync2(dirname4(path), { recursive: true });
1515
1534
  writeFileSync2(path, contents, "utf8");
1516
1535
  ctx.audit?.({ ts: Date.now(), action: "save-memory", payload: { scope, path } });
1517
1536
  return { status: 200, body: { saved: true, path } };
@@ -1520,7 +1539,7 @@ async function handleMemory(method, rest, body, ctx) {
1520
1539
  const dir = scope === "global" ? globalDir : projectMemDir;
1521
1540
  if (!dir) return { status: 503, body: { error: "no project root for project-mem" } };
1522
1541
  mkdirSync2(dir, { recursive: true });
1523
- const path = join5(dir, `${name}.md`);
1542
+ const path = join6(dir, `${name}.md`);
1524
1543
  writeFileSync2(path, contents, "utf8");
1525
1544
  ctx.audit?.({ ts: Date.now(), action: "save-memory", payload: { scope, name, path } });
1526
1545
  return { status: 200, body: { saved: true, path } };
@@ -1531,7 +1550,7 @@ async function handleMemory(method, rest, body, ctx) {
1531
1550
  if ((scope === "global" || scope === "project-mem") && name && SAFE_NAME.test(name)) {
1532
1551
  const dir = scope === "global" ? globalDir : projectMemDir;
1533
1552
  if (!dir) return { status: 503, body: { error: "no project root for project-mem" } };
1534
- const path = join5(dir, `${name}.md`);
1553
+ const path = join6(dir, `${name}.md`);
1535
1554
  if (existsSync5(path)) {
1536
1555
  unlinkSync(path);
1537
1556
  ctx.audit?.({ ts: Date.now(), action: "delete-memory", payload: { scope, name, path } });
@@ -2130,7 +2149,7 @@ async function handlePlans(method, _rest, _body, _ctx) {
2130
2149
 
2131
2150
  // src/server/api/project-tree.ts
2132
2151
  import { existsSync as existsSync7, readdirSync as readdirSync4, statSync as statSync4 } from "fs";
2133
- import { extname as extname3, join as join6, relative as relative2, sep as sep3 } from "path";
2152
+ import { extname as extname3, join as join7, relative as relative2, sep as sep3 } from "path";
2134
2153
  var MAX_DEPTH2 = 6;
2135
2154
  var SKIP_DIRS2 = /* @__PURE__ */ new Set([
2136
2155
  "node_modules",
@@ -2185,7 +2204,7 @@ function buildTree(root, dirPath, depth) {
2185
2204
  const files = [];
2186
2205
  for (const name of names) {
2187
2206
  if (SKIP_DIRS2.has(name)) continue;
2188
- const full = join6(dirPath, name);
2207
+ const full = join7(dirPath, name);
2189
2208
  let st;
2190
2209
  try {
2191
2210
  st = statSync4(full);
@@ -2201,13 +2220,13 @@ function buildTree(root, dirPath, depth) {
2201
2220
  dirs.sort();
2202
2221
  files.sort();
2203
2222
  for (const name of dirs) {
2204
- const full = join6(dirPath, name);
2223
+ const full = join7(dirPath, name);
2205
2224
  const rel = relative2(root, full).split(sep3).join("/");
2206
2225
  const children = buildTree(root, full, depth + 1);
2207
2226
  nodes.push({ name, path: rel, isDir: true, children });
2208
2227
  }
2209
2228
  for (const name of files) {
2210
- const full = join6(dirPath, name);
2229
+ const full = join7(dirPath, name);
2211
2230
  const rel = relative2(root, full).split(sep3).join("/");
2212
2231
  nodes.push({ name, path: rel, isDir: false });
2213
2232
  }
@@ -2222,7 +2241,7 @@ async function handleReviewDiffs(method, _rest, _body, _ctx) {
2222
2241
 
2223
2242
  // src/server/api/semantic.ts
2224
2243
  import { closeSync as closeSync3, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync3 } from "fs";
2225
- import { join as join7 } from "path";
2244
+ import { join as join8 } from "path";
2226
2245
  var JOBS = /* @__PURE__ */ new Map();
2227
2246
  var PULLS = /* @__PURE__ */ new Map();
2228
2247
  function getRoot(ctx) {
@@ -2328,7 +2347,7 @@ async function getStatus(ctx) {
2328
2347
  async function readIndexMeta2(root, current) {
2329
2348
  const dir = await existingSemanticIndexDir(root);
2330
2349
  if (!dir) return { exists: false };
2331
- const dataPath = join7(dir, "index.jsonl");
2350
+ const dataPath = join8(dir, "index.jsonl");
2332
2351
  const diskMeta = await readIndexMeta(dir);
2333
2352
  if (!diskMeta) return { exists: false };
2334
2353
  let chunks = 0;
@@ -2947,8 +2966,8 @@ import {
2947
2966
  statSync as statSync5,
2948
2967
  writeFileSync as writeFileSync3
2949
2968
  } from "fs";
2950
- import { homedir as homedir3 } from "os";
2951
- import { dirname as dirname4, join as join8 } from "path";
2969
+ import { homedir as homedir2 } from "os";
2970
+ import { dirname as dirname5, join as join9 } from "path";
2952
2971
  function parseBody10(raw) {
2953
2972
  if (!raw) return {};
2954
2973
  try {
@@ -2960,16 +2979,16 @@ function parseBody10(raw) {
2960
2979
  }
2961
2980
  var SAFE_NAME2 = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
2962
2981
  function globalSkillsDir() {
2963
- return join8(homedir3(), CARBON_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2982
+ return join9(homedir2(), CARBON_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2964
2983
  }
2965
2984
  function projectSkillsDir(rootDir) {
2966
- return join8(rootDir, CARBON_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2985
+ return join9(rootDir, CARBON_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2967
2986
  }
2968
2987
  function legacyGlobalSkillsDir() {
2969
- return join8(homedir3(), LEGACY_REASONIX_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2988
+ return join9(homedir2(), LEGACY_REASONIX_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2970
2989
  }
2971
2990
  function legacyProjectSkillsDir(rootDir) {
2972
- return join8(rootDir, LEGACY_REASONIX_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2991
+ return join9(rootDir, LEGACY_REASONIX_RUNTIME_DIRNAME, SKILLS_DIRNAME);
2973
2992
  }
2974
2993
  function parseFrontmatterDescription(raw) {
2975
2994
  const desc = parseFrontmatter(raw).data.description?.trim();
@@ -3009,12 +3028,12 @@ function readSkillListEntry(skillPath, name, scope) {
3009
3028
  }
3010
3029
  }
3011
3030
  function resolveSkillPath(dir, name) {
3012
- const folderPath = join8(dir, name, SKILL_FILE);
3031
+ const folderPath = join9(dir, name, SKILL_FILE);
3013
3032
  try {
3014
3033
  if (statSync5(folderPath).isFile()) return { path: folderPath, layout: "folder" };
3015
3034
  } catch {
3016
3035
  }
3017
- const flatPath = join8(dir, `${name}.md`);
3036
+ const flatPath = join9(dir, `${name}.md`);
3018
3037
  try {
3019
3038
  if (statSync5(flatPath).isFile()) return { path: flatPath, layout: "flat" };
3020
3039
  } catch {
@@ -3022,7 +3041,7 @@ function resolveSkillPath(dir, name) {
3022
3041
  return null;
3023
3042
  }
3024
3043
  function defaultSkillPath(dir, name) {
3025
- return { path: join8(dir, name, SKILL_FILE), layout: "folder" };
3044
+ return { path: join9(dir, name, SKILL_FILE), layout: "folder" };
3026
3045
  }
3027
3046
  function listSkills(dir, scope) {
3028
3047
  if (!existsSync9(dir)) return [];
@@ -3034,11 +3053,11 @@ function listSkills(dir, scope) {
3034
3053
  if (entry.isDirectory()) {
3035
3054
  name = entry.name;
3036
3055
  if (!SAFE_NAME2.test(name)) continue;
3037
- skillPath = join8(dir, name, SKILL_FILE);
3056
+ skillPath = join9(dir, name, SKILL_FILE);
3038
3057
  } else if (entry.isFile() && entry.name.endsWith(".md")) {
3039
3058
  name = entry.name.slice(0, -3);
3040
3059
  if (!SAFE_NAME2.test(name)) continue;
3041
- skillPath = join8(dir, entry.name);
3060
+ skillPath = join9(dir, entry.name);
3042
3061
  } else {
3043
3062
  continue;
3044
3063
  }
@@ -3149,7 +3168,7 @@ async function handleSkills(method, rest, body, ctx) {
3149
3168
  return { status: 400, body: { error: fm.error } };
3150
3169
  }
3151
3170
  const target = resolved ?? defaultSkillPath(defaultDir, name);
3152
- mkdirSync3(dirname4(target.path), { recursive: true });
3171
+ mkdirSync3(dirname5(target.path), { recursive: true });
3153
3172
  writeFileSync3(target.path, contents, "utf8");
3154
3173
  ctx.audit?.({
3155
3174
  ts: Date.now(),
@@ -3160,7 +3179,7 @@ async function handleSkills(method, rest, body, ctx) {
3160
3179
  }
3161
3180
  if (method === "DELETE") {
3162
3181
  if (!resolved) return { status: 404, body: { error: "skill not found" } };
3163
- rmSync(resolved.layout === "folder" ? dirname4(resolved.path) : resolved.path, {
3182
+ rmSync(resolved.layout === "folder" ? dirname5(resolved.path) : resolved.path, {
3164
3183
  recursive: true,
3165
3184
  force: true
3166
3185
  });
@@ -3569,4 +3588,4 @@ export {
3569
3588
  readBody,
3570
3589
  startDashboardServer
3571
3590
  };
3572
- //# sourceMappingURL=server-5WVJQUOR.js.map
3591
+ //# sourceMappingURL=server-73KDDDDD.js.map