@standardagents/code 0.11.8 → 0.12.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/index.js CHANGED
@@ -6491,7 +6491,7 @@ function readVersion() {
6491
6491
  if (typeof pkg.version === "string" && pkg.version) return pkg.version;
6492
6492
  } catch {
6493
6493
  }
6494
- return "0.11.8" ;
6494
+ return "0.12.0" ;
6495
6495
  }
6496
6496
  function isLocalHost(host) {
6497
6497
  return host === "localhost" || host === "127.0.0.1" || host === "::1" || host.endsWith(".local") || host.endsWith(".localhost") || /^10\./.test(host) || /^192\.168\./.test(host) || /^172\.(1[6-9]|2\d|3[01])\./.test(host);
@@ -6606,6 +6606,13 @@ async function readFsResponse(api, machineId) {
6606
6606
  async function readFsRequest(api, machineId) {
6607
6607
  return parseFsRequest(await api.userKvGet(fsRequestKey(machineId)));
6608
6608
  }
6609
+ var FS_POLL_HOT_MS = 1e3;
6610
+ var FS_POLL_IDLE_MS = 5e3;
6611
+ var FS_HOT_WINDOW_MS = 5 * 6e4;
6612
+ function fsPollDelay(lastRequestSeenAt, now) {
6613
+ if (lastRequestSeenAt !== null && now - lastRequestSeenAt < FS_HOT_WINDOW_MS) return FS_POLL_HOT_MS;
6614
+ return FS_POLL_IDLE_MS;
6615
+ }
6609
6616
  async function writeFsResponse(api, machineId, res) {
6610
6617
  await api.userKvSet(fsResponseKey(machineId), { ...res, responded_at: Date.now() });
6611
6618
  }
@@ -7517,7 +7524,6 @@ function runUpdate(pm) {
7517
7524
  // src/daemon.ts
7518
7525
  var HEARTBEAT_MS = 3e4;
7519
7526
  var COMMAND_POLL_MS = 8e3;
7520
- var FS_POLL_MS = 1e3;
7521
7527
  var RECLAIM_PROBE_MS = 2 * 6e4;
7522
7528
  var UPDATE_CHECK_MS = 6 * 60 * 6e4;
7523
7529
  var SWEEP_MS = 10 * 6e4;
@@ -7868,12 +7874,14 @@ Run \`standardcode daemon install\` (or plain \`standardcode\`) once to sign in.
7868
7874
  void drainCommands();
7869
7875
  const commandTimer = setInterval(() => void drainCommands(), COMMAND_POLL_MS);
7870
7876
  let lastFsNonce = null;
7877
+ let lastFsRequestSeenAt = null;
7871
7878
  let fsBusy = false;
7872
7879
  const drainFsRequests = async () => {
7873
7880
  if (fsBusy) return;
7874
7881
  fsBusy = true;
7875
7882
  try {
7876
7883
  const req = await readFsRequest(api, identity.machine_id).catch(() => null);
7884
+ if (req) lastFsRequestSeenAt = Math.max(lastFsRequestSeenAt ?? 0, req.requested_at);
7877
7885
  if (!req || req.nonce === lastFsNonce) return;
7878
7886
  lastFsNonce = req.nonce;
7879
7887
  let ok = true;
@@ -7891,7 +7899,15 @@ Run \`standardcode daemon install\` (or plain \`standardcode\`) once to sign in.
7891
7899
  fsBusy = false;
7892
7900
  }
7893
7901
  };
7894
- const fsTimer = setInterval(() => void drainFsRequests(), FS_POLL_MS);
7902
+ let fsTimer = null;
7903
+ let fsStopped = false;
7904
+ const scheduleFsPoll = () => {
7905
+ if (fsStopped) return;
7906
+ fsTimer = setTimeout(() => {
7907
+ void drainFsRequests().finally(scheduleFsPoll);
7908
+ }, fsPollDelay(lastFsRequestSeenAt, Date.now()));
7909
+ };
7910
+ scheduleFsPoll();
7895
7911
  const sweeper = setInterval(() => {
7896
7912
  if (updateReady && ![...workers.values()].some((w) => w.busy)) {
7897
7913
  daemonLog("restarting to apply the installed update");
@@ -7905,7 +7921,8 @@ Run \`standardcode daemon install\` (or plain \`standardcode\`) once to sign in.
7905
7921
  clearInterval(reclaim);
7906
7922
  clearInterval(updateTimer);
7907
7923
  clearInterval(commandTimer);
7908
- clearInterval(fsTimer);
7924
+ fsStopped = true;
7925
+ if (fsTimer) clearTimeout(fsTimer);
7909
7926
  clearInterval(sweeper);
7910
7927
  for (const worker of workers.values()) worker.stop();
7911
7928
  events.close();
@@ -8515,6 +8532,9 @@ function printUsage() {
8515
8532
  "",
8516
8533
  `${c5.bold}Usage${c5.reset}`,
8517
8534
  " standardcode [options] [dir]",
8535
+ " With a directory argument (e.g. `standardcode ./`),",
8536
+ " the session starts right there on this machine \u2014",
8537
+ " no machine or project questions.",
8518
8538
  " standardcode login [--endpoint <url>] [--token <key>]",
8519
8539
  " Sign in (or switch accounts \u2014 always re-runs the flow).",
8520
8540
  " standardcode logout [--endpoint <url>]",
@@ -8729,6 +8749,7 @@ async function main() {
8729
8749
  const endpointArg = cliArgs.endpoint;
8730
8750
  const endpointOverride = cliArgs.promptEndpoint || typeof endpointArg === "string" && endpointArg.trim() !== "";
8731
8751
  const dirArg = cliArgs.dir;
8752
+ const dirArgProvided = Boolean(dirArg && dirArg.trim() !== "");
8732
8753
  let projectDir = path4.resolve(dirArg || process.cwd());
8733
8754
  const machine = os8.hostname();
8734
8755
  const reader = { rl: null };
@@ -8993,15 +9014,23 @@ ${c5.bold}This machine has no always-on daemon${c5.reset} ${c5.dim}\u2014 sessio
8993
9014
  let existing = [];
8994
9015
  let hadResumeMenu = false;
8995
9016
  let where = null;
8996
- let step = remoteTargets.length > 0 ? "machine" : "thread";
9017
+ const locationFlow = !dirArgProvided && remoteTargets.length > 0;
9018
+ let step = locationFlow ? "machine" : "thread";
9019
+ let pickedHere = false;
8997
9020
  flow: for (; ; ) {
8998
9021
  if (step === "machine") {
9022
+ pickedHere = false;
8999
9023
  const picked = await tui.select(
9000
9024
  `${c5.bold}Where should this session run?${c5.reset} ${c5.dim}\u2191\u2193 \xB7 enter \xB7 esc${c5.reset}`,
9001
9025
  [
9026
+ {
9027
+ label: `In this directory, on this machine`,
9028
+ detail: `${shortenPath(launchDir)} \xB7 tools run locally`,
9029
+ value: "here"
9030
+ },
9002
9031
  {
9003
9032
  label: `This machine \u2014 ${self ? machineDisplayName(self) : machine}`,
9004
- detail: "tools run locally",
9033
+ detail: "tools run locally \xB7 choose a project",
9005
9034
  value: null
9006
9035
  },
9007
9036
  ...remoteTargets.map((m) => ({
@@ -9013,6 +9042,16 @@ ${c5.bold}This machine has no always-on daemon${c5.reset} ${c5.dim}\u2014 sessio
9013
9042
  { spaced: true }
9014
9043
  );
9015
9044
  if (picked === void 0) process.exit(0);
9045
+ if (picked === "here") {
9046
+ session.mode = "local";
9047
+ session.runner = void 0;
9048
+ session.remotePath = void 0;
9049
+ projectDir = launchDir;
9050
+ where = null;
9051
+ pickedHere = true;
9052
+ step = "thread";
9053
+ continue;
9054
+ }
9016
9055
  where = picked;
9017
9056
  step = "project";
9018
9057
  } else if (step === "project") {
@@ -9085,8 +9124,8 @@ ${c5.bold}This machine has no always-on daemon${c5.reset} ${c5.dim}\u2014 sessio
9085
9124
  items
9086
9125
  );
9087
9126
  if (picked === void 0) {
9088
- if (remoteTargets.length > 0) {
9089
- step = "project";
9127
+ if (locationFlow) {
9128
+ step = pickedHere ? "machine" : "project";
9090
9129
  continue;
9091
9130
  }
9092
9131
  process.exit(0);
@@ -9120,8 +9159,8 @@ ${c5.bold}This machine has no always-on daemon${c5.reset} ${c5.dim}\u2014 sessio
9120
9159
  step = "thread";
9121
9160
  continue;
9122
9161
  }
9123
- if (remoteTargets.length > 0) {
9124
- step = "project";
9162
+ if (locationFlow) {
9163
+ step = pickedHere ? "machine" : "project";
9125
9164
  continue;
9126
9165
  }
9127
9166
  process.exit(0);