@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.
@@ -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
- `packages/strategies/src/${strategy}/`
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: `stable`.");
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 git worktree"
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 the TradeJS monorepo.
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
- ["prettify", ["yarn", "prettify"]],
493
- ["typecheck", ["yarn", "typecheck"]],
494
- ["unit", ["yarn", "unit"]]
494
+ ["checks", ["yarn", "checks"]]
495
495
  ];
496
496
  agentRun.validation = {
497
- prettify: "pending",
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() || "stable";
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 createWorktree = async (branchName) => {
687
- const worktreeToken = branchName.replace(/[/:]+/g, "--");
688
- const worktreeRoot = import_node_path.default.join(projectRoot, ".agent-worktrees");
689
- const worktreePath = import_node_path.default.join(worktreeRoot, worktreeToken);
690
- await import_promises.default.mkdir(worktreeRoot, { recursive: true });
691
- await runCommand("git", ["worktree", "remove", "--force", worktreePath], {
692
- cwd: projectRoot
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
- ["worktree", "add", "-B", branchName, worktreePath, "origin/stable"],
700
- {
701
- cwd: projectRoot
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
- return worktreePath;
705
- };
706
- var cleanupWorktree = async (worktreePath) => {
707
- await runCommand("git", ["worktree", "remove", "--force", worktreePath], {
708
- cwd: projectRoot
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
- worktreePath = await createWorktree(branchName);
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 (worktreePath) {
892
- await cleanupWorktree(worktreePath);
896
+ if (checkoutRoot) {
897
+ await cleanupStrategyCheckout(checkoutRoot);
893
898
  }
894
899
  }
895
900
  };