@hexdecimal16/nexo 0.3.2 → 0.3.4

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.
package/cli/src/main.js CHANGED
@@ -134,6 +134,7 @@ async function runCommand(args, io, options) {
134
134
  model: values.model,
135
135
  effort: values.effort,
136
136
  workspace: values.workspace,
137
+ projectDir: options.cwd ?? process.cwd(),
137
138
  budgetUsd,
138
139
  }, options.signal);
139
140
  }
@@ -66,6 +66,8 @@ export const ConfigSchema = Type.Object({
66
66
  budgets: Type.Object({
67
67
  perRunUsd: Usd,
68
68
  perSessionUsd: Usd,
69
+ /** Share of the session cap one chat turn may spend (0 to 1); CLI runs, scoring and optimization use perRunUsd. */
70
+ perTurnShare: Type.Number({ exclusiveMinimum: 0, maximum: 1 }),
69
71
  dailyUsd: Usd,
70
72
  monthlyUsd: Usd,
71
73
  optimDefaultUsd: Usd,
@@ -163,6 +165,7 @@ export const DEFAULT_CONFIG = {
163
165
  budgets: {
164
166
  perRunUsd: 0.5,
165
167
  perSessionUsd: 5,
168
+ perTurnShare: 0.2,
166
169
  dailyUsd: 10,
167
170
  monthlyUsd: 150,
168
171
  optimDefaultUsd: 5,
@@ -60,8 +60,9 @@ export function runBudgetLimit(db, budgets, now, limits) {
60
60
  { usd: budgets.monthlyUsd - getSpent(db, monthScope(now)), by: "monthly" },
61
61
  ];
62
62
  let best = candidates[0];
63
+ // Ties go to the later (outer) limit: it is the one the user has to raise.
63
64
  for (const c of candidates)
64
- if (c.usd < best.usd)
65
+ if (c.usd <= best.usd)
65
66
  best = c;
66
67
  return { usd: Math.max(0, best.usd), by: best.by };
67
68
  }
@@ -75,7 +76,7 @@ export function budgetExhaustedError(budget, by, chat) {
75
76
  const capped = by === "run" ? "" : `; ${CAPPED_BY[by]}`;
76
77
  const hint = {
77
78
  run: chat
78
- ? "Each chat turn is capped by budgets.perRunUsd; raise it in /settings (/budget raises the session's cap, not a turn's)"
79
+ ? "Each chat turn is capped at budgets.perTurnShare of the session budget; raise the share in /settings or the session cap with /budget"
79
80
  : "Pass --budget or raise budgets.perRunUsd",
80
81
  session: "Raise the session's budget with /budget <usd>, then continue",
81
82
  daily: "Raise budgets.dailyUsd or wait until tomorrow (UTC)",
@@ -0,0 +1,47 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { release, type } from "node:os";
3
+ function git(cwd, args) {
4
+ try {
5
+ return execFileSync("git", args, { cwd, encoding: "utf8", timeout: 2000, stdio: ["ignore", "pipe", "ignore"] }).trim();
6
+ }
7
+ catch {
8
+ return null;
9
+ }
10
+ }
11
+ /** The current branch, or `detached at <sha>` on a detached HEAD; null outside a git repo. */
12
+ export function gitBranch(cwd) {
13
+ if (git(cwd, ["rev-parse", "--is-inside-work-tree"]) !== "true")
14
+ return null;
15
+ const branch = git(cwd, ["branch", "--show-current"]);
16
+ if (branch)
17
+ return branch;
18
+ const sha = git(cwd, ["rev-parse", "--short", "HEAD"]);
19
+ return sha ? `detached at ${sha}` : "unknown";
20
+ }
21
+ /** Local time as `YYYY-MM-DD HH:mm <zone> (UTC±hh:mm)`. */
22
+ export function localTime(now) {
23
+ const pad = (n) => String(Math.abs(n)).padStart(2, "0");
24
+ const offset = -now.getTimezoneOffset();
25
+ const sign = offset >= 0 ? "+" : "-";
26
+ const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
27
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())} ${zone} (UTC${sign}${pad(Math.trunc(offset / 60))}:${pad(offset % 60)})`;
28
+ }
29
+ /** The prompt's environment section: where nexo was launched, git state, platform, shell and the current local time. */
30
+ export function environmentBlock(input) {
31
+ const lines = ["Environment:"];
32
+ if (input.projectDir) {
33
+ const branch = gitBranch(input.projectDir);
34
+ lines.push(`- Launch directory: ${input.projectDir}`);
35
+ lines.push(`- Git repository: ${branch !== null}`);
36
+ if (branch !== null)
37
+ lines.push(`- Git branch: ${branch}`);
38
+ lines.push(input.workspaceShared
39
+ ? "- The workspace is a shared directory that runs edit in place."
40
+ : "- The user's project files live in the launch directory. The workspace is a scratch copy for files you create; edit project files by absolute path in the launch directory.");
41
+ }
42
+ lines.push(`- Platform: ${process.platform} (${type()} ${release()})`);
43
+ if (input.shell)
44
+ lines.push(`- Shell: ${input.shell}`);
45
+ lines.push(`- Current local time: ${localTime(input.now)}`);
46
+ return lines.join("\n");
47
+ }
@@ -6,7 +6,7 @@ Working rules:
6
6
  - Before following a skill, call load_skill with its name and follow its instructions.
7
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
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.
9
+ - A budget line is appended to your latest input each turn. Prefer fewer, larger steps when it is low. Never say you hit or ran out of budget unless the budget line shows $0.0000 remaining or a tool result says BUDGET_EXCEEDED; otherwise finish the task.
10
10
  - End with a concise final answer that states what you did and where any output files are.`;
11
11
  export const DEFAULT_PLANNER_PROMPT = `Parallel work:
12
12
  - When the instruction has independent parts, call spawn once with all independent tasks so they run in parallel.
@@ -30,5 +30,8 @@ export function renderSystemPrompt(parts) {
30
30
  sections.push(parts.projectInstructions);
31
31
  if (parts.memories)
32
32
  sections.push(parts.memories);
33
+ // Last: it holds the current time, which changes every run and would otherwise break prefix caching for what follows.
34
+ if (parts.environment)
35
+ sections.push(parts.environment);
33
36
  return sections.join("\n\n");
34
37
  }
@@ -16,6 +16,7 @@ import { assistantText, contentText, estimatePromptChars, foreignToolCallsAsText
16
16
  import { DEFAULT_PLANNER_PROMPT, DEFAULT_SYSTEM_PROMPT, renderSystemPrompt } from "./prompts.js";
17
17
  import { loadProjectInstructions } from "../session/project-instructions.js";
18
18
  import { projectScope } from "../session/project-root.js";
19
+ import { environmentBlock } from "./environment.js";
19
20
  import { createGatedStreamFn } from "./provider-gate.js";
20
21
  import { Recorder } from "./recorder.js";
21
22
  import { activePlaybook, emptyMemoryContext, playbookSection, retrieveRunMemories, skillAppendix } from "../learn/context.js";
@@ -616,6 +617,7 @@ export async function executeRun(env, input) {
616
617
  workspace,
617
618
  ...(rollout ? {} : { wikisDir: deps.paths.wikis }),
618
619
  skillIndex: formatSkillIndex(deps.skills),
620
+ ...(rollout ? {} : { environment: environmentBlock({ ...(request.projectDir ? { projectDir: request.projectDir } : {}), now: new Date(), workspaceShared: sharedWorkspace !== null, ...(process.env.SHELL ? { shell: process.env.SHELL } : {}) }) }),
619
621
  ...(request.projectDir && !rollout ? { projectInstructions: loadProjectInstructions(request.projectDir, config.instructions).block } : {}),
620
622
  activeSkill: runSkill
621
623
  ? { name: runSkill.name, body: startPlaybookSection ? `${runSkill.body}\n\n${startPlaybookSection}` : runSkill.body }
@@ -283,7 +283,7 @@ export class Session {
283
283
  catch (error) {
284
284
  return refusedResult(this.env.deps.redact(toErrorPayload(error)));
285
285
  }
286
- const limit = runBudgetLimit(this.deps.db, config.budgets, this.env.now(), { run: config.budgets.perRunUsd, session: remaining });
286
+ const limit = runBudgetLimit(this.deps.db, config.budgets, this.env.now(), { run: config.budgets.perTurnShare * this.budgetUsd, session: remaining });
287
287
  const turnIndex = this.state.turns + 1;
288
288
  this.onEvent = options.onEvent;
289
289
  const sent = withShellNotes(this.state.pendingShell ?? [], instruction);
@@ -26,6 +26,12 @@ export const EDITABLE_SETTINGS = [
26
26
  { key: "models.s2.effort", label: "Effort s2", description: "Default reasoning effort for s2", type: { kind: "enum", values: EFFORTS } },
27
27
  { key: "budgets.perRunUsd", label: "Budget per run", description: "Spending cap for one run or turn, in USD", type: USD },
28
28
  { key: "budgets.perSessionUsd", label: "Budget per session", description: "Spending cap for one interactive session, in USD", type: USD },
29
+ {
30
+ key: "budgets.perTurnShare",
31
+ label: "Turn share of session",
32
+ description: "Share of the session budget one chat turn may spend (0 to 1); budgets.perRunUsd still caps CLI runs",
33
+ type: { kind: "number", integer: false, exclusiveMin: 0, max: 1 },
34
+ },
29
35
  { key: "budgets.dailyUsd", label: "Daily budget", description: "Spending cap per UTC day, in USD", type: USD },
30
36
  { key: "budgets.monthlyUsd", label: "Monthly budget", description: "Spending cap per UTC month, in USD", type: USD },
31
37
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexdecimal16/nexo",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "nexo agent engine",
5
5
  "license": "PolyForm-Noncommercial-1.0.0",
6
6
  "repository": {