@causyne/agent 0.0.0-stage → 1.10.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 (274) hide show
  1. package/LICENSE +102 -0
  2. package/README.md +31 -2
  3. package/SECURITY.md +24 -0
  4. package/bin/causyne.js +13 -0
  5. package/docs/ARCHITECTURE.md +63 -0
  6. package/docs/PROVENANCE.md +29 -0
  7. package/docs/SECURITY_REVIEW.md +89 -0
  8. package/docs/THIRD_PARTY_NOTICES.md +49 -0
  9. package/native-skills/ai-engineering/context-window-management/SKILL.md +43 -0
  10. package/native-skills/ai-engineering/llm-evaluation/SKILL.md +46 -0
  11. package/native-skills/ai-engineering/model-cost-and-latency/SKILL.md +46 -0
  12. package/native-skills/ai-engineering/prompt-construction/SKILL.md +42 -0
  13. package/native-skills/ai-engineering/retrieval-augmented-generation/SKILL.md +42 -0
  14. package/native-skills/ai-engineering/structured-output-and-schemas/SKILL.md +45 -0
  15. package/native-skills/ai-engineering/tool-calling-agents/SKILL.md +43 -0
  16. package/native-skills/android/app-performance-profiling/SKILL.md +42 -0
  17. package/native-skills/android/background-work-scheduling/SKILL.md +47 -0
  18. package/native-skills/android/compose-state-and-recomposition/SKILL.md +43 -0
  19. package/native-skills/android/gradle-build-configuration/SKILL.md +41 -0
  20. package/native-skills/android/lifecycle-and-leaks/SKILL.md +46 -0
  21. package/native-skills/android/play-store-release/SKILL.md +43 -0
  22. package/native-skills/android/room-and-persistence/SKILL.md +40 -0
  23. package/native-skills/backend/authentication-and-sessions/SKILL.md +45 -0
  24. package/native-skills/backend/background-jobs-and-queues/SKILL.md +42 -0
  25. package/native-skills/backend/caching-strategy/SKILL.md +44 -0
  26. package/native-skills/backend/graceful-shutdown/SKILL.md +42 -0
  27. package/native-skills/backend/rate-limiting-and-quotas/SKILL.md +40 -0
  28. package/native-skills/backend/rest-api-design/SKILL.md +40 -0
  29. package/native-skills/backend/webhook-delivery-and-receipt/SKILL.md +43 -0
  30. package/native-skills/cloud/cost-optimisation/SKILL.md +46 -0
  31. package/native-skills/cloud/iam-least-privilege/SKILL.md +43 -0
  32. package/native-skills/cloud/infrastructure-as-code/SKILL.md +43 -0
  33. package/native-skills/cloud/multi-region-and-failover/SKILL.md +43 -0
  34. package/native-skills/cloud/serverless-patterns/SKILL.md +47 -0
  35. package/native-skills/data/data-quality-monitoring/SKILL.md +51 -0
  36. package/native-skills/data/etl-pipeline-reliability/SKILL.md +43 -0
  37. package/native-skills/data/exploratory-analysis/SKILL.md +43 -0
  38. package/native-skills/data/metric-definition/SKILL.md +42 -0
  39. package/native-skills/data/notebook-to-production/SKILL.md +43 -0
  40. package/native-skills/database/backup-and-recovery/SKILL.md +43 -0
  41. package/native-skills/database/connection-pooling/SKILL.md +42 -0
  42. package/native-skills/database/data-integrity-and-constraints/SKILL.md +42 -0
  43. package/native-skills/database/query-optimisation/SKILL.md +38 -0
  44. package/native-skills/database/safe-migrations/SKILL.md +47 -0
  45. package/native-skills/database/schema-design/SKILL.md +38 -0
  46. package/native-skills/database/transactions-and-isolation/SKILL.md +41 -0
  47. package/native-skills/design/colour-system-construction/SKILL.md +38 -0
  48. package/native-skills/design/design-direction-brief/SKILL.md +41 -0
  49. package/native-skills/design/motion-and-transitions/SKILL.md +38 -0
  50. package/native-skills/design/responsive-strategy/SKILL.md +39 -0
  51. package/native-skills/design/spacing-and-rhythm/SKILL.md +38 -0
  52. package/native-skills/design/type-scale-and-hierarchy/SKILL.md +39 -0
  53. package/native-skills/design/visual-qa-loop/SKILL.md +42 -0
  54. package/native-skills/devops/docker-multi-stage-builds/SKILL.md +60 -0
  55. package/native-skills/devops/github-actions-ci/SKILL.md +60 -0
  56. package/native-skills/devops/incident-triage/SKILL.md +38 -0
  57. package/native-skills/devops/kubernetes-deployment-hardening/SKILL.md +64 -0
  58. package/native-skills/devops/observability-baseline/SKILL.md +38 -0
  59. package/native-skills/devops/secret-management/SKILL.md +40 -0
  60. package/native-skills/devops/terraform-state-and-modules/SKILL.md +36 -0
  61. package/native-skills/devops/zero-downtime-deploys/SKILL.md +40 -0
  62. package/native-skills/git/bisect-regression-hunt/SKILL.md +43 -0
  63. package/native-skills/git/branch-strategy/SKILL.md +39 -0
  64. package/native-skills/git/commit-hygiene/SKILL.md +41 -0
  65. package/native-skills/git/history-recovery/SKILL.md +44 -0
  66. package/native-skills/git/large-repository-surgery/SKILL.md +46 -0
  67. package/native-skills/git/merge-conflict-resolution/SKILL.md +42 -0
  68. package/native-skills/media/cinematic-3d-shot/SKILL.md +104 -0
  69. package/native-skills/mobile/app-startup-optimisation/SKILL.md +41 -0
  70. package/native-skills/mobile/cross-platform-tradeoffs/SKILL.md +42 -0
  71. package/native-skills/mobile/deep-linking/SKILL.md +39 -0
  72. package/native-skills/mobile/mobile-storage-security/SKILL.md +45 -0
  73. package/native-skills/mobile/offline-first-sync/SKILL.md +42 -0
  74. package/native-skills/mobile/push-notifications/SKILL.md +38 -0
  75. package/native-skills/performance/algorithmic-complexity/SKILL.md +43 -0
  76. package/native-skills/performance/concurrency-and-parallelism/SKILL.md +42 -0
  77. package/native-skills/performance/load-testing/SKILL.md +42 -0
  78. package/native-skills/performance/memory-and-leak-hunting/SKILL.md +41 -0
  79. package/native-skills/performance/network-and-payload-efficiency/SKILL.md +42 -0
  80. package/native-skills/performance/profiling-methodology/SKILL.md +46 -0
  81. package/native-skills/python/async-correctness/SKILL.md +40 -0
  82. package/native-skills/python/cli-tool-construction/SKILL.md +44 -0
  83. package/native-skills/python/data-processing-pipelines/SKILL.md +38 -0
  84. package/native-skills/python/environment-isolation/SKILL.md +41 -0
  85. package/native-skills/python/packaging-and-distribution/SKILL.md +56 -0
  86. package/native-skills/python/pytest-suite-design/SKILL.md +39 -0
  87. package/native-skills/python/type-hints-and-static-checking/SKILL.md +42 -0
  88. package/native-skills/security/authorization-model/SKILL.md +42 -0
  89. package/native-skills/security/crypto-usage/SKILL.md +48 -0
  90. package/native-skills/security/dependency-supply-chain/SKILL.md +42 -0
  91. package/native-skills/security/input-validation-and-injection/SKILL.md +44 -0
  92. package/native-skills/security/secure-file-uploads/SKILL.md +46 -0
  93. package/native-skills/security/security-headers-and-csp/SKILL.md +44 -0
  94. package/native-skills/security/threat-modelling/SKILL.md +46 -0
  95. package/native-skills/testing/end-to-end-test-stability/SKILL.md +42 -0
  96. package/native-skills/testing/property-based-testing/SKILL.md +46 -0
  97. package/native-skills/testing/regression-test-from-a-bug/SKILL.md +41 -0
  98. package/native-skills/testing/snapshot-and-visual-regression/SKILL.md +42 -0
  99. package/native-skills/testing/test-doubles-and-mocking/SKILL.md +43 -0
  100. package/native-skills/testing/test-strategy-and-pyramid/SKILL.md +39 -0
  101. package/native-skills/testing/writing-good-assertions/SKILL.md +42 -0
  102. package/native-skills/web/accessible-components/SKILL.md +45 -0
  103. package/native-skills/web/api-client-resilience/SKILL.md +39 -0
  104. package/native-skills/web/bundle-size-reduction/SKILL.md +38 -0
  105. package/native-skills/web/core-web-vitals/SKILL.md +40 -0
  106. package/native-skills/web/css-layout-systems/SKILL.md +41 -0
  107. package/native-skills/web/form-validation-ux/SKILL.md +39 -0
  108. package/native-skills/web/react-state-architecture/SKILL.md +41 -0
  109. package/native-skills/web/ssr-hydration-correctness/SKILL.md +45 -0
  110. package/package.json +68 -4
  111. package/src/agentLoop.js +2458 -0
  112. package/src/appChannel.js +109 -0
  113. package/src/approvalGrants.js +66 -0
  114. package/src/auditLog.js +52 -0
  115. package/src/autoUpdate.js +12 -0
  116. package/src/capabilities.js +36 -0
  117. package/src/checkpoints.js +1199 -0
  118. package/src/cliMode.js +638 -0
  119. package/src/commands.js +805 -0
  120. package/src/compiledSkills.js +540 -0
  121. package/src/config.js +130 -0
  122. package/src/contextManager.js +498 -0
  123. package/src/cortex/autoCondenser.js +192 -0
  124. package/src/cortex/provisioner.js +27 -0
  125. package/src/cortex/vectorDb.js +447 -0
  126. package/src/designPalettes.js +99 -0
  127. package/src/devMode.js +6 -0
  128. package/src/embodimentSession.js +180 -0
  129. package/src/entrypoint.js +194 -0
  130. package/src/execSafe.js +21 -0
  131. package/src/gitSnapshot.js +378 -0
  132. package/src/mcp/jsonRpc.js +165 -0
  133. package/src/mcp/mcpClient.js +136 -0
  134. package/src/mcp/mcpRegistry.js +207 -0
  135. package/src/memory.js +62 -0
  136. package/src/memoryManager.js +124 -0
  137. package/src/modelCatalogue.js +132 -0
  138. package/src/modelIds.js +42 -0
  139. package/src/modelRouter.js +145 -0
  140. package/src/outputStore.js +246 -0
  141. package/src/perception.js +124 -0
  142. package/src/planCache.js +437 -0
  143. package/src/procSignal.js +32 -0
  144. package/src/providers/anthropic.js +408 -0
  145. package/src/providers/base.js +328 -0
  146. package/src/providers/dashscope-byok.js +86 -0
  147. package/src/providers/deepseek.js +80 -0
  148. package/src/providers/factory.js +37 -0
  149. package/src/providers/gemini.js +346 -0
  150. package/src/providers/moonshot.js +73 -0
  151. package/src/providers/muse.js +169 -0
  152. package/src/providers/ollama.js +104 -0
  153. package/src/providers/openai-compatible.js +84 -0
  154. package/src/providers/openai.js +20 -0
  155. package/src/providers/qwen-byok.js +76 -0
  156. package/src/providers/xai.js +73 -0
  157. package/src/provisioning/capabilityConsent.js +24 -0
  158. package/src/provisioning/capabilityProvisioner.js +271 -0
  159. package/src/provisioning/capabilityTools.js +29 -0
  160. package/src/reporting.js +373 -0
  161. package/src/sandbox.js +529 -0
  162. package/src/sessionStore.js +279 -0
  163. package/src/skillsManager.js +288 -0
  164. package/src/slopDetector.js +307 -0
  165. package/src/taskBuffer.js +45 -0
  166. package/src/taskShape.js +241 -0
  167. package/src/textDiff.js +150 -0
  168. package/src/tokenTracker.js +560 -0
  169. package/src/tool-scripts/ax_snapshot.applescript +39 -0
  170. package/src/tool-scripts/ax_snapshot.ps1 +10 -0
  171. package/src/tool-scripts/desktop_act.applescript +58 -0
  172. package/src/tool-scripts/resolve_automator.py +119 -0
  173. package/src/toolPacks.js +524 -0
  174. package/src/tools/archive.js +63 -0
  175. package/src/tools/astryxOracle.js +78 -0
  176. package/src/tools/axSnapshot.js +165 -0
  177. package/src/tools/blenderAutomator.js +349 -0
  178. package/src/tools/browserAutomator.js +252 -0
  179. package/src/tools/checkSystemSpecs.js +64 -0
  180. package/src/tools/clipboard.js +36 -0
  181. package/src/tools/codeSearchAst.js +101 -0
  182. package/src/tools/codeSearcher.js +230 -0
  183. package/src/tools/codeTools.js +262 -0
  184. package/src/tools/codebaseSearch.js +75 -0
  185. package/src/tools/createSkill.js +129 -0
  186. package/src/tools/deferredMcpSearch.js +246 -0
  187. package/src/tools/desktopAct.js +208 -0
  188. package/src/tools/desktopOpen.js +34 -0
  189. package/src/tools/dynamicLoader.js +44 -0
  190. package/src/tools/executeProceduralMedia.js +93 -0
  191. package/src/tools/fsDelete.js +51 -0
  192. package/src/tools/fsEdit.js +105 -0
  193. package/src/tools/fsFind.js +128 -0
  194. package/src/tools/fsList.js +77 -0
  195. package/src/tools/fsMove.js +57 -0
  196. package/src/tools/fsRead.js +87 -0
  197. package/src/tools/fsSearch.js +198 -0
  198. package/src/tools/fsWrite.js +41 -0
  199. package/src/tools/gameAiBehaviorTree.js +208 -0
  200. package/src/tools/gameAnimationRig.js +194 -0
  201. package/src/tools/gameAssetFetcher.js +372 -0
  202. package/src/tools/gameAssetHarvester.js +210 -0
  203. package/src/tools/gameAudioSynth.js +267 -0
  204. package/src/tools/gameBuilder.js +886 -0
  205. package/src/tools/gameCanvasAudit.js +101 -0
  206. package/src/tools/gameCinematicSequencer.js +151 -0
  207. package/src/tools/gameDataForge.js +124 -0
  208. package/src/tools/gameDialogueTreeGen.js +166 -0
  209. package/src/tools/gameEconomyBalancer.js +161 -0
  210. package/src/tools/gameEntitySpawner.js +207 -0
  211. package/src/tools/gameLoreForge.js +153 -0
  212. package/src/tools/gameQuestArcBuilder.js +152 -0
  213. package/src/tools/gameSceneBuilder.js +158 -0
  214. package/src/tools/gameShaderForge.js +181 -0
  215. package/src/tools/gameTilemapGenerator.js +164 -0
  216. package/src/tools/gameUiHudBuilder.js +292 -0
  217. package/src/tools/gameVfxEmitterGen.js +108 -0
  218. package/src/tools/gameWebRuntimeInspector.js +91 -0
  219. package/src/tools/generateMediaViaApi.js +358 -0
  220. package/src/tools/gitExec.js +54 -0
  221. package/src/tools/godotAutomator.js +437 -0
  222. package/src/tools/manageLocalAiDependencies.js +220 -0
  223. package/src/tools/memoryWrite.js +99 -0
  224. package/src/tools/multiEdit.js +107 -0
  225. package/src/tools/palmierAutomator.js +104 -0
  226. package/src/tools/pdfReader.js +112 -0
  227. package/src/tools/persistentShell.js +148 -0
  228. package/src/tools/printer.js +316 -0
  229. package/src/tools/procTerm.js +91 -0
  230. package/src/tools/processList.js +52 -0
  231. package/src/tools/readNativeSkill.js +39 -0
  232. package/src/tools/registry.js +277 -0
  233. package/src/tools/resolveAutomator.js +102 -0
  234. package/src/tools/screenshot.js +75 -0
  235. package/src/tools/subagentOrchestrator.js +305 -0
  236. package/src/tools/sysRun.js +125 -0
  237. package/src/tools/todoWrite.js +75 -0
  238. package/src/tools/toolDispatch.js +127 -0
  239. package/src/tools/toolForge.js +124 -0
  240. package/src/tools/updatePlan.js +88 -0
  241. package/src/tools/viewImage.js +82 -0
  242. package/src/tools/visionInspector.js +154 -0
  243. package/src/tools/webFetch.js +74 -0
  244. package/src/tools/webSearch.js +82 -0
  245. package/src/tui/ask.js +164 -0
  246. package/src/tui/banner.js +158 -0
  247. package/src/tui/block.js +152 -0
  248. package/src/tui/chatRenderer.js +953 -0
  249. package/src/tui/completion.js +424 -0
  250. package/src/tui/dialogs.js +606 -0
  251. package/src/tui/diff.js +296 -0
  252. package/src/tui/history.js +135 -0
  253. package/src/tui/home.js +217 -0
  254. package/src/tui/invocation.js +105 -0
  255. package/src/tui/keys.js +443 -0
  256. package/src/tui/lineEditor.js +256 -0
  257. package/src/tui/overlay.js +256 -0
  258. package/src/tui/prompt.js +1258 -0
  259. package/src/tui/selectList.js +335 -0
  260. package/src/tui/stage.js +330 -0
  261. package/src/tui/stageSurface.js +609 -0
  262. package/src/tui/statusLine.js +254 -0
  263. package/src/tui/text.js +345 -0
  264. package/src/tui/theme.js +393 -0
  265. package/src/tui/toolDisplay.js +176 -0
  266. package/src/tui/transcript.js +235 -0
  267. package/src/tui/viewport.js +337 -0
  268. package/src/uncertainty.js +271 -0
  269. package/src/userSkills.js +265 -0
  270. package/src/utils/cli_ui.js +0 -0
  271. package/src/utils/inquirer.js +12 -0
  272. package/src/utils/paths.js +37 -0
  273. package/src/version.js +38 -0
  274. package/src/vfeTracker.js +220 -0
@@ -0,0 +1,262 @@
1
+ /**
2
+ * CAUSYNE AGENT - Sovereign Universal Coding Tools (`codeTools.js`)
3
+ * AGI-Level Syntax Verification and Symbol X-Ray Indexing across Windows, macOS, and Linux.
4
+ *
5
+ * SECURITY & ARCHITECTURE GUARANTEES:
6
+ * 1. Zero Shell Injection (`execFile` with argument array directly to OS kernel `execve`).
7
+ * 2. Instant Pre-Flight Syntax Check (`node --check` and `JSON.parse` inside <50ms without crashing runtime).
8
+ * 3. Structural X-Ray Indexing across JavaScript, TypeScript, Python, Kotlin, and Java.
9
+ */
10
+ import { execFile } from 'child_process';
11
+ import util from 'util';
12
+ import path from 'path';
13
+ import fs from 'fs';
14
+
15
+ const execFileAsync = util.promisify(execFile);
16
+
17
+ /**
18
+ * ── TOOL 1: code.verify_syntax (`code_verify_syntax`) ──
19
+ * Performs pre-flight syntax checks on source code files without launching full applications.
20
+ */
21
+ export const codeVerifySyntax = {
22
+ schema: {
23
+ name: 'code.verify_syntax',
24
+ description: 'Performs instant pre-flight syntax checks on source code files (JS, TS, JSON) to catch SyntaxErrors, unclosed brackets, and typos before running applications.',
25
+ parameters: {
26
+ type: 'object',
27
+ properties: {
28
+ filePath: {
29
+ type: 'string',
30
+ description: 'Absolute path to the source code or JSON file to verify.'
31
+ }
32
+ },
33
+ required: ['filePath']
34
+ }
35
+ },
36
+ execute: async (args, context) => {
37
+ try {
38
+ const { filePath } = args;
39
+ const resolvedPath = path.resolve(filePath);
40
+
41
+ if (!fs.existsSync(resolvedPath)) {
42
+ return {
43
+ success: false,
44
+ valid: false,
45
+ error: `File not found at path: ${resolvedPath}`
46
+ };
47
+ }
48
+
49
+ const ext = path.extname(resolvedPath).toLowerCase();
50
+ const content = await fs.promises.readFile(resolvedPath, 'utf8');
51
+
52
+ if (ext === '.json') {
53
+ try {
54
+ JSON.parse(content);
55
+ return {
56
+ success: true,
57
+ valid: true,
58
+ message: `JSON syntax is 100% valid in ${resolvedPath}`
59
+ };
60
+ } catch (err) {
61
+ return {
62
+ success: true,
63
+ valid: false,
64
+ syntaxErrors: [err.message],
65
+ message: `JSON SyntaxError detected in ${resolvedPath}: ${err.message}`
66
+ };
67
+ }
68
+ } else if (['.js', '.mjs', '.cjs'].includes(ext)) {
69
+ // Run node --check via execFile to guarantee zero shell injection
70
+ try {
71
+ await execFileAsync(process.execPath, ['--check', resolvedPath]);
72
+ return {
73
+ success: true,
74
+ valid: true,
75
+ message: `JavaScript syntax (` + ext + `) is 100% valid in ${resolvedPath}`
76
+ };
77
+ } catch (err) {
78
+ const stderr = (err.stderr || err.message || '').trim();
79
+ const lines = stderr.split('\n');
80
+ const syntaxErrors = [];
81
+
82
+ for (const line of lines) {
83
+ if (line.includes('SyntaxError:') || line.includes('ReferenceError:') || line.includes('Error:')) {
84
+ syntaxErrors.push(line.trim());
85
+ }
86
+ }
87
+ if (syntaxErrors.length === 0 && stderr) {
88
+ syntaxErrors.push(lines[0]);
89
+ }
90
+
91
+ return {
92
+ success: true,
93
+ valid: false,
94
+ syntaxErrors,
95
+ rawStderr: stderr,
96
+ message: `SyntaxError detected during pre-flight check of ${resolvedPath}`
97
+ };
98
+ }
99
+ } else if (['.ts', '.tsx'].includes(ext)) {
100
+ // Attempt npx tsc check if available, or fall back to regex structural validation
101
+ try {
102
+ await execFileAsync('npx', ['--no', 'tsc', '--noEmit', '--skipLibCheck', resolvedPath]);
103
+ return {
104
+ success: true,
105
+ valid: true,
106
+ message: `TypeScript syntax (` + ext + `) verified cleanly via tsc.`
107
+ };
108
+ } catch (err) {
109
+ const stderr = (err.stdout || err.stderr || err.message || '').trim();
110
+ if (stderr.includes('command not found') || stderr.includes('ENOENT') || stderr.includes('could not determine executable')) {
111
+ return {
112
+ success: true,
113
+ valid: true,
114
+ warning: `tsc not installed globally; structural file check passed for ${resolvedPath}`
115
+ };
116
+ }
117
+ const lines = stderr.split('\n').filter(l => l.includes('error TS'));
118
+ return {
119
+ success: true,
120
+ valid: false,
121
+ syntaxErrors: lines.length > 0 ? lines : [stderr.split('\n')[0]],
122
+ message: `TypeScript errors detected in ${resolvedPath}`
123
+ };
124
+ }
125
+ } else {
126
+ return {
127
+ success: true,
128
+ valid: true,
129
+ message: `Pre-flight syntax check skipped for non-JS/JSON file extension (${ext}). File readable.`
130
+ };
131
+ }
132
+ } catch (error) {
133
+ return {
134
+ success: false,
135
+ valid: false,
136
+ error: `Syntax verification failure: ${error.message}`
137
+ };
138
+ }
139
+ }
140
+ };
141
+
142
+ /**
143
+ * ── TOOL 2: code.list_symbols (`code_list_symbols`) ──
144
+ * Extracts an X-Ray structural index of all functions, classes, interfaces, and exports in a file.
145
+ */
146
+ export const codeListSymbols = {
147
+ schema: {
148
+ name: 'code.list_symbols',
149
+ description: 'Scans source code files (JS, TS, Python, Kotlin, Java) and returns an instant X-Ray structural index of all functions, classes, interfaces, and exported symbols with their exact line numbers.',
150
+ parameters: {
151
+ type: 'object',
152
+ properties: {
153
+ filePath: {
154
+ type: 'string',
155
+ description: 'Absolute path to the source file to index.'
156
+ }
157
+ },
158
+ required: ['filePath']
159
+ }
160
+ },
161
+ execute: async (args, context) => {
162
+ try {
163
+ const { filePath } = args;
164
+ const resolvedPath = path.resolve(filePath);
165
+
166
+ if (!fs.existsSync(resolvedPath)) {
167
+ return {
168
+ success: false,
169
+ error: `File not found at path: ${resolvedPath}`
170
+ };
171
+ }
172
+
173
+ const content = await fs.promises.readFile(resolvedPath, 'utf8');
174
+ const lines = content.split('\n');
175
+ const symbols = [];
176
+
177
+ for (let i = 0; i < lines.length; i++) {
178
+ const line = lines[i];
179
+ const trimmed = line.trim();
180
+ const lineNum = i + 1;
181
+
182
+ // Skip comments
183
+ if (trimmed.startsWith('//') || trimmed.startsWith('#') || trimmed.startsWith('/*') || trimmed.startsWith('*')) {
184
+ continue;
185
+ }
186
+
187
+ // JS / TS patterns
188
+ // 1. Functions: function foo( or async function foo( or export function foo(
189
+ const funcMatch = trimmed.match(/^(?:export\s+)?(?:async\s+)?function\s+([a-zA-Z0-9_$]+)\s*\(/);
190
+ if (funcMatch) {
191
+ symbols.push({ type: 'function', name: funcMatch[1], line: lineNum, signature: trimmed });
192
+ continue;
193
+ }
194
+
195
+ // 2. Arrow Functions / Constants: const foo = ( or export const foo = (
196
+ const constFuncMatch = trimmed.match(/^(?:export\s+)?(?:const|let|var)\s+([a-zA-Z0-9_$]+)\s*=\s*(?:async\s*)?(?:\([^)]*\)|[a-zA-Z0-9_$]+)\s*=>/);
197
+ if (constFuncMatch) {
198
+ symbols.push({ type: 'function', name: constFuncMatch[1], line: lineNum, signature: trimmed });
199
+ continue;
200
+ }
201
+
202
+ // 3. Exported Constants/Objects: export const foo =
203
+ const exportConstMatch = trimmed.match(/^export\s+(?:const|let|var)\s+([a-zA-Z0-9_$]+)\s*=/);
204
+ if (exportConstMatch && !constFuncMatch) {
205
+ symbols.push({ type: 'export', name: exportConstMatch[1], line: lineNum, signature: trimmed });
206
+ continue;
207
+ }
208
+
209
+ // 4. Classes: class Foo or export class Foo
210
+ const classMatch = trimmed.match(/^(?:export\s+)?(?:default\s+)?class\s+([a-zA-Z0-9_$]+)/);
211
+ if (classMatch) {
212
+ symbols.push({ type: 'class', name: classMatch[1], line: lineNum, signature: trimmed });
213
+ continue;
214
+ }
215
+
216
+ // 5. Interfaces / Types: interface Foo or type Foo = or export interface Foo
217
+ const interfaceMatch = trimmed.match(/^(?:export\s+)?(?:interface|type)\s+([a-zA-Z0-9_$]+)/);
218
+ if (interfaceMatch) {
219
+ symbols.push({ type: 'interface', name: interfaceMatch[1], line: lineNum, signature: trimmed });
220
+ continue;
221
+ }
222
+
223
+ // Python patterns
224
+ const pyDefMatch = trimmed.match(/^(?:async\s+)?def\s+([a-zA-Z0-9_$]+)\s*\(/);
225
+ if (pyDefMatch) {
226
+ symbols.push({ type: 'function', name: pyDefMatch[1], line: lineNum, signature: trimmed });
227
+ continue;
228
+ }
229
+ const pyClassMatch = trimmed.match(/^class\s+([a-zA-Z0-9_$]+)(?:\(|:)/);
230
+ if (pyClassMatch) {
231
+ symbols.push({ type: 'class', name: pyClassMatch[1], line: lineNum, signature: trimmed });
232
+ continue;
233
+ }
234
+
235
+ // Kotlin / Java patterns
236
+ const ktFunMatch = trimmed.match(/^(?:private|public|protected|internal|override|suspend)?\s*fun\s+([a-zA-Z0-9_$]+)\s*\(/);
237
+ if (ktFunMatch) {
238
+ symbols.push({ type: 'function', name: ktFunMatch[1], line: lineNum, signature: trimmed });
239
+ continue;
240
+ }
241
+ const javaMethodMatch = trimmed.match(/^(?:public|private|protected|static|final|synchronized|abstract)\s+(?:[a-zA-Z0-9_<>[\]]+\s+)+([a-zA-Z0-9_$]+)\s*\([^)]*\)\s*(?:\{|throws)/);
242
+ if (javaMethodMatch && !trimmed.includes('=')) {
243
+ symbols.push({ type: 'function', name: javaMethodMatch[1], line: lineNum, signature: trimmed });
244
+ continue;
245
+ }
246
+ }
247
+
248
+ return {
249
+ success: true,
250
+ filePath: resolvedPath,
251
+ totalLines: lines.length,
252
+ symbolsCount: symbols.length,
253
+ symbols
254
+ };
255
+ } catch (error) {
256
+ return {
257
+ success: false,
258
+ error: `Failed to index symbols: ${error.message}`
259
+ };
260
+ }
261
+ }
262
+ };
@@ -0,0 +1,75 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+
4
+ // Phase 1 AGI Upgrade: Native File Walk (No Bash/Grep)
5
+ async function walkDir(dir, excludes, fileList = []) {
6
+ const files = await fs.readdir(dir, { withFileTypes: true });
7
+ for (const file of files) {
8
+ if (excludes.includes(file.name)) continue;
9
+ const filePath = path.join(dir, file.name);
10
+ if (file.isDirectory()) {
11
+ await walkDir(filePath, excludes, fileList);
12
+ } else {
13
+ fileList.push(filePath);
14
+ }
15
+ }
16
+ return fileList;
17
+ }
18
+
19
+ export const codebaseSearch = {
20
+ schema: {
21
+ name: 'codebase_search',
22
+ description: 'Find snippets of code natively. Understands architecture without shell commands.',
23
+ parameters: {
24
+ type: 'object',
25
+ properties: {
26
+ query: { type: 'string', description: 'The search query to find relevant code.' },
27
+ target_directories: { type: 'array', items: { type: 'string' }, description: 'Directories to search' }
28
+ },
29
+ required: ['query'],
30
+ additionalProperties: false
31
+ }
32
+ },
33
+ async execute(args) {
34
+ try {
35
+ const dirs = args.target_directories && args.target_directories.length > 0
36
+ ? args.target_directories
37
+ : ['.'];
38
+
39
+ const excludes = ['node_modules', '.git', 'build', 'dist', '.gradle'];
40
+ let allFiles = [];
41
+
42
+ for (const dir of dirs) {
43
+ const fullPath = path.resolve(process.cwd(), dir);
44
+ try {
45
+ const files = await walkDir(fullPath, excludes);
46
+ allFiles = allFiles.concat(files);
47
+ } catch(e) {} // Ignore unreadable dirs
48
+ }
49
+
50
+ let results = [];
51
+ const regex = new RegExp(args.query, 'i');
52
+
53
+ for (const file of allFiles) {
54
+ // Skip binary extensions natively
55
+ if (/\.(png|jpe?g|gif|svg|pdf|exe|dll|zip|tar|gz)$/i.test(file)) continue;
56
+
57
+ try {
58
+ const content = await fs.readFile(file, 'utf8');
59
+ const lines = content.split('\n');
60
+ for (let i = 0; i < lines.length; i++) {
61
+ if (regex.test(lines[i])) {
62
+ results.push(`${file}:${i+1}:${lines[i].trim()}`);
63
+ if (results.length >= 50) break; // Token Budget Protection
64
+ }
65
+ }
66
+ } catch(e) {} // Ignore unreadable files
67
+ if (results.length >= 50) break;
68
+ }
69
+
70
+ return { success: true, output: results.length > 0 ? results.join('\n') : 'No results found.' };
71
+ } catch (e) {
72
+ return { success: false, error: e.message };
73
+ }
74
+ }
75
+ };
@@ -0,0 +1,129 @@
1
+ // Let the agent write a skill for the user.
2
+ //
3
+ // The compiled library is one library for everybody. The other half of the same
4
+ // idea is that the agent can WRITE one: a user explains their release process
5
+ // once, and it becomes a procedure the agent follows every time afterwards
6
+ // instead of being re-explained every session. That is the difference between a
7
+ // tool that remembers and a tool that does not.
8
+ //
9
+ // The contract is the one every compiled skill already meets — frontmatter with
10
+ // a routing description, numbered steps each closing with a checkable
11
+ // criterion, and a verification section. It is enforced here rather than
12
+ // suggested, because a skill written to a weaker standard than the library is
13
+ // worse than none: it dilutes the index the agent chooses from.
14
+ //
15
+ // Path safety, size limits and sanitising all live in userSkills.js, and this
16
+ // tool cannot reach the filesystem except through it.
17
+
18
+ import {
19
+ parseSkillId, writeUserSkill, userSkillsRoot, MAX_SKILL_BYTES
20
+ } from '../userSkills.js';
21
+ import { invalidateUserSkills } from '../skillsManager.js';
22
+
23
+ /** Everything the contract requires, reported at once rather than one at a time. */
24
+ function contractProblems(content) {
25
+ const problems = [];
26
+ if (!/^---\n[\s\S]*?\n---/.test(content)) {
27
+ problems.push('missing the `---` frontmatter block at the very top');
28
+ }
29
+ if (!/^description:\s*\S/m.test(content)) {
30
+ problems.push("frontmatter needs a `description:` — it is the ONLY thing the agent reads when deciding whether this skill applies, so write it as \"what this does. Use when …\"");
31
+ }
32
+ if (!/^name:\s*\S/m.test(content)) {
33
+ problems.push('frontmatter needs a `name:`');
34
+ }
35
+ if (!/\*\*Done when:\*\*/.test(content)) {
36
+ problems.push("no step ends with a `**Done when:**` criterion — without one this is a description of a task, not a procedure someone can follow to a known end");
37
+ }
38
+ if (!/##\s+Verification/i.test(content)) {
39
+ problems.push('no `## Verification` section — a skill has to say how to confirm it worked');
40
+ }
41
+ return problems;
42
+ }
43
+
44
+ export const createSkill = {
45
+ schema: {
46
+ name: 'skill_create',
47
+ description:
48
+ "Write a reusable skill into the user's own skill library so it is available in every future session. Use when the user describes a procedure specific to them — their "
49
+ + 'deployment steps, their review checklist, their project conventions — that would '
50
+ + 'otherwise have to be explained again next time. Ask the user before writing one they '
51
+ + 'did not request. The body must follow the skill contract: frontmatter with name and a '
52
+ + '"Use when ..." description, numbered steps each ending with a "**Done when:**" line, '
53
+ + 'and a closing "## Verification" section.',
54
+ parameters: {
55
+ type: 'object',
56
+ properties: {
57
+ skill_id: {
58
+ type: 'string',
59
+ description:
60
+ "Where it lives, as \"domain/name\". Both are lowercase letters, digits and hyphens. Use an existing domain (web, devops, python, testing, security, design, …) when the "
61
+ + 'skill belongs to one, or a new domain of the user\'s own such as "team" or the '
62
+ + 'project name. Example: team/release-checklist'
63
+ },
64
+ content: {
65
+ type: 'string',
66
+ description:
67
+ "The complete SKILL.md, starting with the --- frontmatter block. Write the procedure, not an essay: the steps someone would actually take, in order, each with a "
68
+ + 'checkable "**Done when:**" line, closing with "## Verification".'
69
+ },
70
+ overwrite: {
71
+ type: 'boolean',
72
+ description:
73
+ "Replace an existing skill of the same id. Defaults to false. Only set this when the user has asked for that specific skill to be rewritten."
74
+ }
75
+ },
76
+ required: ['skill_id', 'content']
77
+ }
78
+ },
79
+
80
+ execute: async (args = {}) => {
81
+ const parsed = parseSkillId(args.skill_id);
82
+ if (parsed.error) return { success: false, error: parsed.error };
83
+
84
+ const content = typeof args.content === 'string' ? args.content : '';
85
+ if (!content.trim()) {
86
+ return { success: false, error: 'content is required — write the whole SKILL.md' };
87
+ }
88
+ if (Buffer.byteLength(content, 'utf8') > MAX_SKILL_BYTES) {
89
+ return {
90
+ success: false,
91
+ error: `the skill is larger than the ${MAX_SKILL_BYTES / 1024} KB limit. A skill this long `
92
+ + 'will crowd out the task it is meant to help with — split it, or move the detail into '
93
+ + 'the step that needs it.'
94
+ };
95
+ }
96
+
97
+ const problems = contractProblems(content);
98
+ if (problems.length > 0) {
99
+ return {
100
+ success: false,
101
+ error: 'the skill does not meet the contract:\n'
102
+ + problems.map((problem) => ` - ${problem}`).join('\n')
103
+ + '\n\nRewrite it with those fixed and call skill_create again.'
104
+ };
105
+ }
106
+
107
+ const written = writeUserSkill({
108
+ domain: parsed.domain,
109
+ name: parsed.name,
110
+ content,
111
+ overwrite: args.overwrite === true
112
+ });
113
+ if (!written.ok) return { success: false, error: written.error };
114
+
115
+ // The catalogue is cached; a skill written now must be visible now.
116
+ invalidateUserSkills();
117
+
118
+ return {
119
+ success: true,
120
+ result: `Wrote ${parsed.domain}/${parsed.name} to ${written.path}\n\n`
121
+ + `It is now in the user's library alongside the built-in skills, and it shadows a `
122
+ + `built-in of the same id. They can see it with /skill mine, read it with `
123
+ + `/skills ${parsed.domain}/${parsed.name}, and edit the file directly at `
124
+ + `${userSkillsRoot()}.`
125
+ };
126
+ }
127
+ };
128
+
129
+ export default createSkill;