codexuse-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.
@@ -19219,6 +19219,22 @@ const GitStackedAction = Literals([
19219
19219
  "commit_push",
19220
19220
  "commit_push_pr"
19221
19221
  ]);
19222
+ const GitActionProgressPhase = Literals([
19223
+ "branch",
19224
+ "commit",
19225
+ "push",
19226
+ "pr"
19227
+ ]);
19228
+ const GitActionProgressKind = Literals([
19229
+ "action_started",
19230
+ "phase_started",
19231
+ "hook_started",
19232
+ "hook_output",
19233
+ "hook_finished",
19234
+ "action_finished",
19235
+ "action_failed"
19236
+ ]);
19237
+ const GitActionProgressStream = Literals(["stdout", "stderr"]);
19222
19238
  const GitCommitStepStatus = Literals(["created", "skipped_no_changes"]);
19223
19239
  const GitPushStepStatus = Literals([
19224
19240
  "pushed",
@@ -19266,6 +19282,7 @@ const GitResolvedPullRequest = Struct({
19266
19282
  const GitStatusInput = Struct({ cwd: TrimmedNonEmptyStringSchema });
19267
19283
  const GitPullInput = Struct({ cwd: TrimmedNonEmptyStringSchema });
19268
19284
  const GitRunStackedActionInput = Struct({
19285
+ actionId: optional$2(TrimmedNonEmptyStringSchema),
19269
19286
  cwd: TrimmedNonEmptyStringSchema,
19270
19287
  action: GitStackedAction,
19271
19288
  commitMessage: optional$2(TrimmedNonEmptyStringSchema.check(isMaxLength(1e4))),
@@ -19371,6 +19388,61 @@ const GitPullResult = Struct({
19371
19388
  branch: TrimmedNonEmptyStringSchema,
19372
19389
  upstreamBranch: TrimmedNonEmptyStringSchema.pipe(NullOr)
19373
19390
  });
19391
+ const GitActionProgressBase = Struct({
19392
+ actionId: TrimmedNonEmptyStringSchema,
19393
+ cwd: TrimmedNonEmptyStringSchema,
19394
+ action: GitStackedAction
19395
+ });
19396
+ const GitActionStartedEvent = Struct({
19397
+ ...GitActionProgressBase.fields,
19398
+ kind: Literal("action_started"),
19399
+ phases: Array$1(GitActionProgressPhase)
19400
+ });
19401
+ const GitActionPhaseStartedEvent = Struct({
19402
+ ...GitActionProgressBase.fields,
19403
+ kind: Literal("phase_started"),
19404
+ phase: GitActionProgressPhase,
19405
+ label: TrimmedNonEmptyStringSchema
19406
+ });
19407
+ const GitActionHookStartedEvent = Struct({
19408
+ ...GitActionProgressBase.fields,
19409
+ kind: Literal("hook_started"),
19410
+ hookName: TrimmedNonEmptyStringSchema
19411
+ });
19412
+ const GitActionHookOutputEvent = Struct({
19413
+ ...GitActionProgressBase.fields,
19414
+ kind: Literal("hook_output"),
19415
+ hookName: NullOr(TrimmedNonEmptyStringSchema),
19416
+ stream: GitActionProgressStream,
19417
+ text: TrimmedNonEmptyStringSchema
19418
+ });
19419
+ const GitActionHookFinishedEvent = Struct({
19420
+ ...GitActionProgressBase.fields,
19421
+ kind: Literal("hook_finished"),
19422
+ hookName: TrimmedNonEmptyStringSchema,
19423
+ exitCode: NullOr(Int),
19424
+ durationMs: NullOr(NonNegativeInt)
19425
+ });
19426
+ const GitActionFinishedEvent = Struct({
19427
+ ...GitActionProgressBase.fields,
19428
+ kind: Literal("action_finished"),
19429
+ result: GitRunStackedActionResult
19430
+ });
19431
+ const GitActionFailedEvent = Struct({
19432
+ ...GitActionProgressBase.fields,
19433
+ kind: Literal("action_failed"),
19434
+ phase: NullOr(GitActionProgressPhase),
19435
+ message: TrimmedNonEmptyStringSchema
19436
+ });
19437
+ const GitActionProgressEvent = Union([
19438
+ GitActionStartedEvent,
19439
+ GitActionPhaseStartedEvent,
19440
+ GitActionHookStartedEvent,
19441
+ GitActionHookOutputEvent,
19442
+ GitActionHookFinishedEvent,
19443
+ GitActionFinishedEvent,
19444
+ GitActionFailedEvent
19445
+ ]);
19374
19446
  //#endregion
19375
19447
  //#region ../../packages/t3-contracts/src/keybindings.ts
19376
19448
  const MAX_KEYBINDING_VALUE_LENGTH = 64;
@@ -19476,27 +19548,44 @@ const EDITORS = [
19476
19548
  {
19477
19549
  id: "cursor",
19478
19550
  label: "Cursor",
19479
- command: "cursor"
19551
+ command: "cursor",
19552
+ supportsGoto: true
19480
19553
  },
19481
19554
  {
19482
19555
  id: "vscode",
19483
19556
  label: "VS Code",
19484
- command: "code"
19557
+ command: "code",
19558
+ supportsGoto: true
19559
+ },
19560
+ {
19561
+ id: "vscode-insiders",
19562
+ label: "VS Code Insiders",
19563
+ command: "code-insiders",
19564
+ supportsGoto: true
19565
+ },
19566
+ {
19567
+ id: "vscodium",
19568
+ label: "VSCodium",
19569
+ command: "codium",
19570
+ supportsGoto: true
19485
19571
  },
19486
19572
  {
19487
19573
  id: "zed",
19488
19574
  label: "Zed",
19489
- command: "zed"
19575
+ command: "zed",
19576
+ supportsGoto: false
19490
19577
  },
19491
19578
  {
19492
19579
  id: "antigravity",
19493
19580
  label: "Antigravity",
19494
- command: "agy"
19581
+ command: "agy",
19582
+ supportsGoto: false
19495
19583
  },
19496
19584
  {
19497
19585
  id: "file-manager",
19498
19586
  label: "File Manager",
19499
- command: null
19587
+ command: null,
19588
+ supportsGoto: false
19500
19589
  }
19501
19590
  ];
19502
19591
  const EditorId = Literals(EDITORS.map((e) => e.id));
@@ -19638,6 +19727,7 @@ const WS_METHODS = {
19638
19727
  telemetryTrack: "telemetry.track"
19639
19728
  };
19640
19729
  const WS_CHANNELS = {
19730
+ gitActionProgress: "git.actionProgress",
19641
19731
  terminalEvent: "terminal.event",
19642
19732
  serverWelcome: "server.welcome",
19643
19733
  serverConfigUpdated: "server.configUpdated",
@@ -19802,6 +19892,7 @@ const makeWsPushSchema = (channel, payload) => Struct({
19802
19892
  const WsPushServerWelcome = makeWsPushSchema(WS_CHANNELS.serverWelcome, WsWelcomePayload);
19803
19893
  const WsPushServerConfigUpdated = makeWsPushSchema(WS_CHANNELS.serverConfigUpdated, ServerConfigUpdatedPayload);
19804
19894
  const WsPushServerProvidersUpdated = makeWsPushSchema(WS_CHANNELS.serverProvidersUpdated, ServerProviderUpdatedPayload);
19895
+ const WsPushGitActionProgress = makeWsPushSchema(WS_CHANNELS.gitActionProgress, GitActionProgressEvent);
19805
19896
  const WsPushTerminalEvent = makeWsPushSchema(WS_CHANNELS.terminalEvent, TerminalEvent);
19806
19897
  const WsPushProfilesSwitched = makeWsPushSchema(WS_CHANNELS.profilesSwitched, Unknown);
19807
19898
  const WsPushRateLimitsUpdated = makeWsPushSchema(WS_CHANNELS.rateLimitsUpdated, Unknown);
@@ -19809,6 +19900,7 @@ const WsPushRateLimitsState = makeWsPushSchema(WS_CHANNELS.rateLimitsState, Unkn
19809
19900
  const WsPushCliStatusUpdated = makeWsPushSchema(WS_CHANNELS.cliStatusUpdated, Unknown);
19810
19901
  const WsPushOrchestrationDomainEvent = makeWsPushSchema(ORCHESTRATION_WS_CHANNELS.domainEvent, OrchestrationEvent);
19811
19902
  const WsPushChannelSchema = Literals([
19903
+ WS_CHANNELS.gitActionProgress,
19812
19904
  WS_CHANNELS.serverWelcome,
19813
19905
  WS_CHANNELS.serverConfigUpdated,
19814
19906
  WS_CHANNELS.serverProvidersUpdated,
@@ -19823,6 +19915,7 @@ const WsPush = Union([
19823
19915
  WsPushServerWelcome,
19824
19916
  WsPushServerConfigUpdated,
19825
19917
  WsPushServerProvidersUpdated,
19918
+ WsPushGitActionProgress,
19826
19919
  WsPushTerminalEvent,
19827
19920
  WsPushProfilesSwitched,
19828
19921
  WsPushRateLimitsUpdated,
@@ -19852,8 +19945,8 @@ var OpenError = class extends TaggedErrorClass()("OpenError", {
19852
19945
  cause: optional$2(Defect)
19853
19946
  }) {};
19854
19947
  const LINE_COLUMN_SUFFIX_PATTERN = /:\d+(?::\d+)?$/;
19855
- function shouldUseGotoFlag(editorId, target) {
19856
- return (editorId === "cursor" || editorId === "vscode") && LINE_COLUMN_SUFFIX_PATTERN.test(target);
19948
+ function shouldUseGotoFlag(editor, target) {
19949
+ return editor.supportsGoto && LINE_COLUMN_SUFFIX_PATTERN.test(target);
19857
19950
  }
19858
19951
  function fileManagerCommandForPlatform(platform) {
19859
19952
  switch (platform) {
@@ -19943,7 +20036,7 @@ var Open = class extends Service()("t3/open") {};
19943
20036
  const resolveEditorLaunch = fnUntraced(function* (input, platform = process.platform) {
19944
20037
  const editorDef = EDITORS.find((editor) => editor.id === input.editor);
19945
20038
  if (!editorDef) return yield* new OpenError({ message: `Unknown editor: ${input.editor}` });
19946
- if (editorDef.command) return shouldUseGotoFlag(editorDef.id, input.cwd) ? {
20039
+ if (editorDef.command) return shouldUseGotoFlag(editorDef, input.cwd) ? {
19947
20040
  command: editorDef.command,
19948
20041
  args: ["--goto", input.cwd]
19949
20042
  } : {
@@ -29154,16 +29247,17 @@ function getActiveOffer() {
29154
29247
  checkoutBaseUrl: "https://hweihwang.gumroad.com/l/codex-use"
29155
29248
  };
29156
29249
  }
29157
- function buildCheckoutUrl(offer, utm) {
29250
+ function buildCheckoutUrl(offer, options) {
29158
29251
  const base = offer.checkoutBaseUrl;
29159
29252
  const withCoupon = offer.isActive && offer.couponCode ? `${base}/${offer.couponCode}` : base;
29160
- if (!utm) return withCoupon;
29161
- const params = new URLSearchParams();
29162
- params.set("utm_source", utm.source);
29163
- params.set("utm_medium", utm.medium);
29164
- if (utm.campaign) params.set("utm_campaign", utm.campaign);
29165
- else if (offer.campaign) params.set("utm_campaign", offer.campaign);
29166
- return `${withCoupon}?${params.toString()}`;
29253
+ const url = new URL(withCoupon);
29254
+ if (options?.directCheckout) url.searchParams.set("wanted", "true");
29255
+ if (!options?.source || !options?.medium) return url.toString();
29256
+ url.searchParams.set("utm_source", options.source);
29257
+ url.searchParams.set("utm_medium", options.medium);
29258
+ if (options.campaign) url.searchParams.set("utm_campaign", options.campaign);
29259
+ else if (offer.campaign) url.searchParams.set("utm_campaign", offer.campaign);
29260
+ return url.toString();
29167
29261
  }
29168
29262
  //#endregion
29169
29263
  //#region ../../packages/runtime-profiles/src/license/service.ts
@@ -29171,6 +29265,7 @@ const offer = getActiveOffer();
29171
29265
  const PRODUCT_PERMALINK = offer.productPermalink;
29172
29266
  const PRODUCT_ID = "3_CcyVEXt2FOMiEpPx8xzw==";
29173
29267
  const PRODUCT_URL = buildCheckoutUrl(offer);
29268
+ const CHECKOUT_URL = buildCheckoutUrl(offer, { directCheckout: true });
29174
29269
  const LICENSE_PRICE_DISPLAY = offer.isActive ? offer.salePriceDisplay : offer.basePriceDisplay;
29175
29270
  const BASE_PRICE_DISPLAY = offer.basePriceDisplay;
29176
29271
  const PROMO_CODE = offer.couponCode;
@@ -29287,6 +29382,7 @@ function toLicenseStatus(stored, overrides = {}) {
29287
29382
  message: null,
29288
29383
  error: stored?.lastVerificationError ?? null,
29289
29384
  productUrl: PRODUCT_URL,
29385
+ checkoutUrl: CHECKOUT_URL,
29290
29386
  productId: PRODUCT_ID,
29291
29387
  productPermalink: PRODUCT_PERMALINK,
29292
29388
  priceDisplay: LICENSE_PRICE_DISPLAY,
@@ -35605,6 +35701,14 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
35605
35701
  }
35606
35702
  }];
35607
35703
  }
35704
+ if (event.method === "process/stderr") return [{
35705
+ type: "runtime.warning",
35706
+ ...runtimeEventBase(event, canonicalThreadId),
35707
+ payload: {
35708
+ message: event.message ?? "Codex process stderr",
35709
+ ...event.payload !== void 0 ? { detail: event.payload } : {}
35710
+ }
35711
+ }];
35608
35712
  if (event.method === "windows/worldWritableWarning") return [{
35609
35713
  type: "runtime.warning",
35610
35714
  ...runtimeEventBase(event, canonicalThreadId),
@@ -38143,6 +38247,20 @@ const makeGitManager = gen(function* () {
38143
38247
  const gitCore = yield* GitCore;
38144
38248
  const gitHubCli = yield* GitHubCli;
38145
38249
  const textGeneration = yield* TextGeneration;
38250
+ const createProgressEmitter = (input, options) => {
38251
+ const actionId = options?.actionId ?? randomUUID();
38252
+ const reporter = options?.progressReporter;
38253
+ const emit = (event) => reporter ? reporter.publish({
38254
+ actionId,
38255
+ cwd: input.cwd,
38256
+ action: input.action,
38257
+ ...event
38258
+ }) : void_$1;
38259
+ return {
38260
+ actionId,
38261
+ emit
38262
+ };
38263
+ };
38146
38264
  const configurePullRequestHeadUpstream = (cwd, pullRequest, localBranch = pullRequest.headBranch) => gen(function* () {
38147
38265
  const repositoryNameWithOwner = resolveHeadRepositoryNameWithOwner(pullRequest) ?? "";
38148
38266
  if (repositoryNameWithOwner.length === 0) return;
@@ -38344,15 +38462,28 @@ const makeGitManager = gen(function* () {
38344
38462
  commitMessage: formatCommitMessage(generated.subject, generated.body)
38345
38463
  };
38346
38464
  });
38347
- const runCommitStep = (cwd, branch, commitMessage, preResolvedSuggestion, filePaths, model) => gen(function* () {
38348
- const suggestion = preResolvedSuggestion ?? (yield* resolveCommitAndBranchSuggestion({
38349
- cwd,
38350
- branch,
38351
- ...commitMessage ? { commitMessage } : {},
38352
- ...filePaths ? { filePaths } : {},
38353
- ...model ? { model } : {}
38354
- }));
38465
+ const runCommitStep = (cwd, branch, commitMessage, preResolvedSuggestion, filePaths, model, progress) => gen(function* () {
38466
+ let suggestion = preResolvedSuggestion;
38467
+ if (!suggestion) {
38468
+ if (!commitMessage?.trim()) yield* progress?.emit({
38469
+ kind: "phase_started",
38470
+ phase: "commit",
38471
+ label: "Generating commit message..."
38472
+ }) ?? void_$1;
38473
+ suggestion = yield* resolveCommitAndBranchSuggestion({
38474
+ cwd,
38475
+ branch,
38476
+ ...commitMessage ? { commitMessage } : {},
38477
+ ...filePaths ? { filePaths } : {},
38478
+ ...model ? { model } : {}
38479
+ });
38480
+ }
38355
38481
  if (!suggestion) return { status: "skipped_no_changes" };
38482
+ yield* progress?.emit({
38483
+ kind: "phase_started",
38484
+ phase: "commit",
38485
+ label: "Committing..."
38486
+ }) ?? void_$1;
38356
38487
  const { commitSha } = yield* gitCore.commit(cwd, suggestion.subject, suggestion.body);
38357
38488
  return {
38358
38489
  status: "created",
@@ -38555,32 +38686,79 @@ const makeGitManager = gen(function* () {
38555
38686
  status,
38556
38687
  resolvePullRequest,
38557
38688
  preparePullRequestThread,
38558
- runStackedAction: fnUntraced(function* (input) {
38559
- const wantsPush = input.action !== "commit";
38560
- const wantsPr = input.action === "commit_push_pr";
38561
- const initialStatus = yield* gitCore.statusDetails(input.cwd);
38562
- if (!input.featureBranch && wantsPush && !initialStatus.branch) return yield* gitManagerError("runStackedAction", "Cannot push from detached HEAD.");
38563
- if (!input.featureBranch && wantsPr && !initialStatus.branch) return yield* gitManagerError("runStackedAction", "Cannot create a pull request from detached HEAD.");
38564
- let branchStep;
38565
- let commitMessageForStep = input.commitMessage;
38566
- let preResolvedCommitSuggestion = void 0;
38567
- if (input.featureBranch) {
38568
- const result = yield* runFeatureBranchStep(input.cwd, initialStatus.branch, input.commitMessage, input.filePaths, input.textGenerationModel);
38569
- branchStep = result.branchStep;
38570
- commitMessageForStep = result.resolvedCommitMessage;
38571
- preResolvedCommitSuggestion = result.resolvedCommitSuggestion;
38572
- } else branchStep = { status: "skipped_not_requested" };
38573
- const currentBranch = branchStep.name ?? initialStatus.branch;
38574
- const commit = yield* runCommitStep(input.cwd, currentBranch, commitMessageForStep, preResolvedCommitSuggestion, input.filePaths, input.textGenerationModel);
38575
- const push = wantsPush ? yield* gitCore.pushCurrentBranch(input.cwd, currentBranch) : { status: "skipped_not_requested" };
38576
- const pr = wantsPr ? yield* runPrStep(input.cwd, currentBranch, input.textGenerationModel) : { status: "skipped_not_requested" };
38577
- return {
38578
- action: input.action,
38579
- branch: branchStep,
38580
- commit,
38581
- push,
38582
- pr
38583
- };
38689
+ runStackedAction: fnUntraced(function* (input, options) {
38690
+ const progress = createProgressEmitter({
38691
+ cwd: input.cwd,
38692
+ action: input.action
38693
+ }, options);
38694
+ const phases = [
38695
+ ...input.featureBranch ? ["branch"] : [],
38696
+ "commit",
38697
+ ...input.action !== "commit" ? ["push"] : [],
38698
+ ...input.action === "commit_push_pr" ? ["pr"] : []
38699
+ ];
38700
+ let currentPhase = null;
38701
+ return yield* gen(function* () {
38702
+ yield* progress.emit({
38703
+ kind: "action_started",
38704
+ phases
38705
+ });
38706
+ const wantsPush = input.action !== "commit";
38707
+ const wantsPr = input.action === "commit_push_pr";
38708
+ const initialStatus = yield* gitCore.statusDetails(input.cwd);
38709
+ if (!input.featureBranch && wantsPush && !initialStatus.branch) return yield* gitManagerError("runStackedAction", "Cannot push from detached HEAD.");
38710
+ if (!input.featureBranch && wantsPr && !initialStatus.branch) return yield* gitManagerError("runStackedAction", "Cannot create a pull request from detached HEAD.");
38711
+ let branchStep;
38712
+ let commitMessageForStep = input.commitMessage;
38713
+ let preResolvedCommitSuggestion = void 0;
38714
+ if (input.featureBranch) {
38715
+ currentPhase = "branch";
38716
+ yield* progress.emit({
38717
+ kind: "phase_started",
38718
+ phase: "branch",
38719
+ label: "Preparing feature branch..."
38720
+ });
38721
+ const result = yield* runFeatureBranchStep(input.cwd, initialStatus.branch, input.commitMessage, input.filePaths, input.textGenerationModel);
38722
+ branchStep = result.branchStep;
38723
+ commitMessageForStep = result.resolvedCommitMessage;
38724
+ preResolvedCommitSuggestion = result.resolvedCommitSuggestion;
38725
+ } else branchStep = { status: "skipped_not_requested" };
38726
+ const currentBranch = branchStep.name ?? initialStatus.branch;
38727
+ currentPhase = "commit";
38728
+ const commit = yield* runCommitStep(input.cwd, currentBranch, commitMessageForStep, preResolvedCommitSuggestion, input.filePaths, input.textGenerationModel, progress);
38729
+ const push = wantsPush ? yield* progress.emit({
38730
+ kind: "phase_started",
38731
+ phase: "push",
38732
+ label: "Pushing..."
38733
+ }).pipe(flatMap(() => gen(function* () {
38734
+ currentPhase = "push";
38735
+ return yield* gitCore.pushCurrentBranch(input.cwd, currentBranch);
38736
+ }))) : { status: "skipped_not_requested" };
38737
+ const pr = wantsPr ? yield* progress.emit({
38738
+ kind: "phase_started",
38739
+ phase: "pr",
38740
+ label: "Creating PR..."
38741
+ }).pipe(flatMap(() => gen(function* () {
38742
+ currentPhase = "pr";
38743
+ return yield* runPrStep(input.cwd, currentBranch, input.textGenerationModel);
38744
+ }))) : { status: "skipped_not_requested" };
38745
+ const result = {
38746
+ action: input.action,
38747
+ branch: branchStep,
38748
+ commit,
38749
+ push,
38750
+ pr
38751
+ };
38752
+ yield* progress.emit({
38753
+ kind: "action_finished",
38754
+ result
38755
+ });
38756
+ return result;
38757
+ }).pipe(catch_((error) => progress.emit({
38758
+ kind: "action_failed",
38759
+ phase: currentPhase,
38760
+ message: error.message
38761
+ }).pipe(flatMap(() => fail$1(error)))));
38584
38762
  })
38585
38763
  };
38586
38764
  });
@@ -43356,6 +43534,9 @@ const LEGACY_LICENSE_SECRET_FILE = "license.secret";
43356
43534
  function isRecord$3(value) {
43357
43535
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
43358
43536
  }
43537
+ function isMissingPathError(error) {
43538
+ return error.code === "ENOENT";
43539
+ }
43359
43540
  function resolveHomeDir() {
43360
43541
  const home = process.env.HOME || process.env.USERPROFILE || os.homedir();
43361
43542
  if (!home) throw new Error("HOME is not set.");
@@ -43479,7 +43660,7 @@ async function cleanupLegacyCanonicalSources() {
43479
43660
  }
43480
43661
  }
43481
43662
  } catch (error) {
43482
- logWarn("Failed cleaning legacy profile metadata:", {
43663
+ if (!isMissingPathError(error)) logWarn("Failed cleaning legacy profile metadata:", {
43483
43664
  profileHomesRoot,
43484
43665
  error: error instanceof Error ? error.message : String(error)
43485
43666
  });
@@ -43492,7 +43673,7 @@ async function cleanupLegacyCanonicalSources() {
43492
43673
  await removeIfExists(path.join(skillsRoot, entry.name, LEGACY_SKILL_MANIFEST));
43493
43674
  }
43494
43675
  } catch (error) {
43495
- logWarn("Failed cleaning legacy skills metadata:", {
43676
+ if (!isMissingPathError(error)) logWarn("Failed cleaning legacy skills metadata:", {
43496
43677
  skillsRoot,
43497
43678
  error: error instanceof Error ? error.message : String(error)
43498
43679
  });
@@ -44557,8 +44738,6 @@ const AGENTS_FILENAME = "AGENTS.md";
44557
44738
  const MANAGED_AGENTS_DIR = "agents";
44558
44739
  const DEFAULT_AGENT_MAX_THREADS = 6;
44559
44740
  const DEFAULT_AGENT_MAX_DEPTH = 1;
44560
- const DEFAULT_AGENT_MODEL = "gpt-5-codex";
44561
- const DEFAULT_REASONING_EFFORT = "medium";
44562
44741
  const RESERVED_AGENT_KEYS = new Set(["max_threads", "max_depth"]);
44563
44742
  function asTomlJsonMap(config) {
44564
44743
  return config;
@@ -44816,13 +44995,9 @@ function ensureRoleNameAvailable(config, name, excludingName) {
44816
44995
  }
44817
44996
  }
44818
44997
  function buildTemplateContent(input) {
44819
- const overrides = {
44820
- model: normalizeOptionalString(input.model) ?? DEFAULT_AGENT_MODEL,
44821
- model_reasoning_effort: normalizeOptionalString(input.reasoningEffort) ?? DEFAULT_REASONING_EFFORT
44822
- };
44823
44998
  const developerInstructions = normalizeOptionalString(input.developerInstructions);
44824
- if (developerInstructions) overrides.developer_instructions = developerInstructions;
44825
- return `# Agent-specific overrides\n${ensureTrailingNewline((0, import_toml.stringify)(asTomlJsonMap(overrides)))}`;
44999
+ if (!developerInstructions) return "";
45000
+ return `# Agent-specific overrides\n${ensureTrailingNewline((0, import_toml.stringify)(asTomlJsonMap({ developer_instructions: developerInstructions })))}`;
44826
45001
  }
44827
45002
  async function readManagedRoleConfigPath(agentName, options) {
44828
45003
  const { codexHome, config } = await loadAgentsConfig(options);
@@ -44914,11 +45089,7 @@ async function createAgentRole(payload, options) {
44914
45089
  const relativeConfigPath = managedRelativeConfigForName(name);
44915
45090
  const targetPath = await resolveSafeManagedAbsPathForWrite(loaded.codexHome, relativeConfigPath);
44916
45091
  if (await statFile(targetPath)) throw new Error(`Target config file already exists: ${targetPath}`);
44917
- await saveFileContent(targetPath, buildTemplateContent({
44918
- model: payload.model,
44919
- reasoningEffort: payload.reasoningEffort,
44920
- developerInstructions: payload.developerInstructions
44921
- }));
45092
+ await saveFileContent(targetPath, buildTemplateContent({ developerInstructions: payload.developerInstructions }));
44922
45093
  try {
44923
45094
  const agents = ensureRawTable(loaded.config, "agents");
44924
45095
  agents[name] = {
@@ -47651,10 +47822,11 @@ function profileKey(profile) {
47651
47822
  * When the user is not on a Pro license and has saved more profiles than allowed,
47652
47823
  * this method prunes unauthorized profiles from disk (best effort; logs errors on failure).
47653
47824
  */
47654
- async function loadProfilesViewData() {
47825
+ async function loadProfilesViewData(options = {}) {
47826
+ const backgroundRefresh = options.backgroundRefresh !== false;
47655
47827
  await profileManager.initialize();
47656
47828
  const license = await licenseService.getCachedStatus();
47657
- licenseService.refreshStatusInBackground();
47829
+ if (backgroundRefresh) licenseService.refreshStatusInBackground();
47658
47830
  const { name: currentProfile, trusted: currentProfileTrusted } = await profileManager.getCurrentProfile();
47659
47831
  const profiles = await profileManager.listProfiles();
47660
47832
  const customGroupsByAccountKey = await profileManager.getCustomGroupsByAccountKey();
@@ -47670,10 +47842,12 @@ async function loadProfilesViewData() {
47670
47842
  };
47671
47843
  let enrichedProfiles = effectiveProfiles;
47672
47844
  if (rateLimitEnabled) {
47673
- ensureRateLimitRefresher();
47674
47845
  const rateLimitEligible = effectiveProfiles.filter((profile) => profile.isValid && !profile.tokenStatus?.requiresUserAction);
47675
47846
  const resolvedSnapshots = await resolveRateLimitSnapshots(rateLimitEligible.map((profile) => profileKey(profile)));
47676
- await refreshRateLimitTelemetry(profileManager, rateLimitEligible, resolvedSnapshots);
47847
+ if (backgroundRefresh) {
47848
+ ensureRateLimitRefresher();
47849
+ await refreshRateLimitTelemetry(profileManager, rateLimitEligible, resolvedSnapshots);
47850
+ }
47677
47851
  const refreshState = getRateLimitRefreshState();
47678
47852
  refreshStatus = {
47679
47853
  pendingAccountIds: refreshState.queuedAccountIds.slice(),
@@ -49322,7 +49496,10 @@ var TelegramBridge = class {
49322
49496
  await fs$1.mkdir(path.dirname(lockPath), { recursive: true });
49323
49497
  const payload = JSON.stringify({
49324
49498
  pid: process.pid,
49325
- startedAt: nowIso()
49499
+ parentPid: process.ppid > 0 ? process.ppid : null,
49500
+ startedAt: nowIso(),
49501
+ processStartSignature: this.readProcessStartSignature(process.pid),
49502
+ ownerKind: this.getRuntimeLockOwnerKind()
49326
49503
  }, null, 2);
49327
49504
  try {
49328
49505
  await fs$1.writeFile(lockPath, payload, {
@@ -49334,8 +49511,9 @@ var TelegramBridge = class {
49334
49511
  } catch (error) {
49335
49512
  if (error.code !== "EEXIST") throw error;
49336
49513
  }
49337
- const existingPid = await this.readLockPid(lockPath);
49338
- if (existingPid && existingPid !== process.pid && this.isProcessAlive(existingPid)) throw new Error(`Telegram bridge already running in another process (pid ${existingPid}). Stop the other instance to avoid duplicate replies.`);
49514
+ const existingLock = await this.readRuntimeLock(lockPath);
49515
+ await this.tryRecoverOrphanedDesktopRuntimeLock(existingLock);
49516
+ if (this.isActiveRuntimeLockOwner(existingLock)) throw new Error(this.buildRuntimeLockConflictMessage(existingLock));
49339
49517
  await fs$1.unlink(lockPath).catch(() => void 0);
49340
49518
  await fs$1.writeFile(lockPath, payload, {
49341
49519
  encoding: "utf8",
@@ -49349,15 +49527,178 @@ var TelegramBridge = class {
49349
49527
  if (!lockPath) return;
49350
49528
  await fs$1.unlink(lockPath).catch(() => void 0);
49351
49529
  }
49352
- async readLockPid(lockPath) {
49530
+ async readRuntimeLock(lockPath) {
49353
49531
  try {
49354
49532
  const raw = await fs$1.readFile(lockPath, "utf8");
49355
- const pid = asNumber(JSON.parse(raw).pid);
49356
- return pid && pid > 0 ? Math.trunc(pid) : null;
49533
+ const parsed = JSON.parse(raw);
49534
+ const pid = asNumber(parsed.pid);
49535
+ const parentPid = asNumber(parsed.parentPid);
49536
+ return {
49537
+ pid: pid && pid > 0 ? Math.trunc(pid) : null,
49538
+ parentPid: parentPid && parentPid > 0 ? Math.trunc(parentPid) : null,
49539
+ startedAt: asTrimmedString(parsed.startedAt) || null,
49540
+ processStartSignature: asTrimmedString(parsed.processStartSignature) || null,
49541
+ ownerKind: this.normalizeRuntimeLockOwnerKind(parsed.ownerKind)
49542
+ };
49357
49543
  } catch {
49358
- return null;
49544
+ return {
49545
+ pid: null,
49546
+ parentPid: null,
49547
+ startedAt: null,
49548
+ processStartSignature: null,
49549
+ ownerKind: "unknown"
49550
+ };
49359
49551
  }
49360
49552
  }
49553
+ isActiveRuntimeLockOwner(lock) {
49554
+ const pid = lock.pid;
49555
+ if (!pid || pid === process.pid) return false;
49556
+ if (!this.isProcessAlive(pid)) return false;
49557
+ const liveProcessStartSignature = this.readProcessStartSignature(pid);
49558
+ if (lock.processStartSignature && liveProcessStartSignature) return lock.processStartSignature === liveProcessStartSignature;
49559
+ const liveCommand = this.readProcessCommand(pid);
49560
+ if (liveCommand) return this.isLikelyTelegramBridgeProcessCommand(liveCommand);
49561
+ return true;
49562
+ }
49563
+ normalizeRuntimeLockOwnerKind(value) {
49564
+ const normalized = asTrimmedString(value).toLowerCase();
49565
+ if (normalized === "desktop-app" || normalized === "daemon") return normalized;
49566
+ return "unknown";
49567
+ }
49568
+ getRuntimeLockOwnerKind() {
49569
+ return this.normalizeRuntimeLockOwnerKind(process.env.CODEXUSE_TELEGRAM_RUNTIME_OWNER);
49570
+ }
49571
+ buildRuntimeLockConflictMessage(lock) {
49572
+ const ownerKind = this.getEffectiveRuntimeLockOwnerKind(lock);
49573
+ const pidText = lock.pid ? ` (pid ${lock.pid})` : "";
49574
+ switch (ownerKind) {
49575
+ case "desktop-app": return `Telegram bridge is already active in another CodexUse desktop app process${pidText}. Quit the other desktop session to avoid duplicate replies.`;
49576
+ case "daemon": return `Telegram bridge is already active in a CodexUse daemon process${pidText}. Stop the daemon or disable Telegram there before enabling it here.`;
49577
+ default: return `Telegram bridge is already active in another CodexUse process${pidText}. Stop the other instance to avoid duplicate replies.`;
49578
+ }
49579
+ }
49580
+ getEffectiveRuntimeLockOwnerKind(lock) {
49581
+ if (lock.ownerKind !== "unknown") return lock.ownerKind;
49582
+ if (!lock.pid) return "unknown";
49583
+ const command = this.readProcessCommand(lock.pid);
49584
+ return command ? this.inferRuntimeLockOwnerKindFromCommand(command) : "unknown";
49585
+ }
49586
+ inferRuntimeLockOwnerKindFromCommand(command) {
49587
+ const normalized = command.trim().toLowerCase();
49588
+ if (!normalized) return "unknown";
49589
+ if (normalized.includes("/.electrobun-build/") || normalized.includes(".app/contents/macos/bun") || normalized.includes("resources/app/server/dist/index")) return "desktop-app";
49590
+ if (normalized.includes("cli/dist/server/index") || normalized.includes(" daemon ")) return "daemon";
49591
+ return "unknown";
49592
+ }
49593
+ async tryRecoverOrphanedDesktopRuntimeLock(lock) {
49594
+ const pid = lock.pid;
49595
+ const ownerKind = this.getEffectiveRuntimeLockOwnerKind(lock);
49596
+ if (!pid || ownerKind !== "desktop-app" || pid === process.pid) return;
49597
+ if (!this.isProcessAlive(pid)) return;
49598
+ const parentPid = lock.parentPid ?? this.readProcessParentPid(pid);
49599
+ if (parentPid && parentPid !== 1 && this.isProcessAlive(parentPid)) return;
49600
+ const command = this.readProcessCommand(pid);
49601
+ if (command && !this.isLikelyTelegramBridgeProcessCommand(command)) return;
49602
+ logWarn("[telegram-bridge] terminating orphaned desktop bridge owner", {
49603
+ pid,
49604
+ parentPid,
49605
+ ownerKind,
49606
+ command: command ? compactErrorText(command, 160) : null
49607
+ });
49608
+ await this.terminateProcess(pid);
49609
+ }
49610
+ readProcessParentPid(pid) {
49611
+ if (process.platform === "win32") return null;
49612
+ const result = spawnSync("ps", [
49613
+ "-p",
49614
+ String(pid),
49615
+ "-o",
49616
+ "ppid="
49617
+ ], {
49618
+ encoding: "utf8",
49619
+ stdio: [
49620
+ "ignore",
49621
+ "pipe",
49622
+ "ignore"
49623
+ ]
49624
+ });
49625
+ if (result.status !== 0) return null;
49626
+ const parentPid = asNumber(result.stdout.trim());
49627
+ return parentPid && parentPid > 0 ? Math.trunc(parentPid) : null;
49628
+ }
49629
+ readProcessStartSignature(pid) {
49630
+ if (process.platform === "win32") return null;
49631
+ const result = spawnSync("ps", [
49632
+ "-p",
49633
+ String(pid),
49634
+ "-o",
49635
+ "lstart="
49636
+ ], {
49637
+ encoding: "utf8",
49638
+ stdio: [
49639
+ "ignore",
49640
+ "pipe",
49641
+ "ignore"
49642
+ ]
49643
+ });
49644
+ if (result.status !== 0) return null;
49645
+ const output = result.stdout.trim();
49646
+ return output.length > 0 ? output : null;
49647
+ }
49648
+ readProcessCommand(pid) {
49649
+ if (process.platform === "win32") return null;
49650
+ const result = spawnSync("ps", [
49651
+ "-p",
49652
+ String(pid),
49653
+ "-o",
49654
+ "command="
49655
+ ], {
49656
+ encoding: "utf8",
49657
+ stdio: [
49658
+ "ignore",
49659
+ "pipe",
49660
+ "ignore"
49661
+ ]
49662
+ });
49663
+ if (result.status !== 0) return null;
49664
+ const output = result.stdout.trim();
49665
+ return output.length > 0 ? output : null;
49666
+ }
49667
+ isLikelyTelegramBridgeProcessCommand(command) {
49668
+ const normalized = command.trim().toLowerCase();
49669
+ if (!normalized) return false;
49670
+ return [
49671
+ "codexuse",
49672
+ "codex-use",
49673
+ "apps/server/dist/index",
49674
+ "server/dist/index.mjs",
49675
+ "cli/dist/server/index",
49676
+ "resources/app/server/dist/index"
49677
+ ].some((needle) => normalized.includes(needle));
49678
+ }
49679
+ async terminateProcess(pid) {
49680
+ if (!this.isProcessAlive(pid)) return;
49681
+ try {
49682
+ process.kill(pid, "SIGTERM");
49683
+ } catch {
49684
+ return;
49685
+ }
49686
+ if (await this.waitForProcessExit(pid, 2e3)) return;
49687
+ try {
49688
+ process.kill(pid, "SIGKILL");
49689
+ } catch {
49690
+ return;
49691
+ }
49692
+ await this.waitForProcessExit(pid, 2e3);
49693
+ }
49694
+ async waitForProcessExit(pid, timeoutMs) {
49695
+ const deadline = nowMs() + timeoutMs;
49696
+ while (nowMs() < deadline) {
49697
+ if (!this.isProcessAlive(pid)) return true;
49698
+ await this.sleep(100);
49699
+ }
49700
+ return !this.isProcessAlive(pid);
49701
+ }
49361
49702
  isProcessAlive(pid) {
49362
49703
  try {
49363
49704
  process.kill(pid, 0);
@@ -50005,7 +50346,7 @@ const createServer = fn(function* () {
50005
50346
  persistExternalThreadOverrideIntent,
50006
50347
  runExternalCodexThreadSync
50007
50348
  };
50008
- const routeRequest = fnUntraced(function* (request) {
50349
+ const routeRequest = fnUntraced(function* (request, ws) {
50009
50350
  const orchestrationResult = yield* handleOrchestrationRequest(request.body, orchestrationRequestContext);
50010
50351
  if (orchestrationResult !== unhandledRequest) return orchestrationResult;
50011
50352
  switch (request.body._tag) {
@@ -50069,7 +50410,10 @@ const createServer = fn(function* () {
50069
50410
  }
50070
50411
  case WS_METHODS.gitRunStackedAction: {
50071
50412
  const body = stripRequestTag(request.body);
50072
- return yield* gitManager.runStackedAction(body);
50413
+ return yield* gitManager.runStackedAction(body, {
50414
+ actionId: body.actionId,
50415
+ ...ws ? { progressReporter: { publish: (event) => pushBus.publishClient(ws, WS_CHANNELS.gitActionProgress, event).pipe(asVoid) } } : {}
50416
+ });
50073
50417
  }
50074
50418
  case WS_METHODS.gitResolvePullRequest: {
50075
50419
  const body = stripRequestTag(request.body);
@@ -50532,7 +50876,7 @@ const createServer = fn(function* () {
50532
50876
  id: "unknown",
50533
50877
  error: { message: `Invalid request format: ${formatSchemaError(request.failure)}` }
50534
50878
  });
50535
- const result = yield* exit(routeRequest(request.success));
50879
+ const result = yield* exit(routeRequest(request.success, ws));
50536
50880
  if (isFailure(result)) return yield* sendWsResponse({
50537
50881
  id: request.success.id,
50538
50882
  error: { message: pretty(result.cause) }