@hexdecimal16/nexo 0.3.3 → 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
|
@@ -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
|
+
}
|
|
@@ -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
|
}
|
package/core/src/engine/run.js
CHANGED
|
@@ -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 }
|