@colbymchenry/codegraph-darwin-x64 1.0.0 → 1.1.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.
Files changed (175) hide show
  1. package/lib/dist/bin/codegraph.js +258 -17
  2. package/lib/dist/bin/codegraph.js.map +1 -1
  3. package/lib/dist/bin/fatal-handler.d.ts +20 -0
  4. package/lib/dist/bin/fatal-handler.d.ts.map +1 -0
  5. package/lib/dist/bin/fatal-handler.js +118 -0
  6. package/lib/dist/bin/fatal-handler.js.map +1 -0
  7. package/lib/dist/db/index.d.ts +22 -1
  8. package/lib/dist/db/index.d.ts.map +1 -1
  9. package/lib/dist/db/index.js +46 -1
  10. package/lib/dist/db/index.js.map +1 -1
  11. package/lib/dist/db/queries.d.ts +14 -0
  12. package/lib/dist/db/queries.d.ts.map +1 -1
  13. package/lib/dist/db/queries.js +25 -0
  14. package/lib/dist/db/queries.js.map +1 -1
  15. package/lib/dist/directory.d.ts +58 -0
  16. package/lib/dist/directory.d.ts.map +1 -1
  17. package/lib/dist/directory.js +165 -0
  18. package/lib/dist/directory.js.map +1 -1
  19. package/lib/dist/extraction/grammars.d.ts +11 -3
  20. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  21. package/lib/dist/extraction/grammars.js +14 -5
  22. package/lib/dist/extraction/grammars.js.map +1 -1
  23. package/lib/dist/extraction/index.d.ts.map +1 -1
  24. package/lib/dist/extraction/index.js +202 -32
  25. package/lib/dist/extraction/index.js.map +1 -1
  26. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  27. package/lib/dist/extraction/languages/c-cpp.js +47 -2
  28. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  29. package/lib/dist/extraction/languages/csharp.d.ts.map +1 -1
  30. package/lib/dist/extraction/languages/csharp.js +20 -0
  31. package/lib/dist/extraction/languages/csharp.js.map +1 -1
  32. package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
  33. package/lib/dist/extraction/languages/dart.js +22 -0
  34. package/lib/dist/extraction/languages/dart.js.map +1 -1
  35. package/lib/dist/extraction/languages/java.d.ts.map +1 -1
  36. package/lib/dist/extraction/languages/java.js +213 -9
  37. package/lib/dist/extraction/languages/java.js.map +1 -1
  38. package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
  39. package/lib/dist/extraction/languages/kotlin.js +51 -0
  40. package/lib/dist/extraction/languages/kotlin.js.map +1 -1
  41. package/lib/dist/extraction/languages/scala.d.ts.map +1 -1
  42. package/lib/dist/extraction/languages/scala.js +19 -9
  43. package/lib/dist/extraction/languages/scala.js.map +1 -1
  44. package/lib/dist/extraction/parse-worker.js +4 -1
  45. package/lib/dist/extraction/parse-worker.js.map +1 -1
  46. package/lib/dist/extraction/tree-sitter-types.d.ts +13 -0
  47. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  48. package/lib/dist/extraction/tree-sitter.d.ts +119 -0
  49. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  50. package/lib/dist/extraction/tree-sitter.js +890 -11
  51. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  52. package/lib/dist/index.d.ts +33 -0
  53. package/lib/dist/index.d.ts.map +1 -1
  54. package/lib/dist/index.js +68 -7
  55. package/lib/dist/index.js.map +1 -1
  56. package/lib/dist/installer/index.d.ts.map +1 -1
  57. package/lib/dist/installer/index.js +33 -56
  58. package/lib/dist/installer/index.js.map +1 -1
  59. package/lib/dist/installer/instructions-template.d.ts +3 -3
  60. package/lib/dist/installer/instructions-template.d.ts.map +1 -1
  61. package/lib/dist/installer/instructions-template.js +4 -4
  62. package/lib/dist/installer/targets/claude.d.ts +18 -12
  63. package/lib/dist/installer/targets/claude.d.ts.map +1 -1
  64. package/lib/dist/installer/targets/claude.js +78 -6
  65. package/lib/dist/installer/targets/claude.js.map +1 -1
  66. package/lib/dist/installer/targets/shared.d.ts +12 -2
  67. package/lib/dist/installer/targets/shared.d.ts.map +1 -1
  68. package/lib/dist/installer/targets/shared.js +13 -12
  69. package/lib/dist/installer/targets/shared.js.map +1 -1
  70. package/lib/dist/installer/targets/types.d.ts +7 -0
  71. package/lib/dist/installer/targets/types.d.ts.map +1 -1
  72. package/lib/dist/mcp/daemon-manager.d.ts +42 -0
  73. package/lib/dist/mcp/daemon-manager.d.ts.map +1 -0
  74. package/lib/dist/mcp/daemon-manager.js +129 -0
  75. package/lib/dist/mcp/daemon-manager.js.map +1 -0
  76. package/lib/dist/mcp/daemon-registry.d.ts +47 -0
  77. package/lib/dist/mcp/daemon-registry.d.ts.map +1 -0
  78. package/lib/dist/mcp/daemon-registry.js +229 -0
  79. package/lib/dist/mcp/daemon-registry.js.map +1 -0
  80. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  81. package/lib/dist/mcp/daemon.js +5 -0
  82. package/lib/dist/mcp/daemon.js.map +1 -1
  83. package/lib/dist/mcp/engine.d.ts.map +1 -1
  84. package/lib/dist/mcp/engine.js +8 -0
  85. package/lib/dist/mcp/engine.js.map +1 -1
  86. package/lib/dist/mcp/index.d.ts +1 -0
  87. package/lib/dist/mcp/index.d.ts.map +1 -1
  88. package/lib/dist/mcp/index.js +13 -0
  89. package/lib/dist/mcp/index.js.map +1 -1
  90. package/lib/dist/mcp/liveness-watchdog.d.ts +18 -0
  91. package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -0
  92. package/lib/dist/mcp/liveness-watchdog.js +207 -0
  93. package/lib/dist/mcp/liveness-watchdog.js.map +1 -0
  94. package/lib/dist/mcp/server-instructions.d.ts +18 -14
  95. package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
  96. package/lib/dist/mcp/server-instructions.js +57 -52
  97. package/lib/dist/mcp/server-instructions.js.map +1 -1
  98. package/lib/dist/mcp/session.d.ts.map +1 -1
  99. package/lib/dist/mcp/session.js +23 -18
  100. package/lib/dist/mcp/session.js.map +1 -1
  101. package/lib/dist/mcp/tools.d.ts +51 -1
  102. package/lib/dist/mcp/tools.d.ts.map +1 -1
  103. package/lib/dist/mcp/tools.js +585 -151
  104. package/lib/dist/mcp/tools.js.map +1 -1
  105. package/lib/dist/project-config.d.ts +19 -0
  106. package/lib/dist/project-config.d.ts.map +1 -0
  107. package/lib/dist/project-config.js +180 -0
  108. package/lib/dist/project-config.js.map +1 -0
  109. package/lib/dist/reasoning/config.d.ts +45 -0
  110. package/lib/dist/reasoning/config.d.ts.map +1 -0
  111. package/lib/dist/reasoning/config.js +171 -0
  112. package/lib/dist/reasoning/config.js.map +1 -0
  113. package/lib/dist/reasoning/credentials.d.ts +5 -0
  114. package/lib/dist/reasoning/credentials.d.ts.map +1 -0
  115. package/lib/dist/reasoning/credentials.js +83 -0
  116. package/lib/dist/reasoning/credentials.js.map +1 -0
  117. package/lib/dist/reasoning/login.d.ts +21 -0
  118. package/lib/dist/reasoning/login.d.ts.map +1 -0
  119. package/lib/dist/reasoning/login.js +85 -0
  120. package/lib/dist/reasoning/login.js.map +1 -0
  121. package/lib/dist/reasoning/reasoner.d.ts +43 -0
  122. package/lib/dist/reasoning/reasoner.d.ts.map +1 -0
  123. package/lib/dist/reasoning/reasoner.js +308 -0
  124. package/lib/dist/reasoning/reasoner.js.map +1 -0
  125. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +33 -0
  126. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -0
  127. package/lib/dist/resolution/c-fnptr-synthesizer.js +352 -0
  128. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -0
  129. package/lib/dist/resolution/callback-synthesizer.d.ts +6 -1
  130. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  131. package/lib/dist/resolution/callback-synthesizer.js +1109 -1
  132. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  133. package/lib/dist/resolution/frameworks/goframe.d.ts +41 -0
  134. package/lib/dist/resolution/frameworks/goframe.d.ts.map +1 -0
  135. package/lib/dist/resolution/frameworks/goframe.js +112 -0
  136. package/lib/dist/resolution/frameworks/goframe.js.map +1 -0
  137. package/lib/dist/resolution/frameworks/index.d.ts +1 -0
  138. package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
  139. package/lib/dist/resolution/frameworks/index.js +5 -1
  140. package/lib/dist/resolution/frameworks/index.js.map +1 -1
  141. package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
  142. package/lib/dist/resolution/frameworks/react.js +17 -60
  143. package/lib/dist/resolution/frameworks/react.js.map +1 -1
  144. package/lib/dist/resolution/goframe-synthesizer.d.ts +28 -0
  145. package/lib/dist/resolution/goframe-synthesizer.d.ts.map +1 -0
  146. package/lib/dist/resolution/goframe-synthesizer.js +158 -0
  147. package/lib/dist/resolution/goframe-synthesizer.js.map +1 -0
  148. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  149. package/lib/dist/resolution/import-resolver.js +56 -0
  150. package/lib/dist/resolution/import-resolver.js.map +1 -1
  151. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  152. package/lib/dist/resolution/name-matcher.js +48 -8
  153. package/lib/dist/resolution/name-matcher.js.map +1 -1
  154. package/lib/dist/resolution/strip-comments.d.ts +1 -1
  155. package/lib/dist/resolution/strip-comments.d.ts.map +1 -1
  156. package/lib/dist/resolution/strip-comments.js +2 -0
  157. package/lib/dist/resolution/strip-comments.js.map +1 -1
  158. package/lib/dist/sync/watcher.d.ts +68 -1
  159. package/lib/dist/sync/watcher.d.ts.map +1 -1
  160. package/lib/dist/sync/watcher.js +212 -14
  161. package/lib/dist/sync/watcher.js.map +1 -1
  162. package/lib/dist/telemetry/index.d.ts +0 -3
  163. package/lib/dist/telemetry/index.d.ts.map +1 -1
  164. package/lib/dist/telemetry/index.js +4 -7
  165. package/lib/dist/telemetry/index.js.map +1 -1
  166. package/lib/dist/upgrade/index.d.ts.map +1 -1
  167. package/lib/dist/upgrade/index.js +40 -4
  168. package/lib/dist/upgrade/index.js.map +1 -1
  169. package/lib/dist/utils.d.ts +14 -1
  170. package/lib/dist/utils.d.ts.map +1 -1
  171. package/lib/dist/utils.js +20 -2
  172. package/lib/dist/utils.js.map +1 -1
  173. package/lib/node_modules/.package-lock.json +1 -1
  174. package/lib/package.json +2 -2
  175. package/package.json +1 -1
@@ -0,0 +1,19 @@
1
+ import { Language } from './types';
2
+ /** Filename of the project-scoped config, resolved relative to the project root. */
3
+ export declare const PROJECT_CONFIG_FILENAME = "codegraph.json";
4
+ export interface ProjectConfig {
5
+ /** Map of custom file extension (`.foo`) to a supported language id. */
6
+ extensions?: Record<string, string>;
7
+ }
8
+ /**
9
+ * Load the validated extension overrides for a project, mtime-cached.
10
+ *
11
+ * Returns a map of `.ext` → supported language id. The result merges on top of
12
+ * the built-in extension map at the point of use (see `detectLanguage` /
13
+ * `isSourceFile`), with these user mappings taking precedence. Returns an empty
14
+ * map when there is no `codegraph.json` (the zero-config default).
15
+ */
16
+ export declare function loadExtensionOverrides(rootDir: string): Record<string, Language>;
17
+ /** Test/maintenance hook: forget cached config (e.g. after rewriting it in a test). */
18
+ export declare function clearProjectConfigCache(): void;
19
+ //# sourceMappingURL=project-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-config.d.ts","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAInC,oFAAoF;AACpF,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAoFD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAoBhF;AAED,uFAAuF;AACvF,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C"}
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PROJECT_CONFIG_FILENAME = void 0;
37
+ exports.loadExtensionOverrides = loadExtensionOverrides;
38
+ exports.clearProjectConfigCache = clearProjectConfigCache;
39
+ /**
40
+ * Project-scoped configuration: a committed `codegraph.json` at the project
41
+ * root that a team shares through version control.
42
+ *
43
+ * Today it carries one thing — `extensions`, an opt-in map from a custom file
44
+ * extension to one of CodeGraph's supported languages. The built-in
45
+ * extension → language table (`EXTENSION_MAP` in `extraction/grammars.ts`) is
46
+ * otherwise hardcoded, so a codebase that uses a non-standard extension for a
47
+ * supported language (e.g. `.dota_lua` for Lua) sees those files silently
48
+ * skipped. This lets the project map them once, in a version-controlled file:
49
+ *
50
+ * {
51
+ * "extensions": {
52
+ * ".dota_lua": "lua",
53
+ * ".tpl": "php"
54
+ * }
55
+ * }
56
+ *
57
+ * User mappings merge on TOP of the built-ins and win on conflict, so a project
58
+ * can also re-point a built-in extension (e.g. force `.h` → `cpp`). Absent or
59
+ * malformed config is the zero-config default — no overrides, no error. Invalid
60
+ * individual entries are warned-and-skipped (never fatal): an unparseable
61
+ * project file must not break indexing.
62
+ */
63
+ const fs = __importStar(require("fs"));
64
+ const path = __importStar(require("path"));
65
+ const grammars_1 = require("./extraction/grammars");
66
+ const errors_1 = require("./errors");
67
+ /** Filename of the project-scoped config, resolved relative to the project root. */
68
+ exports.PROJECT_CONFIG_FILENAME = 'codegraph.json';
69
+ /**
70
+ * Cache keyed by project root. The loader is called once per indexing/scan/sync
71
+ * operation (and per watch event), so the mtime guard keeps repeat calls to one
72
+ * `stat` while a single `codegraph.json` is in force. Keying by root keeps two
73
+ * projects in the same process (the daemon / multi-project MCP server) isolated.
74
+ */
75
+ const overridesCache = new Map();
76
+ const cacheMeta = new Map();
77
+ /** Shared frozen empty map so the no-config path allocates nothing. */
78
+ const EMPTY = Object.freeze({});
79
+ /**
80
+ * Normalize a user-provided extension key to the `.ext` lowercase form used by
81
+ * the built-in map. Returns null for keys that can never match a real file
82
+ * extension (so the caller warns and skips):
83
+ * - empty / just "."
84
+ * - multi-part (".d.ts") — language detection keys off the FINAL extension
85
+ * only (`lastIndexOf('.')`), so a multi-dot key would never be consulted.
86
+ * - anything containing a path separator.
87
+ */
88
+ function normalizeExtKey(raw) {
89
+ if (typeof raw !== 'string')
90
+ return null;
91
+ let ext = raw.trim().toLowerCase();
92
+ if (!ext)
93
+ return null;
94
+ if (!ext.startsWith('.'))
95
+ ext = '.' + ext;
96
+ const body = ext.slice(1);
97
+ if (!body)
98
+ return null;
99
+ if (body.includes('.') || body.includes('/') || body.includes('\\'))
100
+ return null;
101
+ return ext;
102
+ }
103
+ /**
104
+ * Parse and validate the `extensions` map out of a `codegraph.json` file.
105
+ * Every failure mode degrades to "no overrides from this entry" — a bad file or
106
+ * a typo'd language never throws.
107
+ */
108
+ function parseExtensionOverrides(file) {
109
+ let raw;
110
+ try {
111
+ raw = fs.readFileSync(file, 'utf-8');
112
+ }
113
+ catch {
114
+ return EMPTY;
115
+ }
116
+ let parsed;
117
+ try {
118
+ parsed = JSON.parse(raw);
119
+ }
120
+ catch (err) {
121
+ (0, errors_1.logWarn)(`Ignoring ${exports.PROJECT_CONFIG_FILENAME}: not valid JSON`, {
122
+ file,
123
+ error: err instanceof Error ? err.message : String(err),
124
+ });
125
+ return EMPTY;
126
+ }
127
+ if (!parsed || typeof parsed !== 'object')
128
+ return EMPTY;
129
+ const exts = parsed.extensions;
130
+ if (!exts || typeof exts !== 'object' || Array.isArray(exts))
131
+ return EMPTY;
132
+ const out = {};
133
+ for (const [rawKey, rawVal] of Object.entries(exts)) {
134
+ const key = normalizeExtKey(rawKey);
135
+ if (!key) {
136
+ (0, errors_1.logWarn)(`Ignoring extension mapping in ${exports.PROJECT_CONFIG_FILENAME}: "${rawKey}" is not a valid file extension`, { file });
137
+ continue;
138
+ }
139
+ if (typeof rawVal !== 'string' || !(0, grammars_1.isLanguageSupported)(rawVal)) {
140
+ (0, errors_1.logWarn)(`Ignoring extension "${rawKey}" in ${exports.PROJECT_CONFIG_FILENAME}: "${String(rawVal)}" is not a supported language`, { file });
141
+ continue;
142
+ }
143
+ out[key] = rawVal;
144
+ }
145
+ return Object.keys(out).length > 0 ? out : EMPTY;
146
+ }
147
+ /**
148
+ * Load the validated extension overrides for a project, mtime-cached.
149
+ *
150
+ * Returns a map of `.ext` → supported language id. The result merges on top of
151
+ * the built-in extension map at the point of use (see `detectLanguage` /
152
+ * `isSourceFile`), with these user mappings taking precedence. Returns an empty
153
+ * map when there is no `codegraph.json` (the zero-config default).
154
+ */
155
+ function loadExtensionOverrides(rootDir) {
156
+ const file = path.join(rootDir, exports.PROJECT_CONFIG_FILENAME);
157
+ let mtimeMs;
158
+ try {
159
+ mtimeMs = fs.statSync(file).mtimeMs;
160
+ }
161
+ catch {
162
+ // No config file — drop any stale cache entry and return the default.
163
+ cacheMeta.delete(rootDir);
164
+ overridesCache.delete(rootDir);
165
+ return EMPTY;
166
+ }
167
+ const meta = cacheMeta.get(rootDir);
168
+ if (meta && meta.mtimeMs === mtimeMs)
169
+ return meta.overrides;
170
+ const overrides = parseExtensionOverrides(file);
171
+ cacheMeta.set(rootDir, { mtimeMs, overrides });
172
+ overridesCache.set(rootDir, overrides);
173
+ return overrides;
174
+ }
175
+ /** Test/maintenance hook: forget cached config (e.g. after rewriting it in a test). */
176
+ function clearProjectConfigCache() {
177
+ cacheMeta.clear();
178
+ overridesCache.clear();
179
+ }
180
+ //# sourceMappingURL=project-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-config.js","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIA,wDAoBC;AAGD,0DAGC;AA1JD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,uCAAyB;AACzB,2CAA6B;AAE7B,oDAA4D;AAC5D,qCAAmC;AAEnC,oFAAoF;AACvE,QAAA,uBAAuB,GAAG,gBAAgB,CAAC;AAYxD;;;;;GAKG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,EAAoC,CAAC;AACnE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;AAEhD,uEAAuE;AACvE,MAAM,KAAK,GAA6B,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE1D;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACnC,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GA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C,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC;IAE5D,MAAM,SAAS,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAChD,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/C,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,uFAAuF;AACvF,SAAgB,uBAAuB;IACrC,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,cAAc,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,45 @@
1
+ /** Managed tier ("CodeGraph AI") — the metered gateway used when logged in. */
2
+ export declare const MANAGED_DEFAULT_URL = "https://ai.getcodegraph.com/v1";
3
+ /** The gateway's public model id (it translates this to the upstream provider id). */
4
+ export declare const MANAGED_DEFAULT_MODEL = "openai/gpt-oss-120b";
5
+ export interface OffloadConfig {
6
+ /** Managed tier: route through CodeGraph AI (metered) with the logged-in org token. */
7
+ managed?: boolean;
8
+ /** OpenAI-compatible base URL ending in `/v1` (e.g. https://api.cerebras.ai/v1). */
9
+ url?: string;
10
+ /** Model id to request (default `gpt-oss-120b` BYO, `openai/gpt-oss-120b` managed). */
11
+ model?: string;
12
+ /** Name of the env var holding the provider API key (never persisted). BYO only. */
13
+ keyEnv?: string;
14
+ /** reasoning_effort: low | medium | high (default `low`). */
15
+ effort?: string;
16
+ /** Output style: plain | report (default `plain`). */
17
+ style?: string;
18
+ }
19
+ export interface ResolvedOffload {
20
+ /** True when the offload is usable (endpoint present; for managed, a token too). */
21
+ enabled: boolean;
22
+ /** Managed tier (CodeGraph AI, metered) vs BYO endpoint. */
23
+ managed: boolean;
24
+ url?: string;
25
+ model: string;
26
+ /** Resolved API key / org token (from env, the configured `keyEnv`, or login), if any. */
27
+ apiKey?: string;
28
+ /** Where the key/token came from (for `status` display) — never the secret itself. */
29
+ keySource?: string;
30
+ effort: string;
31
+ style: string;
32
+ timeoutMs: number;
33
+ maxTokens: number;
34
+ strip: boolean;
35
+ debug: boolean;
36
+ /** Where the endpoint came from — drives `codegraph offload status`. */
37
+ origin: 'env' | 'config' | 'none';
38
+ }
39
+ /** The persisted offload block (empty object if none). */
40
+ export declare function readOffloadConfig(): OffloadConfig;
41
+ /** Persist (or, with `null`, clear) the offload block, leaving other config keys intact. */
42
+ export declare function writeOffloadConfig(offload: OffloadConfig | null): void;
43
+ /** Merge the persisted config with `CODEGRAPH_OFFLOAD_*` env overrides (env wins). */
44
+ export declare function resolveOffload(env?: NodeJS.ProcessEnv): ResolvedOffload;
45
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/reasoning/config.ts"],"names":[],"mappings":"AAqBA,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,mCAAmC,CAAC;AACpE,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC5B,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,wEAAwE;IACxE,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CACnC;AAsBD,0DAA0D;AAC1D,wBAAgB,iBAAiB,IAAI,aAAa,CAIjD;AAED,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAKtE;AAOD,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,eAAe,CAwDpF"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.MANAGED_DEFAULT_MODEL = exports.MANAGED_DEFAULT_URL = void 0;
37
+ exports.readOffloadConfig = readOffloadConfig;
38
+ exports.writeOffloadConfig = writeOffloadConfig;
39
+ exports.resolveOffload = resolveOffload;
40
+ /**
41
+ * Reasoning-offload configuration: the persistent, machine-level settings the
42
+ * `codegraph offload` CLI writes, merged with `CODEGRAPH_OFFLOAD_*` env overrides.
43
+ *
44
+ * Stored in `~/.codegraph/config.json` under the `offload` key — the same global
45
+ * home CodeGraph already uses for the daemon registry — because the reasoning
46
+ * endpoint is a per-machine choice (the model you bring), not per-project state.
47
+ * Every codegraph MCP server on the machine picks it up, so a user configures it
48
+ * once. Env vars override the file (CI / ephemeral / advanced use).
49
+ *
50
+ * For a BYO endpoint, the API key is NEVER written to disk: the CLI stores the
51
+ * NAME of an env var (`keyEnv`) and reads the key from it at call time. The
52
+ * MANAGED tier ("CodeGraph AI") instead authenticates with a revocable, org-scoped
53
+ * token from `codegraph offload login`, stored separately in `credentials.json`
54
+ * (see ./credentials) — so `config.json` itself never carries a secret either way.
55
+ */
56
+ const fs = __importStar(require("fs"));
57
+ const path = __importStar(require("path"));
58
+ const os = __importStar(require("os"));
59
+ const credentials_1 = require("./credentials");
60
+ /** Managed tier ("CodeGraph AI") — the metered gateway used when logged in. */
61
+ exports.MANAGED_DEFAULT_URL = 'https://ai.getcodegraph.com/v1';
62
+ /** The gateway's public model id (it translates this to the upstream provider id). */
63
+ exports.MANAGED_DEFAULT_MODEL = 'openai/gpt-oss-120b';
64
+ function configDir() {
65
+ return path.join(os.homedir(), '.codegraph');
66
+ }
67
+ function configPath() {
68
+ return path.join(configDir(), 'config.json');
69
+ }
70
+ function readUserConfig() {
71
+ try {
72
+ return JSON.parse(fs.readFileSync(configPath(), 'utf8'));
73
+ }
74
+ catch {
75
+ return {};
76
+ }
77
+ }
78
+ function writeUserConfig(cfg) {
79
+ fs.mkdirSync(configDir(), { recursive: true });
80
+ fs.writeFileSync(configPath(), JSON.stringify(cfg, null, 2) + '\n');
81
+ }
82
+ /** The persisted offload block (empty object if none). */
83
+ function readOffloadConfig() {
84
+ const cfg = readUserConfig();
85
+ const o = cfg.offload;
86
+ return o && typeof o === 'object' ? o : {};
87
+ }
88
+ /** Persist (or, with `null`, clear) the offload block, leaving other config keys intact. */
89
+ function writeOffloadConfig(offload) {
90
+ const cfg = readUserConfig();
91
+ if (offload === null)
92
+ delete cfg.offload;
93
+ else
94
+ cfg.offload = offload;
95
+ writeUserConfig(cfg);
96
+ }
97
+ const trimmed = (v) => {
98
+ const t = v?.trim();
99
+ return t ? t : undefined;
100
+ };
101
+ /** Merge the persisted config with `CODEGRAPH_OFFLOAD_*` env overrides (env wins). */
102
+ function resolveOffload(env = process.env) {
103
+ // Hard kill-switch: disable the offload for this process/session without touching
104
+ // the persisted config or the stored login — e.g. one A/B arm, or a user who wants
105
+ // codegraph_explore to return raw source for a session. Env-only by design.
106
+ if (env.CODEGRAPH_OFFLOAD_DISABLE === '1') {
107
+ return {
108
+ enabled: false, managed: false, url: undefined, model: exports.MANAGED_DEFAULT_MODEL,
109
+ apiKey: undefined, keySource: undefined, effort: 'low', style: 'plain',
110
+ timeoutMs: 20000, maxTokens: 12000, strip: false,
111
+ debug: env.CODEGRAPH_OFFLOAD_DEBUG === '1', origin: 'none',
112
+ };
113
+ }
114
+ const c = readOffloadConfig();
115
+ const managed = !!c.managed;
116
+ const envUrl = trimmed(env.CODEGRAPH_OFFLOAD_URL);
117
+ const envKey = trimmed(env.CODEGRAPH_OFFLOAD_KEY);
118
+ let url;
119
+ let apiKey;
120
+ let keySource;
121
+ let model;
122
+ if (managed) {
123
+ // Managed tier: default to the CodeGraph AI gateway + its public model id; the
124
+ // bearer is the org token from `codegraph offload login` (or an env override).
125
+ url = envUrl ?? trimmed(c.url) ?? exports.MANAGED_DEFAULT_URL;
126
+ model = trimmed(env.CODEGRAPH_OFFLOAD_MODEL) ?? trimmed(c.model) ?? exports.MANAGED_DEFAULT_MODEL;
127
+ if (envKey) {
128
+ apiKey = envKey;
129
+ keySource = 'CODEGRAPH_OFFLOAD_KEY';
130
+ }
131
+ else {
132
+ const t = (0, credentials_1.readOffloadToken)();
133
+ if (t) {
134
+ apiKey = t;
135
+ keySource = 'codegraph login';
136
+ }
137
+ }
138
+ }
139
+ else {
140
+ // BYO: endpoint + (optional) provider key resolved from env or the named env var.
141
+ url = envUrl ?? trimmed(c.url);
142
+ model = trimmed(env.CODEGRAPH_OFFLOAD_MODEL) ?? trimmed(c.model) ?? 'gpt-oss-120b';
143
+ if (envKey) {
144
+ apiKey = envKey;
145
+ keySource = 'CODEGRAPH_OFFLOAD_KEY';
146
+ }
147
+ else if (c.keyEnv && trimmed(env[c.keyEnv])) {
148
+ apiKey = trimmed(env[c.keyEnv]);
149
+ keySource = c.keyEnv;
150
+ }
151
+ }
152
+ const origin = envUrl ? 'env' : (managed || trimmed(c.url)) ? 'config' : 'none';
153
+ return {
154
+ // Managed needs both an endpoint AND a token (no token → effectively logged out);
155
+ // BYO needs only an endpoint (some endpoints require no auth).
156
+ enabled: managed ? (!!url && !!apiKey) : !!url,
157
+ managed,
158
+ url,
159
+ model,
160
+ apiKey,
161
+ keySource,
162
+ effort: trimmed(env.CODEGRAPH_OFFLOAD_EFFORT) ?? trimmed(c.effort) ?? 'low',
163
+ style: trimmed(env.CODEGRAPH_OFFLOAD_STYLE) ?? trimmed(c.style) ?? 'plain',
164
+ timeoutMs: Number(env.CODEGRAPH_OFFLOAD_TIMEOUT_MS) || 20000,
165
+ maxTokens: Number(env.CODEGRAPH_OFFLOAD_MAXTOKENS) || 12000,
166
+ strip: env.CODEGRAPH_OFFLOAD_STRIP === '1',
167
+ debug: env.CODEGRAPH_OFFLOAD_DEBUG === '1',
168
+ origin,
169
+ };
170
+ }
171
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/reasoning/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,8CAIC;AAGD,gDAKC;AAQD,wCAwDC;AA/JD;;;;;;;;;;;;;;;GAeG;AACH,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,+CAAiD;AAEjD,+EAA+E;AAClE,QAAA,mBAAmB,GAAG,gCAAgC,CAAC;AACpE,sFAAsF;AACzE,QAAA,qBAAqB,GAAG,qBAAqB,CAAC;AAsC3D,SAAS,SAAS;IAChB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC;AACD,SAAS,UAAU;IACjB,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,aAAa,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,MAAM,CAAC,CAA4B,CAAC;IACtF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,GAA4B;IACnD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,0DAA0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ffloadToken(): string | undefined;
3
+ /** Persist (or, with `null`, clear) the managed-offload org token at `0600`. */
4
+ export declare function writeOffloadToken(token: string | null): void;
5
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/reasoning/credentials.ts"],"names":[],"mappings":"AA0BA,yEAAyE;AACzE,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAGrD;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAS5D"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readOffloadToken = readOffloadToken;
37
+ exports.writeOffloadToken = writeOffloadToken;
38
+ /**
39
+ * Managed-offload credentials: the CodeGraph org token that authenticates the
40
+ * managed reasoning tier against `codegraph-ai` (the metered gateway).
41
+ *
42
+ * Unlike a BYO provider key (which is never persisted — the config stores only the
43
+ * NAME of an env var), the org token IS a revocable, org-scoped auth token issued
44
+ * to this machine — like the token `gh auth` or `npm login` stores. So it lives in
45
+ * its own file, `~/.codegraph/credentials.json`, written `0600`, kept out of the
46
+ * shareable `config.json`.
47
+ */
48
+ const fs = __importStar(require("fs"));
49
+ const path = __importStar(require("path"));
50
+ const os = __importStar(require("os"));
51
+ function credentialsPath() {
52
+ return path.join(os.homedir(), '.codegraph', 'credentials.json');
53
+ }
54
+ function read() {
55
+ try {
56
+ return JSON.parse(fs.readFileSync(credentialsPath(), 'utf8'));
57
+ }
58
+ catch {
59
+ return {};
60
+ }
61
+ }
62
+ /** The stored managed-offload org token, if the machine is logged in. */
63
+ function readOffloadToken() {
64
+ const t = read().offloadToken;
65
+ return typeof t === 'string' && t.trim() ? t.trim() : undefined;
66
+ }
67
+ /** Persist (or, with `null`, clear) the managed-offload org token at `0600`. */
68
+ function writeOffloadToken(token) {
69
+ const p = credentialsPath();
70
+ fs.mkdirSync(path.dirname(p), { recursive: true });
71
+ const creds = read();
72
+ if (token === null)
73
+ delete creds.offloadToken;
74
+ else
75
+ creds.offloadToken = token;
76
+ // Write restrictively: create at 0600, and tighten an existing file too.
77
+ fs.writeFileSync(p, JSON.stringify(creds, null, 2) + '\n', { mode: 0o600 });
78
+ try {
79
+ fs.chmodSync(p, 0o600);
80
+ }
81
+ catch { /* best-effort on platforms without POSIX modes */ }
82
+ }
83
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/reasoning/credentials.ts"],"names":[],"mappings":";;;;;;;;;;;;;;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AAC;IAC5E,IAAI,CAAC;QAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,kDAAkD,CAAC,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,21 @@
1
+ /** Dashboard base for the device-login endpoints; override for testing via CODEGRAPH_LOGIN_URL. */
2
+ export declare function loginBaseUrl(): string;
3
+ /** The dashboard's response to a device-authorization start request. */
4
+ export interface DeviceStart {
5
+ device_code: string;
6
+ user_code: string;
7
+ verification_uri: string;
8
+ /** Same URL with the code prefilled, for one-click open. */
9
+ verification_uri_complete?: string;
10
+ /** Seconds the CLI should wait between polls. */
11
+ interval?: number;
12
+ /** Seconds until the request expires. */
13
+ expires_in?: number;
14
+ }
15
+ /** Begin a device-authorization request. */
16
+ export declare function startDeviceLogin(): Promise<DeviceStart>;
17
+ /** Poll until the user approves in the browser; resolves with the org token. */
18
+ export declare function pollForToken(deviceCode: string, intervalSec: number, expiresInSec: number): Promise<string>;
19
+ /** Best-effort: open a URL in the default browser. Never throws — the URL is also printed. */
20
+ export declare function openBrowser(url: string): Promise<void>;
21
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/reasoning/login.ts"],"names":[],"mappings":"AAeA,mGAAmG;AACnG,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED,wEAAwE;AACxE,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,4CAA4C;AAC5C,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,WAAW,CAAC,CAY7D;AAED,gFAAgF;AAChF,wBAAsB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBjH;AAED,8FAA8F;AAC9F,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAY5D"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loginBaseUrl = loginBaseUrl;
4
+ exports.startDeviceLogin = startDeviceLogin;
5
+ exports.pollForToken = pollForToken;
6
+ exports.openBrowser = openBrowser;
7
+ /**
8
+ * Managed-login device flow for `codegraph login`.
9
+ *
10
+ * Opens the user's browser to the CodeGraph dashboard, where they authorize with
11
+ * their account; the CLI meanwhile polls for the minted, org-scoped token and
12
+ * stores it (see ./credentials + ./config) to turn on managed reasoning.
13
+ *
14
+ * This talks to the DASHBOARD (app.getcodegraph.com), not the metered gateway —
15
+ * it's a plain OAuth-style device handshake (RFC 8628 shape), nothing proprietary.
16
+ * The resulting token is what authenticates the managed reasoning calls (./reasoner).
17
+ */
18
+ const child_process_1 = require("child_process");
19
+ const DEFAULT_BASE = 'https://app.getcodegraph.com';
20
+ /** Dashboard base for the device-login endpoints; override for testing via CODEGRAPH_LOGIN_URL. */
21
+ function loginBaseUrl() {
22
+ const raw = process.env.CODEGRAPH_LOGIN_URL?.trim() || DEFAULT_BASE;
23
+ return raw.replace(/\/+$/, '');
24
+ }
25
+ /** Begin a device-authorization request. */
26
+ async function startDeviceLogin() {
27
+ const base = loginBaseUrl();
28
+ const res = await fetch(`${base}/api/cli/device/start`, {
29
+ method: 'POST',
30
+ headers: { 'content-type': 'application/json' },
31
+ body: '{}',
32
+ }).catch(() => null);
33
+ if (!res)
34
+ throw new Error(`couldn't reach ${base} — check your connection`);
35
+ if (!res.ok)
36
+ throw new Error(`couldn't start login (HTTP ${res.status})`);
37
+ const j = (await res.json().catch(() => null));
38
+ if (!j?.device_code || !j.user_code)
39
+ throw new Error('login start returned an unexpected response');
40
+ return j;
41
+ }
42
+ /** Poll until the user approves in the browser; resolves with the org token. */
43
+ async function pollForToken(deviceCode, intervalSec, expiresInSec) {
44
+ const deadline = Date.now() + Math.max(30, expiresInSec || 600) * 1000;
45
+ let waitMs = Math.max(2, intervalSec || 5) * 1000;
46
+ const base = loginBaseUrl();
47
+ while (Date.now() < deadline) {
48
+ await new Promise((r) => setTimeout(r, waitMs));
49
+ const res = await fetch(`${base}/api/cli/device/token`, {
50
+ method: 'POST',
51
+ headers: { 'content-type': 'application/json' },
52
+ body: JSON.stringify({ device_code: deviceCode }),
53
+ }).catch(() => null);
54
+ if (!res)
55
+ continue; // transient network blip — keep polling until the deadline
56
+ if (res.status === 200) {
57
+ const j = (await res.json().catch(() => null));
58
+ if (j?.token)
59
+ return j.token;
60
+ }
61
+ else if (res.status === 429) {
62
+ waitMs += 2000; // server asked us to slow down
63
+ }
64
+ else if (res.status === 404 || res.status === 410) {
65
+ throw new Error('the login request expired — run `codegraph login` again');
66
+ }
67
+ // 202 (authorization pending) → keep waiting
68
+ }
69
+ throw new Error('login timed out before you approved — run `codegraph login` again');
70
+ }
71
+ /** Best-effort: open a URL in the default browser. Never throws — the URL is also printed. */
72
+ async function openBrowser(url) {
73
+ const [cmd, args] = process.platform === 'darwin' ? ['open', [url]]
74
+ : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]]
75
+ : ['xdg-open', [url]];
76
+ try {
77
+ const child = (0, child_process_1.spawn)(cmd, args, { stdio: 'ignore', detached: true });
78
+ child.on('error', () => { });
79
+ child.unref();
80
+ }
81
+ catch {
82
+ /* the URL is printed for manual open */
83
+ }
84
+ }
85
+ //# sourceMappingURL=login.js.map