@hexdecimal16/nexo 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/LICENSE +75 -0
  2. package/README.md +75 -2
  3. package/cli/src/bin.js +12 -0
  4. package/cli/src/common.js +77 -0
  5. package/cli/src/doctor.js +27 -0
  6. package/cli/src/eval-cases.js +65 -0
  7. package/cli/src/eval.js +67 -0
  8. package/cli/src/init.js +186 -0
  9. package/cli/src/interactive.js +171 -0
  10. package/cli/src/learn.js +178 -0
  11. package/cli/src/main.js +261 -0
  12. package/cli/src/optimize.js +289 -0
  13. package/cli/src/prompter.js +47 -0
  14. package/cli/src/review.js +120 -0
  15. package/cli/src/runtime.js +2 -0
  16. package/cli/src/sessions.js +34 -0
  17. package/cli/src/settings.js +169 -0
  18. package/cli/src/ui.js +112 -0
  19. package/core/src/approval/classifier.js +152 -0
  20. package/core/src/config/load.js +283 -0
  21. package/core/src/config/schema.js +186 -0
  22. package/core/src/cost/admission.js +90 -0
  23. package/core/src/cost/budget.js +67 -0
  24. package/core/src/cost/pricing.js +53 -0
  25. package/core/src/engine/charged-completion.js +79 -0
  26. package/core/src/engine/errors.js +77 -0
  27. package/core/src/engine/mcp.js +11 -0
  28. package/core/src/engine/messages.js +86 -0
  29. package/core/src/engine/prompts.js +32 -0
  30. package/core/src/engine/provider-gate.js +33 -0
  31. package/core/src/engine/recorder.js +61 -0
  32. package/core/src/engine/run.js +1115 -0
  33. package/core/src/engine/semaphore.js +45 -0
  34. package/core/src/engine/spawn-tool.js +119 -0
  35. package/core/src/engine/task-graph.js +153 -0
  36. package/core/src/index.js +32 -0
  37. package/core/src/learn/caller.js +171 -0
  38. package/core/src/learn/context.js +112 -0
  39. package/core/src/learn/embedder.js +216 -0
  40. package/core/src/learn/job.js +196 -0
  41. package/core/src/learn/wiki.js +116 -0
  42. package/core/src/learn/worker.js +141 -0
  43. package/core/src/optimize/adapter.js +250 -0
  44. package/core/src/optimize/climb.js +338 -0
  45. package/core/src/optimize/mine.js +95 -0
  46. package/core/src/optimize/optimize.js +377 -0
  47. package/core/src/optimize/optimizer-run.js +67 -0
  48. package/core/src/optimize/reflect.js +100 -0
  49. package/core/src/optimize/scratchpad-wiki.js +69 -0
  50. package/core/src/providers/claude-p.js +363 -0
  51. package/core/src/providers/kiro-p.js +408 -0
  52. package/core/src/providers/models.js +10 -0
  53. package/core/src/scoring/calibration.js +31 -0
  54. package/core/src/scoring/continuation.js +24 -0
  55. package/core/src/scoring/runner.js +322 -0
  56. package/core/src/scoring/sources.js +88 -0
  57. package/core/src/session/lock.js +88 -0
  58. package/core/src/session/session.js +647 -0
  59. package/core/src/session/shell.js +26 -0
  60. package/core/src/session/transcript.js +86 -0
  61. package/core/src/settings/config-edit.js +472 -0
  62. package/core/src/settings/credentials.js +120 -0
  63. package/core/src/settings/doctor.js +103 -0
  64. package/core/src/settings/settings.js +265 -0
  65. package/mcp/src/hub.js +184 -0
  66. package/mcp/src/index.js +1 -0
  67. package/memory/src/curate.js +121 -0
  68. package/memory/src/index.js +4 -0
  69. package/memory/src/prompts.js +143 -0
  70. package/memory/src/retrieval.js +91 -0
  71. package/memory/src/similarity.js +47 -0
  72. package/optimize/src/engine.js +206 -0
  73. package/optimize/src/index.js +8 -0
  74. package/optimize/src/merge.js +73 -0
  75. package/optimize/src/novelty.js +37 -0
  76. package/optimize/src/pareto.js +83 -0
  77. package/optimize/src/proposer.js +148 -0
  78. package/optimize/src/report.js +107 -0
  79. package/optimize/src/rng.js +34 -0
  80. package/optimize/src/target.js +34 -0
  81. package/package.json +47 -4
  82. package/router/src/effort.js +5 -0
  83. package/router/src/escalation.js +171 -0
  84. package/router/src/index.js +4 -0
  85. package/router/src/registry.js +21 -0
  86. package/router/src/resolve.js +117 -0
  87. package/scorers/src/deterministic.js +194 -0
  88. package/scorers/src/family.js +48 -0
  89. package/scorers/src/index.js +6 -0
  90. package/scorers/src/judge.js +284 -0
  91. package/scorers/src/regex-worker.js +3 -0
  92. package/scorers/src/spec.js +147 -0
  93. package/scorers/src/trajectory.js +22 -0
  94. package/scorers/src/types.js +1 -0
  95. package/sdk/src/index.js +3 -0
  96. package/sdk/src/nexo.js +94 -0
  97. package/sdk/src/runtime.js +39 -0
  98. package/skills/bundled/browser/SKILL.md +57 -0
  99. package/skills/bundled/wiki/SKILL.md +73 -0
  100. package/skills/src/frontmatter.js +25 -0
  101. package/skills/src/index.js +3 -0
  102. package/skills/src/load-skill-tool.js +41 -0
  103. package/skills/src/loader.js +95 -0
  104. package/store/src/artifacts.js +124 -0
  105. package/store/src/budget-ledger.js +18 -0
  106. package/store/src/cost-report.js +46 -0
  107. package/store/src/cursor.js +35 -0
  108. package/store/src/db.js +83 -0
  109. package/store/src/errors.js +9 -0
  110. package/store/src/eval-cases.js +255 -0
  111. package/store/src/feedback.js +154 -0
  112. package/store/src/goldens.js +61 -0
  113. package/store/src/ids.js +6 -0
  114. package/store/src/index.js +25 -0
  115. package/store/src/judge-calibration.js +182 -0
  116. package/store/src/learn-jobs.js +145 -0
  117. package/store/src/memories.js +261 -0
  118. package/store/src/migrations/001_init.sql +81 -0
  119. package/store/src/migrations/002_feedback.sql +9 -0
  120. package/store/src/migrations/003_sessions.sql +19 -0
  121. package/store/src/migrations/004_scoring.sql +22 -0
  122. package/store/src/migrations/005_judge_calibration.sql +27 -0
  123. package/store/src/migrations/006_learning.sql +77 -0
  124. package/store/src/migrations/007_optimize.sql +55 -0
  125. package/store/src/migrations/008_mined_cases_and_climb.sql +46 -0
  126. package/store/src/mine.js +51 -0
  127. package/store/src/optim.js +291 -0
  128. package/store/src/paths.js +22 -0
  129. package/store/src/playbooks.js +199 -0
  130. package/store/src/reindex.js +143 -0
  131. package/store/src/run-dir.js +151 -0
  132. package/store/src/runs.js +310 -0
  133. package/store/src/scores.js +92 -0
  134. package/store/src/sessions.js +304 -0
  135. package/store/src/span-tree.js +98 -0
  136. package/store/src/spans.js +84 -0
  137. package/store/src/sql.js +13 -0
  138. package/store/src/workspace-copy.js +80 -0
  139. package/telemetry/src/errors.js +32 -0
  140. package/telemetry/src/index.js +3 -0
  141. package/telemetry/src/logger.js +39 -0
  142. package/telemetry/src/redact.js +106 -0
  143. package/tools/src/builtin.js +269 -0
  144. package/tools/src/change-tracker.js +57 -0
  145. package/tools/src/confine.js +101 -0
  146. package/tools/src/index.js +7 -0
  147. package/tools/src/leases.js +57 -0
  148. package/tools/src/policy.js +162 -0
  149. package/tools/src/read-only.js +338 -0
  150. package/tools/src/session-rules.js +140 -0
  151. package/tui/src/app.js +948 -0
  152. package/tui/src/approvals.js +96 -0
  153. package/tui/src/commands.js +38 -0
  154. package/tui/src/components.js +248 -0
  155. package/tui/src/index.js +5 -0
  156. package/tui/src/picker.js +78 -0
  157. package/tui/src/session-picker.js +100 -0
  158. package/tui/src/settings-screen.js +346 -0
  159. package/tui/src/text.js +70 -0
  160. package/tui/src/theme.js +44 -0
  161. package/web/public/cost.html +25 -0
  162. package/web/public/fonts/GeistMono-400.woff2 +0 -0
  163. package/web/public/fonts/GeistMono-600.woff2 +0 -0
  164. package/web/public/fonts/InstrumentSans-400.woff2 +0 -0
  165. package/web/public/fonts/InstrumentSans-600.woff2 +0 -0
  166. package/web/public/index.html +39 -0
  167. package/web/public/judge.html +21 -0
  168. package/web/public/learning.html +46 -0
  169. package/web/public/lib/api-types.ts +616 -0
  170. package/web/public/lib/common-view.ts +47 -0
  171. package/web/public/lib/cost-view.ts +35 -0
  172. package/web/public/lib/files-view.ts +90 -0
  173. package/web/public/lib/format.ts +35 -0
  174. package/web/public/lib/html.ts +51 -0
  175. package/web/public/lib/judge-view.ts +62 -0
  176. package/web/public/lib/learning-view.ts +102 -0
  177. package/web/public/lib/optim-view.ts +148 -0
  178. package/web/public/lib/pager.ts +56 -0
  179. package/web/public/lib/poller.ts +79 -0
  180. package/web/public/lib/run-view.ts +61 -0
  181. package/web/public/lib/runs-view.ts +87 -0
  182. package/web/public/lib/score-view.ts +94 -0
  183. package/web/public/lib/sessions-view.ts +28 -0
  184. package/web/public/lib/span-view.ts +90 -0
  185. package/web/public/lib/theme.ts +60 -0
  186. package/web/public/lib/timeline.ts +97 -0
  187. package/web/public/lib/wikis-view.ts +257 -0
  188. package/web/public/optim.html +30 -0
  189. package/web/public/pages/api.ts +60 -0
  190. package/web/public/pages/cost.ts +36 -0
  191. package/web/public/pages/judge.ts +15 -0
  192. package/web/public/pages/learning.ts +92 -0
  193. package/web/public/pages/optim.ts +68 -0
  194. package/web/public/pages/paging.ts +18 -0
  195. package/web/public/pages/run.ts +221 -0
  196. package/web/public/pages/runs.ts +91 -0
  197. package/web/public/pages/sessions.ts +25 -0
  198. package/web/public/pages/wikis.ts +103 -0
  199. package/web/public/run.html +36 -0
  200. package/web/public/sessions.html +28 -0
  201. package/web/public/style.css +288 -0
  202. package/web/public/wikis.html +25 -0
  203. package/web/src/api.js +682 -0
  204. package/web/src/http-errors.js +60 -0
  205. package/web/src/index.js +5 -0
  206. package/web/src/server.js +292 -0
  207. package/web/src/static.js +86 -0
  208. package/web/src/strip.js +22 -0
@@ -0,0 +1,32 @@
1
+ export const DEFAULT_SYSTEM_PROMPT = `You are nexo, a general-purpose agent that completes the user's instruction using tools and skills.
2
+
3
+ Working rules:
4
+ - Your workspace directory is {{workspace}}. Use paths relative to it, and save files you create there unless the user names another location.
5
+ - A skill's scripts and project files may live elsewhere: run them by absolute path from the workspace instead of changing into their folder, and point their output into the workspace.
6
+ - Before following a skill, call load_skill with its name and follow its instructions.
7
+ - Make independent tool calls in the same turn, and combine related shell steps into one command. To read several files, pass paths to one read call.
8
+ - Scope searches to a directory, never find /. Start a command that may outlive the bash timeout in the background (nohup ... > job.log 2>&1 &) and poll the log.
9
+ - A budget line is appended to your latest input each turn. Finish within the budget; prefer fewer, larger steps when it is low.
10
+ - End with a concise final answer that states what you did and where any output files are.`;
11
+ export const DEFAULT_PLANNER_PROMPT = `Parallel work:
12
+ - When the instruction has independent parts, call spawn once with all independent tasks so they run in parallel.
13
+ - Use dependsOn only when a task needs another task's output; dependency outputs are appended to the dependent task's instruction.
14
+ - Choose model "s1" and low effort for simple tasks; use "s2" or higher effort only for hard reasoning. Give each task a clear, self-contained instruction.`;
15
+ /** The line that points the agent at the wikis directory; the wiki skill holds the rules for using it. */
16
+ export function wikiPrompt(wikisDir) {
17
+ return `Wikis: the user keeps persistent knowledge bases as markdown folders under ${wikisDir}. When a task produces durable subject knowledge worth keeping (research findings, a source you read, a topic the user keeps returning to), load the wiki skill with load_skill and file it in the wiki that fits, creating a new wiki when none fits. Do not create or edit wikis for one-off questions, small talk or routine code changes. Load the wiki skill first whenever the task is about a wiki.`;
18
+ }
19
+ export function renderSystemPrompt(parts) {
20
+ const sections = [parts.systemPrompt.replaceAll("{{workspace}}", parts.workspace)];
21
+ if (parts.plannerPrompt)
22
+ sections.push(parts.plannerPrompt);
23
+ if (parts.wikisDir)
24
+ sections.push(wikiPrompt(parts.wikisDir));
25
+ if (parts.skillIndex)
26
+ sections.push(parts.skillIndex);
27
+ if (parts.activeSkill)
28
+ sections.push(`# Active skill: ${parts.activeSkill.name}\n${parts.activeSkill.body}`);
29
+ if (parts.memories)
30
+ sections.push(parts.memories);
31
+ return sections.join("\n\n");
32
+ }
@@ -0,0 +1,33 @@
1
+ import { Semaphore } from "./semaphore.js";
2
+ /**
3
+ * Wraps Models.streamSimple so each provider never exceeds its configured number of concurrent requests. When the
4
+ * request carries no `apiKey`, the key from `resolveApiKey` is passed as the request's `apiKey` option.
5
+ */
6
+ export function createGatedStreamFn(models, limits, resolveApiKey) {
7
+ const semaphores = new Map();
8
+ const semaphoreFor = (provider) => {
9
+ const limit = limits[provider];
10
+ if (limit === undefined)
11
+ return undefined;
12
+ let sem = semaphores.get(provider);
13
+ if (!sem) {
14
+ sem = new Semaphore(limit);
15
+ semaphores.set(provider, sem);
16
+ }
17
+ return sem;
18
+ };
19
+ return async (model, context, options) => {
20
+ const sem = semaphoreFor(model.provider);
21
+ const release = sem ? await sem.acquire(options?.signal) : () => { };
22
+ try {
23
+ const apiKey = options?.apiKey ?? resolveApiKey?.(model.provider);
24
+ const stream = models.streamSimple(model, context, apiKey === undefined ? options : { ...options, apiKey });
25
+ stream.result().then(release, release);
26
+ return stream;
27
+ }
28
+ catch (error) {
29
+ release();
30
+ throw error;
31
+ }
32
+ };
33
+ }
@@ -0,0 +1,61 @@
1
+ import { insertSpan, newId, updateSpan } from "../../../store/src/index.js";
2
+ /**
3
+ * Writes each span to SQLite (redacted) and appends a full snapshot to trajectory.jsonl (redacted by RunDir) on start
4
+ * and on finish. The in-memory copy keeps the raw values so later `finish` merges see the original attrs.
5
+ */
6
+ export class Recorder {
7
+ deps;
8
+ spans = new Map();
9
+ constructor(deps) {
10
+ this.deps = deps;
11
+ }
12
+ start(input) {
13
+ const span = {
14
+ id: newId(),
15
+ runId: this.deps.runId,
16
+ parentSpanId: input.parentSpanId,
17
+ kind: input.kind,
18
+ name: input.name,
19
+ status: "running",
20
+ startedAt: this.deps.now().toISOString(),
21
+ endedAt: null,
22
+ queuedMs: input.queuedMs ?? null,
23
+ model: input.model ?? null,
24
+ provider: input.provider ?? null,
25
+ tier: input.tier ?? null,
26
+ effort: input.effort ?? null,
27
+ modelSource: input.modelSource ?? null,
28
+ tokensIn: 0,
29
+ tokensOut: 0,
30
+ cacheRead: 0,
31
+ cacheWrite: 0,
32
+ costUsd: 0,
33
+ costUnknown: false,
34
+ payloadRef: null,
35
+ attrs: input.attrs ?? {},
36
+ };
37
+ this.spans.set(span.id, span);
38
+ insertSpan(this.deps.db, this.deps.redact(span));
39
+ this.deps.runDir.appendTrajectory(span);
40
+ return span.id;
41
+ }
42
+ finish(id, patch) {
43
+ const current = this.spans.get(id);
44
+ if (!current)
45
+ return;
46
+ const { attrs, ...rest } = patch;
47
+ const next = {
48
+ ...current,
49
+ ...rest,
50
+ status: patch.status ?? "ok",
51
+ endedAt: this.deps.now().toISOString(),
52
+ attrs: { ...current.attrs, ...attrs },
53
+ };
54
+ this.spans.set(id, next);
55
+ updateSpan(this.deps.db, id, this.deps.redact(next));
56
+ this.deps.runDir.appendTrajectory(next);
57
+ }
58
+ get(id) {
59
+ return this.spans.get(id);
60
+ }
61
+ }