@tradejs/cli 3.0.1 → 3.1.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.
- package/dist/cli.js +2593 -2167
- package/dist/lib/aiPocketSearch.js +10 -0
- package/dist/lib/aiTrainResearch.js +24 -15
- package/dist/lib/researchAgent.js +16 -2
- package/dist/lib/runtimeLineage.js +24 -15
- package/dist/lib/strategyGateFingerprint.js +26 -15
- package/dist/lib/strategyRelease.js +266 -253
- package/dist/scripts/agentRun.js +50 -45
- package/dist/scripts/aiPocketSearch.js +2269 -1972
- package/dist/scripts/aiTrain.js +24 -15
- package/dist/scripts/replay.js +24 -15
- package/dist/scripts/replayRunner.js +24 -15
- package/dist/scripts/researchAuto.js +2 -2
- package/dist/scripts/runtimeEvidence.js +1 -0
- package/dist/scripts/runtimeScorecard.js +108 -103
- package/dist/scripts/signals.js +24 -15
- package/dist/scripts/signalsDaemon.js +24 -15
- package/dist/scripts/strategyRelease.js +222 -209
- package/dist/scripts/test-ml.js +8 -2
- package/package.json +8 -9
package/dist/scripts/agentRun.js
CHANGED
|
@@ -117,6 +117,7 @@ ${chunk}`, {
|
|
|
117
117
|
var RESEARCH_AGENT_MODEL = "openai/gpt-5.4";
|
|
118
118
|
var RESEARCH_AGENT_REASONING_EFFORT = "medium";
|
|
119
119
|
var RESEARCH_AGENT_BRANCH_PREFIX = "codex/research";
|
|
120
|
+
var RESEARCH_AGENT_DEFAULT_GITHUB_ORGANIZATION = "TradeJS-Dev";
|
|
120
121
|
var buildResearchAgentBranchName = (strategy, runId) => {
|
|
121
122
|
const normalizedStrategy = strategy.trim().replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[^a-zA-Z0-9-]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase();
|
|
122
123
|
const normalizedRunId = runId.trim().replace(/[^a-zA-Z0-9-]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase();
|
|
@@ -124,8 +125,15 @@ var buildResearchAgentBranchName = (strategy, runId) => {
|
|
|
124
125
|
};
|
|
125
126
|
var buildResearchAgentCommitMessage = (strategy, runId) => `Research agent: ${strategy} follow-up for ${runId}`;
|
|
126
127
|
var buildResearchAgentPrTitle = (strategy, runId) => `Research agent: ${strategy} follow-up for ${runId}`;
|
|
128
|
+
var getResearchAgentRepositoryName = (strategy) => {
|
|
129
|
+
if (strategy === "TrendLine" || strategy === "ReverseTrendLine") {
|
|
130
|
+
return "TradeJS-Strategy-TrendLine";
|
|
131
|
+
}
|
|
132
|
+
return `TradeJS-Strategy-${strategy}`;
|
|
133
|
+
};
|
|
134
|
+
var getResearchAgentRepository = (strategy, organization = RESEARCH_AGENT_DEFAULT_GITHUB_ORGANIZATION) => `${organization}/${getResearchAgentRepositoryName(strategy)}`;
|
|
127
135
|
var getResearchAgentAllowedPathPrefixes = (strategy) => [
|
|
128
|
-
`
|
|
136
|
+
`src/${strategy}/`
|
|
129
137
|
];
|
|
130
138
|
var parseGithubRepositoryFromRemote = (value) => {
|
|
131
139
|
const trimmed = value.trim();
|
|
@@ -179,7 +187,7 @@ var buildResearchAgentPrBody = (params) => {
|
|
|
179
187
|
lines.push("");
|
|
180
188
|
lines.push("## Notes");
|
|
181
189
|
lines.push("- Created automatically by the TradeJS research agent.");
|
|
182
|
-
lines.push("- Base branch: `
|
|
190
|
+
lines.push("- Base branch: `main`.");
|
|
183
191
|
return lines.join("\n");
|
|
184
192
|
};
|
|
185
193
|
var normalizeDiffOutput = (value) => {
|
|
@@ -235,7 +243,7 @@ ${diffText}`)) {
|
|
|
235
243
|
// src/scripts/agentRun.ts
|
|
236
244
|
import_args.default.example(
|
|
237
245
|
"yarn cli:node8g agent-run --runId 1710000000000-trendline --strategy TrendLine",
|
|
238
|
-
"Run the OpenRouter-based research follow-up coding agent in a
|
|
246
|
+
"Run the OpenRouter-based research follow-up coding agent in a strategy repository"
|
|
239
247
|
);
|
|
240
248
|
import_args.default.option(["U", "user"], "Use user config", "root");
|
|
241
249
|
import_args.default.option(["r", "runId"], "Research run id");
|
|
@@ -243,7 +251,7 @@ import_args.default.option(["s", "strategy"], "Strategy name");
|
|
|
243
251
|
import_args.default.option("json", "Print structured JSON summary", false);
|
|
244
252
|
var flags = import_args.default.parse(process.argv);
|
|
245
253
|
var projectRoot = String(process.env.PROJECT_CWD || process.cwd()).trim() || process.cwd();
|
|
246
|
-
var AGENT_SYSTEM_PROMPT = `You are a senior TypeScript trading research coding agent working inside
|
|
254
|
+
var AGENT_SYSTEM_PROMPT = `You are a senior TypeScript trading research coding agent working inside a standalone TradeJS strategy repository.
|
|
247
255
|
|
|
248
256
|
Output ONLY one of:
|
|
249
257
|
1. A unified git diff relative to repo root that can be applied with git apply.
|
|
@@ -333,13 +341,7 @@ var listFilesRecursive = async (targetPath) => {
|
|
|
333
341
|
}
|
|
334
342
|
};
|
|
335
343
|
var collectStrategyContextFiles = async (worktreePath, strategy) => {
|
|
336
|
-
const strategyRoot = import_node_path.default.join(
|
|
337
|
-
worktreePath,
|
|
338
|
-
"packages",
|
|
339
|
-
"strategies",
|
|
340
|
-
"src",
|
|
341
|
-
strategy
|
|
342
|
-
);
|
|
344
|
+
const strategyRoot = import_node_path.default.join(worktreePath, "src", strategy);
|
|
343
345
|
const strategyFiles = await listFilesRecursive(strategyRoot);
|
|
344
346
|
const files = strategyFiles.filter(
|
|
345
347
|
(filePath) => /\.(ts|tsx|md)$/.test(filePath)
|
|
@@ -489,14 +491,10 @@ var getChangedFilesFromGit = async (worktreePath) => {
|
|
|
489
491
|
};
|
|
490
492
|
var runValidationSuite = async (worktreePath, agentRun) => {
|
|
491
493
|
const commands = [
|
|
492
|
-
["
|
|
493
|
-
["typecheck", ["yarn", "typecheck"]],
|
|
494
|
-
["unit", ["yarn", "unit"]]
|
|
494
|
+
["checks", ["yarn", "checks"]]
|
|
495
495
|
];
|
|
496
496
|
agentRun.validation = {
|
|
497
|
-
|
|
498
|
-
typecheck: "pending",
|
|
499
|
-
unit: "pending"
|
|
497
|
+
checks: "pending"
|
|
500
498
|
};
|
|
501
499
|
for (const [key, command] of commands) {
|
|
502
500
|
const result = await runCommand(command[0], command.slice(1), {
|
|
@@ -605,9 +603,6 @@ var saveAgentRun = async (userName, runId, strategy, agentRun) => {
|
|
|
605
603
|
});
|
|
606
604
|
};
|
|
607
605
|
var resolveGithubRepository = async (worktreePath) => {
|
|
608
|
-
if (process.env.AGENT_GITHUB_REPOSITORY?.trim()) {
|
|
609
|
-
return process.env.AGENT_GITHUB_REPOSITORY.trim();
|
|
610
|
-
}
|
|
611
606
|
const remote = await runCommandOrThrow(
|
|
612
607
|
"git",
|
|
613
608
|
["-C", worktreePath, "remote", "get-url", "origin"],
|
|
@@ -629,7 +624,7 @@ var createGithubPullRequest = async (params) => {
|
|
|
629
624
|
if (!owner || !repo) {
|
|
630
625
|
throw new Error(`Invalid GitHub repository value: ${repository}`);
|
|
631
626
|
}
|
|
632
|
-
const baseBranch = process.env.AGENT_GITHUB_BASE_BRANCH?.trim() || "
|
|
627
|
+
const baseBranch = process.env.AGENT_GITHUB_BASE_BRANCH?.trim() || "main";
|
|
633
628
|
const head = `${owner}:${params.branchName}`;
|
|
634
629
|
const headers = {
|
|
635
630
|
Authorization: `Bearer ${token}`,
|
|
@@ -683,31 +678,34 @@ var createGithubPullRequest = async (params) => {
|
|
|
683
678
|
reused: false
|
|
684
679
|
};
|
|
685
680
|
};
|
|
686
|
-
var
|
|
687
|
-
const
|
|
688
|
-
const
|
|
689
|
-
const
|
|
690
|
-
await import_promises.default.
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
await runCommandOrThrow("git", ["fetch", "origin", "stable"], {
|
|
695
|
-
cwd: projectRoot
|
|
696
|
-
});
|
|
681
|
+
var createStrategyCheckout = async (strategy, branchName) => {
|
|
682
|
+
const organization = process.env.AGENT_GITHUB_ORGANIZATION?.trim() || "TradeJS-Dev";
|
|
683
|
+
const repository = getResearchAgentRepository(strategy, organization);
|
|
684
|
+
const baseBranch = process.env.AGENT_GITHUB_BASE_BRANCH?.trim() || "main";
|
|
685
|
+
const checkoutRoot = await import_promises.default.mkdtemp(
|
|
686
|
+
import_node_path.default.join(import_node_os.default.tmpdir(), "tradejs-strategy-agent-")
|
|
687
|
+
);
|
|
688
|
+
const checkoutPath = import_node_path.default.join(checkoutRoot, "repository");
|
|
697
689
|
await runCommandOrThrow(
|
|
698
690
|
"git",
|
|
699
|
-
[
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
691
|
+
[
|
|
692
|
+
"clone",
|
|
693
|
+
"--branch",
|
|
694
|
+
baseBranch,
|
|
695
|
+
"--single-branch",
|
|
696
|
+
`git@github.com:${repository}.git`,
|
|
697
|
+
checkoutPath
|
|
698
|
+
],
|
|
699
|
+
{ cwd: checkoutRoot }
|
|
703
700
|
);
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
701
|
+
await runCommandOrThrow(
|
|
702
|
+
"git",
|
|
703
|
+
["-C", checkoutPath, "switch", "-c", branchName],
|
|
704
|
+
{ cwd: checkoutPath }
|
|
705
|
+
);
|
|
706
|
+
return { checkoutPath, checkoutRoot, repository };
|
|
710
707
|
};
|
|
708
|
+
var cleanupStrategyCheckout = async (checkoutRoot) => import_promises.default.rm(checkoutRoot, { recursive: true, force: true });
|
|
711
709
|
var main = async () => {
|
|
712
710
|
const userName = String(flags.user || "root").trim() || "root";
|
|
713
711
|
const requestedRunId = String(flags.runId || "").trim();
|
|
@@ -733,10 +731,17 @@ var main = async () => {
|
|
|
733
731
|
summary: "Awaiting model patch",
|
|
734
732
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
735
733
|
};
|
|
734
|
+
let checkoutRoot = "";
|
|
736
735
|
let worktreePath = "";
|
|
737
736
|
await saveAgentRun(userName, run.runId, run.strategy, agentRun);
|
|
738
737
|
try {
|
|
739
|
-
|
|
738
|
+
const checkout = await createStrategyCheckout(run.strategy, branchName);
|
|
739
|
+
checkoutRoot = checkout.checkoutRoot;
|
|
740
|
+
worktreePath = checkout.checkoutPath;
|
|
741
|
+
agentRun.repository = checkout.repository;
|
|
742
|
+
await runCommandOrThrow("yarn", ["install", "--immutable"], {
|
|
743
|
+
cwd: worktreePath
|
|
744
|
+
});
|
|
740
745
|
const userPrompt = await buildPrompt(worktreePath, run, allowedPrefixes);
|
|
741
746
|
const messages = [
|
|
742
747
|
{ role: "system", content: AGENT_SYSTEM_PROMPT },
|
|
@@ -888,8 +893,8 @@ Return a corrected unified diff only. Keep the same allowed paths.`
|
|
|
888
893
|
}
|
|
889
894
|
process.exit(1);
|
|
890
895
|
} finally {
|
|
891
|
-
if (
|
|
892
|
-
await
|
|
896
|
+
if (checkoutRoot) {
|
|
897
|
+
await cleanupStrategyCheckout(checkoutRoot);
|
|
893
898
|
}
|
|
894
899
|
}
|
|
895
900
|
};
|