graphite-code 0.3.0__py3-none-any.whl

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 (112) hide show
  1. graphite/__init__.py +41 -0
  2. graphite/__main__.py +7 -0
  3. graphite/_cleanup_worker.py +525 -0
  4. graphite/activation.py +164 -0
  5. graphite/agent_hooks.py +577 -0
  6. graphite/agent_settings.py +226 -0
  7. graphite/analyze.py +146 -0
  8. graphite/answer_contract.py +420 -0
  9. graphite/bootstrap.py +210 -0
  10. graphite/buildlock.py +99 -0
  11. graphite/cache.py +131 -0
  12. graphite/channel.py +1325 -0
  13. graphite/cli.py +3053 -0
  14. graphite/cluster.py +111 -0
  15. graphite/config.py +209 -0
  16. graphite/context.py +355 -0
  17. graphite/daemon.py +745 -0
  18. graphite/daemon_health.py +733 -0
  19. graphite/debt.py +118 -0
  20. graphite/dependency_install.py +1597 -0
  21. graphite/detach.py +33 -0
  22. graphite/doctor.py +678 -0
  23. graphite/doctor_probes.py +2100 -0
  24. graphite/engine_identity.py +238 -0
  25. graphite/export/__init__.py +6 -0
  26. graphite/export/html.py +244 -0
  27. graphite/export/json.py +39 -0
  28. graphite/export/md.py +68 -0
  29. graphite/extract/__init__.py +4 -0
  30. graphite/extract/ast.py +1964 -0
  31. graphite/freshness.py +127 -0
  32. graphite/git.py +406 -0
  33. graphite/graph.py +117 -0
  34. graphite/graph_io.py +188 -0
  35. graphite/health.py +147 -0
  36. graphite/hook_entry.py +68 -0
  37. graphite/hookinstall.py +224 -0
  38. graphite/hookshim.py +86 -0
  39. graphite/incident_ledger.py +247 -0
  40. graphite/ingest.py +279 -0
  41. graphite/init.py +791 -0
  42. graphite/io.py +32 -0
  43. graphite/listing.py +51 -0
  44. graphite/llm.py +518 -0
  45. graphite/llm_probe.py +157 -0
  46. graphite/mcp.py +7 -0
  47. graphite/mcp_server.py +450 -0
  48. graphite/natural_query.py +252 -0
  49. graphite/overlays.py +713 -0
  50. graphite/probe_process.py +879 -0
  51. graphite/probe_workspace.py +728 -0
  52. graphite/process_contracts.py +22 -0
  53. graphite/provider_observer.py +397 -0
  54. graphite/query.py +646 -0
  55. graphite/query_plan.py +97 -0
  56. graphite/replacement_audit.py +291 -0
  57. graphite/resolve.py +660 -0
  58. graphite/review.py +782 -0
  59. graphite/routing/__init__.py +5 -0
  60. graphite/routing/approval.py +362 -0
  61. graphite/routing/classifier.py +169 -0
  62. graphite/routing/claude_executor.py +419 -0
  63. graphite/routing/claude_probe.py +102 -0
  64. graphite/routing/cli_identity.py +84 -0
  65. graphite/routing/codex_executor.py +383 -0
  66. graphite/routing/codex_probe.py +93 -0
  67. graphite/routing/context_builder.py +327 -0
  68. graphite/routing/contracts.py +802 -0
  69. graphite/routing/diff_policy.py +468 -0
  70. graphite/routing/edit_apply.py +166 -0
  71. graphite/routing/effort.py +43 -0
  72. graphite/routing/lifecycle.py +771 -0
  73. graphite/routing/lifecycle_operator.py +227 -0
  74. graphite/routing/lifecycle_service.py +555 -0
  75. graphite/routing/lifecycle_storage.py +977 -0
  76. graphite/routing/ollama_executor.py +341 -0
  77. graphite/routing/ollama_probe.py +72 -0
  78. graphite/routing/openrouter_executor.py +338 -0
  79. graphite/routing/openrouter_probe.py +188 -0
  80. graphite/routing/policy.py +815 -0
  81. graphite/routing/probe_runner.py +543 -0
  82. graphite/routing/process_runner.py +523 -0
  83. graphite/routing/profiles.py +554 -0
  84. graphite/routing/prompt.py +58 -0
  85. graphite/routing/registry.py +444 -0
  86. graphite/routing/route_pool.py +629 -0
  87. graphite/routing/route_pool_execution.py +275 -0
  88. graphite/routing/schema_validation.py +169 -0
  89. graphite/routing/service.py +1263 -0
  90. graphite/routing/settings.py +99 -0
  91. graphite/routing/shadow.py +201 -0
  92. graphite/routing/storage.py +4001 -0
  93. graphite/routing/telemetry.py +346 -0
  94. graphite/routing/worktree.py +259 -0
  95. graphite/routing/zai_edit.py +113 -0
  96. graphite/routing/zai_executor.py +191 -0
  97. graphite/routing/zai_probe.py +126 -0
  98. graphite/savings.py +84 -0
  99. graphite/ts_bridge.py +142 -0
  100. graphite/ts_resolver.mjs +314 -0
  101. graphite/typescript_activation.py +1586 -0
  102. graphite/usage_ledger.py +156 -0
  103. graphite/validation.py +148 -0
  104. graphite/watch.py +167 -0
  105. graphite/windows_job.py +368 -0
  106. graphite/windows_startup.py +144 -0
  107. graphite/windows_task.py +212 -0
  108. graphite_code-0.3.0.dist-info/METADATA +743 -0
  109. graphite_code-0.3.0.dist-info/RECORD +112 -0
  110. graphite_code-0.3.0.dist-info/WHEEL +4 -0
  111. graphite_code-0.3.0.dist-info/entry_points.txt +3 -0
  112. graphite_code-0.3.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ import { pathToFileURL } from "node:url";
4
+ import path from "node:path";
5
+
6
+ function readStdin() {
7
+ return new Promise((resolve, reject) => {
8
+ let data = "";
9
+ process.stdin.setEncoding("utf8");
10
+ process.stdin.on("data", chunk => { data += chunk; });
11
+ process.stdin.on("end", () => resolve(data));
12
+ process.stdin.on("error", reject);
13
+ });
14
+ }
15
+
16
+ function normalizePath(value) {
17
+ return value.replace(/\\/g, "/");
18
+ }
19
+
20
+ function loadTypeScript(root) {
21
+ const candidates = [
22
+ path.join(root, "package.json"),
23
+ path.join(process.cwd(), "package.json"),
24
+ path.join(path.dirname(new URL(import.meta.url).pathname), "package.json"),
25
+ ];
26
+ const errors = [];
27
+ for (const candidate of candidates) {
28
+ try {
29
+ const req = createRequire(pathToFileURL(candidate));
30
+ return { ts: req("typescript"), source: candidate };
31
+ } catch (error) {
32
+ errors.push(`${candidate}: ${error.message}`);
33
+ }
34
+ }
35
+ return { ts: null, error: errors.join("\n") };
36
+ }
37
+
38
+ function parseConfig(ts, root, files) {
39
+ const configPath = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
40
+ if (!configPath) {
41
+ return {
42
+ configPath: null,
43
+ options: {
44
+ allowJs: true,
45
+ checkJs: false,
46
+ moduleResolution: ts.ModuleResolutionKind.Node10,
47
+ target: ts.ScriptTarget.ES2022,
48
+ module: ts.ModuleKind.ESNext,
49
+ noEmit: true,
50
+ skipLibCheck: true,
51
+ },
52
+ fileNames: files,
53
+ };
54
+ }
55
+ const read = ts.readConfigFile(configPath, ts.sys.readFile);
56
+ if (read.error) {
57
+ return {
58
+ configPath,
59
+ options: { noEmit: true, skipLibCheck: true },
60
+ fileNames: files,
61
+ configError: ts.flattenDiagnosticMessageText(read.error.messageText, "\n"),
62
+ };
63
+ }
64
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(configPath));
65
+ return {
66
+ configPath,
67
+ options: { ...parsed.options, noEmit: true, skipLibCheck: true },
68
+ fileNames: files,
69
+ configError: parsed.errors?.length
70
+ ? parsed.errors.map(e => ts.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n")
71
+ : null,
72
+ };
73
+ }
74
+
75
+ function relFor(root, abs) {
76
+ const rel = normalizePath(path.relative(root, abs));
77
+ return rel && !rel.startsWith("../") && rel !== ".." ? rel : null;
78
+ }
79
+
80
+ function resolveModule(ts, host, options, root, knownFiles, containingFile, specifier) {
81
+ const result = ts.resolveModuleName(specifier, containingFile, options, host).resolvedModule;
82
+ if (!result || !result.resolvedFileName) return null;
83
+ const resolved = normalizePath(result.resolvedFileName);
84
+ if (result.isExternalLibraryImport || resolved.includes("/node_modules/")) return null;
85
+ const rel = relFor(root, resolved);
86
+ if (!rel) return null;
87
+ const withoutDts = rel.replace(/\.d\.ts$/, ".ts");
88
+ if (knownFiles.has(rel)) return rel;
89
+ if (knownFiles.has(withoutDts)) return withoutDts;
90
+ return null;
91
+ }
92
+
93
+ function lineOf(sourceFile, node) {
94
+ return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
95
+ }
96
+
97
+ function moduleText(node) {
98
+ return node && typeof node.text === "string" ? node.text : null;
99
+ }
100
+
101
+ function addUniqueEdge(edges, seen, edge) {
102
+ const key = `${edge.source}\0${edge.target}\0${edge.relation}\0${edge.confidence}`;
103
+ if (seen.has(key)) return;
104
+ seen.add(key);
105
+ edges.push(edge);
106
+ }
107
+
108
+ function collectModuleEdges(ts, program, host, options, root, knownFiles) {
109
+ const edges = [];
110
+ const seen = new Set();
111
+ for (const sourceFile of program.getSourceFiles()) {
112
+ const sourceRel = relFor(root, sourceFile.fileName);
113
+ if (!sourceRel || !knownFiles.has(sourceRel)) continue;
114
+
115
+ function addEdge(specifier, syntax, line, typeOnly = false) {
116
+ const targetRel = resolveModule(ts, host, options, root, knownFiles, sourceFile.fileName, specifier);
117
+ if (!targetRel || targetRel === sourceRel) return;
118
+ const confidence = syntax === "export"
119
+ ? "TS_COMPILER_EXPORT"
120
+ : syntax === "dynamic_import"
121
+ ? "TS_COMPILER_DYNAMIC_IMPORT"
122
+ : typeOnly
123
+ ? "TS_COMPILER_TYPE_IMPORT"
124
+ : "TS_COMPILER_IMPORT";
125
+ addUniqueEdge(edges, seen, {
126
+ source: sourceRel,
127
+ target: targetRel,
128
+ specifier,
129
+ syntax,
130
+ relation: syntax === "export" ? "exports" : "imports",
131
+ confidence,
132
+ line,
133
+ });
134
+ }
135
+
136
+ function visit(node) {
137
+ if (ts.isImportDeclaration(node)) {
138
+ const specifier = moduleText(node.moduleSpecifier);
139
+ if (specifier) addEdge(specifier, "import", lineOf(sourceFile, node), Boolean(node.importClause?.isTypeOnly));
140
+ } else if (ts.isExportDeclaration(node)) {
141
+ const specifier = moduleText(node.moduleSpecifier);
142
+ if (specifier) addEdge(specifier, "export", lineOf(sourceFile, node), Boolean(node.isTypeOnly));
143
+ } else if (
144
+ ts.isCallExpression(node)
145
+ && node.expression.kind === ts.SyntaxKind.ImportKeyword
146
+ && node.arguments.length === 1
147
+ && ts.isStringLiteralLike(node.arguments[0])
148
+ ) {
149
+ addEdge(node.arguments[0].text, "dynamic_import", lineOf(sourceFile, node), false);
150
+ }
151
+ ts.forEachChild(node, visit);
152
+ }
153
+ visit(sourceFile);
154
+ }
155
+ edges.sort(edgeSort);
156
+ return edges;
157
+ }
158
+
159
+ function collectSymbolEdges(ts, program, root, knownFiles) {
160
+ const checker = program.getTypeChecker();
161
+ const edges = [];
162
+ const seen = new Set();
163
+
164
+ for (const sourceFile of program.getSourceFiles()) {
165
+ const sourceRel = relFor(root, sourceFile.fileName);
166
+ if (!sourceRel || !knownFiles.has(sourceRel)) continue;
167
+
168
+ function visit(node) {
169
+ if (ts.isIdentifier(node) && !isDeclarationOrImportName(ts, node)) {
170
+ const edge = symbolEdgeForNode(ts, checker, root, knownFiles, sourceRel, sourceFile, node);
171
+ if (edge) addUniqueEdge(edges, seen, edge);
172
+ }
173
+ ts.forEachChild(node, visit);
174
+ }
175
+ visit(sourceFile);
176
+ }
177
+ edges.sort(edgeSort);
178
+ return edges;
179
+ }
180
+
181
+ function symbolEdgeForNode(ts, checker, root, knownFiles, sourceRel, sourceFile, node) {
182
+ let symbol = checker.getSymbolAtLocation(node);
183
+ if (!symbol) return null;
184
+ if ((symbol.flags & ts.SymbolFlags.Alias) !== 0) {
185
+ try {
186
+ symbol = checker.getAliasedSymbol(symbol);
187
+ } catch {
188
+ return null;
189
+ }
190
+ }
191
+ const declaration = firstProjectDeclaration(root, knownFiles, symbol.declarations || []);
192
+ if (!declaration) return null;
193
+ const targetRel = relFor(root, declaration.getSourceFile().fileName);
194
+ if (!targetRel || targetRel === sourceRel || !knownFiles.has(targetRel)) return null;
195
+ const typeOnly = isTypePosition(ts, node);
196
+ return {
197
+ source: sourceRel,
198
+ target: targetRel,
199
+ specifier: symbol.getName ? symbol.getName() : node.text,
200
+ syntax: typeOnly ? "type_reference" : "symbol_reference",
201
+ relation: typeOnly ? "type_references" : "references",
202
+ confidence: typeOnly ? "TS_COMPILER_TYPE_REFERENCE" : "TS_COMPILER_SYMBOL_REFERENCE",
203
+ line: lineOf(sourceFile, node),
204
+ };
205
+ }
206
+
207
+ function firstProjectDeclaration(root, knownFiles, declarations) {
208
+ for (const declaration of declarations) {
209
+ const rel = relFor(root, declaration.getSourceFile().fileName);
210
+ if (rel && knownFiles.has(rel)) return declaration;
211
+ }
212
+ return null;
213
+ }
214
+
215
+ function isDeclarationOrImportName(ts, node) {
216
+ const parent = node.parent;
217
+ if (!parent) return false;
218
+ if (parent.name === node) {
219
+ return ts.isClassDeclaration(parent)
220
+ || ts.isFunctionDeclaration(parent)
221
+ || ts.isVariableDeclaration(parent)
222
+ || ts.isParameter(parent)
223
+ || ts.isPropertyDeclaration(parent)
224
+ || ts.isMethodDeclaration(parent)
225
+ || ts.isInterfaceDeclaration(parent)
226
+ || ts.isTypeAliasDeclaration(parent)
227
+ || ts.isEnumDeclaration(parent)
228
+ || ts.isImportClause(parent)
229
+ || ts.isNamespaceImport(parent)
230
+ || ts.isImportSpecifier(parent)
231
+ || ts.isExportSpecifier(parent)
232
+ || ts.isPropertySignature(parent)
233
+ || ts.isMethodSignature(parent);
234
+ }
235
+ return ts.isImportSpecifier(parent)
236
+ || ts.isExportSpecifier(parent)
237
+ || ts.isImportClause(parent)
238
+ || ts.isNamespaceImport(parent)
239
+ || ts.isImportDeclaration(parent)
240
+ || ts.isExportDeclaration(parent);
241
+ }
242
+
243
+ function isTypePosition(ts, node) {
244
+ let current = node;
245
+ while (current.parent) {
246
+ const parent = current.parent;
247
+ if (
248
+ parent.kind === ts.SyntaxKind.TypeReference
249
+ || parent.kind === ts.SyntaxKind.TypeQuery
250
+ || parent.kind === ts.SyntaxKind.TypeLiteral
251
+ || parent.kind === ts.SyntaxKind.TypeAliasDeclaration
252
+ || parent.kind === ts.SyntaxKind.InterfaceDeclaration
253
+ || parent.kind === ts.SyntaxKind.ExpressionWithTypeArguments
254
+ || parent.kind === ts.SyntaxKind.HeritageClause
255
+ || parent.type === current
256
+ || parent.typeName === current
257
+ ) {
258
+ return true;
259
+ }
260
+ if (
261
+ ts.isCallExpression(parent)
262
+ || ts.isNewExpression(parent)
263
+ || ts.isExpressionStatement(parent)
264
+ || ts.isBinaryExpression(parent)
265
+ || ts.isPropertyAccessExpression(parent)
266
+ ) {
267
+ return false;
268
+ }
269
+ current = parent;
270
+ }
271
+ return false;
272
+ }
273
+
274
+ function edgeSort(a, b) {
275
+ return `${a.source}\0${a.relation}\0${a.confidence}\0${a.specifier}\0${a.target}`
276
+ .localeCompare(`${b.source}\0${b.relation}\0${b.confidence}\0${b.specifier}\0${b.target}`);
277
+ }
278
+
279
+ try {
280
+ const input = JSON.parse(await readStdin());
281
+ const root = path.resolve(input.root);
282
+ const relFiles = Array.isArray(input.files) ? input.files.map(normalizePath) : [];
283
+ const absFiles = relFiles.map(file => path.resolve(root, file));
284
+ const knownFiles = new Set(relFiles);
285
+ const loaded = loadTypeScript(root);
286
+ if (!loaded.ts) {
287
+ console.log(JSON.stringify({ ok: false, reason: "typescript_not_available", detail: loaded.error }));
288
+ process.exit(0);
289
+ }
290
+ const ts = loaded.ts;
291
+ const parsed = parseConfig(ts, root, absFiles);
292
+ const host = ts.createCompilerHost(parsed.options, true);
293
+ const program = ts.createProgram(absFiles, parsed.options, host);
294
+ const moduleEdges = collectModuleEdges(ts, program, host, parsed.options, root, knownFiles);
295
+ const symbolEdges = input.symbolReferences === false ? [] : collectSymbolEdges(ts, program, root, knownFiles);
296
+ const edges = [...moduleEdges, ...symbolEdges].sort(edgeSort);
297
+ console.log(JSON.stringify({
298
+ ok: true,
299
+ typescriptVersion: ts.version,
300
+ typescriptSource: loaded.source,
301
+ configPath: parsed.configPath ? normalizePath(path.relative(root, parsed.configPath)) : null,
302
+ configError: parsed.configError || null,
303
+ fileCount: relFiles.length,
304
+ moduleEdgeCount: moduleEdges.length,
305
+ symbolEdgeCount: symbolEdges.length,
306
+ edges,
307
+ }));
308
+ } catch (error) {
309
+ console.log(JSON.stringify({ ok: false, reason: "resolver_error", detail: error?.stack || String(error) }));
310
+ process.exit(0);
311
+ }
312
+
313
+
314
+