@omniralph/agent 0.5.0 → 0.6.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 +419 -54
- package/dist/cli.js.map +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -860,7 +860,13 @@ var RalphPrepareResult = z10.object({
|
|
|
860
860
|
headSha: CommitSha,
|
|
861
861
|
durationMs: z10.int().min(0)
|
|
862
862
|
});
|
|
863
|
+
var RALPH_REQUEST_SOURCES = ["linear", "chat"];
|
|
863
864
|
var RalphRequestPayload = RalphJobBase.extend({
|
|
865
|
+
/**
|
|
866
|
+
* Where the requests come from. Older control panels don't send it (Linear);
|
|
867
|
+
* older agents ignore it and prompt as for Linear.
|
|
868
|
+
*/
|
|
869
|
+
source: z10.enum(RALPH_REQUEST_SOURCES).default("linear"),
|
|
864
870
|
epic: RalphIssue.extend({
|
|
865
871
|
kind: z10.enum(RALPH_EPIC_KINDS).default("children"),
|
|
866
872
|
url: z10.url().nullable().default(null),
|
|
@@ -885,7 +891,12 @@ var RalphRequestPayload = RalphJobBase.extend({
|
|
|
885
891
|
*/
|
|
886
892
|
resumeSessionId: z10.string().min(1).max(200).nullable().default(null),
|
|
887
893
|
/** Every Linear attachment of the run (the epic, its stories and the thread). */
|
|
888
|
-
attachments: RalphAttachments
|
|
894
|
+
attachments: RalphAttachments,
|
|
895
|
+
/**
|
|
896
|
+
* `/ship`: the session prepares one commit and describes it; the job
|
|
897
|
+
* commits, pushes the branch, and opens the PR/MR when there is none.
|
|
898
|
+
*/
|
|
899
|
+
ship: z10.boolean().default(false)
|
|
889
900
|
});
|
|
890
901
|
var RALPH_PULL_REQUEST_ACTIONS = ["open", "update", "ready"];
|
|
891
902
|
var RalphPullRequestAction = z10.object({
|
|
@@ -911,6 +922,10 @@ var RalphRequestResult = z10.object({
|
|
|
911
922
|
findings: z10.array(RalphFindingOutcome).max(50).optional(),
|
|
912
923
|
/** What the session left uncommitted, stashed. */
|
|
913
924
|
stashSha: CommitSha.optional(),
|
|
925
|
+
/** `/ship`: the commit the job made (absent when there was nothing to commit). */
|
|
926
|
+
commitSha: CommitSha.optional(),
|
|
927
|
+
/** `/ship`: whether the job pushed the branch. */
|
|
928
|
+
pushed: z10.boolean().optional(),
|
|
914
929
|
usage: TokenUsage,
|
|
915
930
|
durationMs: z10.int().min(0)
|
|
916
931
|
});
|
|
@@ -971,6 +986,24 @@ var RalphCleanupResult = z10.object({
|
|
|
971
986
|
handled: z10.int().min(0).default(0),
|
|
972
987
|
durationMs: z10.int().min(0)
|
|
973
988
|
});
|
|
989
|
+
var RalphPermissionRequest = z10.object({
|
|
990
|
+
/** Chosen by the agent; the answer is read back with it. */
|
|
991
|
+
requestId: z10.uuid(),
|
|
992
|
+
/** The tool, e.g. `Bash`. */
|
|
993
|
+
tool: z10.string().trim().min(1).max(200),
|
|
994
|
+
/** What the call does, e.g. the command. */
|
|
995
|
+
detail: z10.string().max(4e3).default(""),
|
|
996
|
+
/** Why Claude Code asks (its decision reason), if it said. */
|
|
997
|
+
reason: z10.string().max(1e3).optional(),
|
|
998
|
+
/** How long the agent waits for an answer before it denies the call. */
|
|
999
|
+
timeoutSeconds: z10.int().min(1).max(86400)
|
|
1000
|
+
});
|
|
1001
|
+
var RALPH_PERMISSION_STATUSES = ["pending", "allowed", "denied", "expired"];
|
|
1002
|
+
var RalphPermissionAnswer = z10.object({
|
|
1003
|
+
status: z10.enum(RALPH_PERMISSION_STATUSES),
|
|
1004
|
+
/** Who answered in Linear, when known. */
|
|
1005
|
+
answeredBy: z10.string().nullable().default(null)
|
|
1006
|
+
});
|
|
974
1007
|
var RalphActivity = z10.object({
|
|
975
1008
|
type: z10.enum(["thought", "action"]),
|
|
976
1009
|
/** A thought's text, or an action's name (e.g. the tool). */
|
|
@@ -3619,6 +3652,13 @@ var RequestAgentOutput = z11.object({
|
|
|
3619
3652
|
),
|
|
3620
3653
|
waiting: z11.boolean().optional().describe(
|
|
3621
3654
|
"True only when you are ending your turn to wait for background work you started; you are resumed when it finishes."
|
|
3655
|
+
),
|
|
3656
|
+
commit: z11.object({
|
|
3657
|
+
message: z11.string().describe(
|
|
3658
|
+
"The commit message: a one-line subject (imperative mood, at most ~72 characters), a blank line, then a short body saying what changed and why."
|
|
3659
|
+
)
|
|
3660
|
+
}).optional().describe(
|
|
3661
|
+
"Only when shipping (`/ship`): the message the orchestrator commits the worktree's changes with before it pushes the branch."
|
|
3622
3662
|
)
|
|
3623
3663
|
});
|
|
3624
3664
|
function isWaitingRequest(structured) {
|
|
@@ -3632,6 +3672,7 @@ function readRequestResult(structured) {
|
|
|
3632
3672
|
const parsed = structured === void 0 ? void 0 : RequestAgentOutput.safeParse(structured);
|
|
3633
3673
|
if (!parsed?.success) return { problem: problemWith(parsed?.error) };
|
|
3634
3674
|
const { pullRequest } = parsed.data;
|
|
3675
|
+
const message = parsed.data.commit?.message.trim();
|
|
3635
3676
|
const title = pullRequest?.title?.replace(/\s+/g, " ").trim();
|
|
3636
3677
|
const body = pullRequest?.body?.trim();
|
|
3637
3678
|
const findings = [];
|
|
@@ -3647,7 +3688,8 @@ function readRequestResult(structured) {
|
|
|
3647
3688
|
...pullRequest && {
|
|
3648
3689
|
pullRequest: { action: pullRequest.action, ...title && { title }, ...body && { body } }
|
|
3649
3690
|
},
|
|
3650
|
-
...findings.length > 0 && { findings: findings.slice(0, MAX_FINDING_OUTCOMES) }
|
|
3691
|
+
...findings.length > 0 && { findings: findings.slice(0, MAX_FINDING_OUTCOMES) },
|
|
3692
|
+
...message && { commit: { message } }
|
|
3651
3693
|
}
|
|
3652
3694
|
};
|
|
3653
3695
|
}
|
|
@@ -3937,17 +3979,29 @@ function buildDescribePrPrompt(ctx) {
|
|
|
3937
3979
|
].join("\n");
|
|
3938
3980
|
}
|
|
3939
3981
|
var REQUEST_HEADING = "## Request from your team";
|
|
3940
|
-
function requestSystemAppend(historyRewrite = "when-asked") {
|
|
3982
|
+
function requestSystemAppend(historyRewrite = "when-asked", source = "linear", options = {}) {
|
|
3983
|
+
if (options.ship) return shipSystemAppend(source);
|
|
3941
3984
|
const rewrite = historyRewrite === "when-asked" ? "- Don't rewrite history on your own initiative. When the request explicitly asks for it (rebase, squash, amend, reword), do it on the epic branch and push with `git push --force-with-lease`. That is allowed here." : "- Never rewrite published history or force-push in this repository. If asked to rebase or squash, explain that it is disabled here and offer to merge the base branch instead.";
|
|
3942
|
-
|
|
3985
|
+
const where = source === "chat" ? "a request in a chat thread about a repository" : "a request in a Linear agent session about a PRD epic";
|
|
3986
|
+
const thread = source === "chat" ? "the chat thread" : "the Linear thread";
|
|
3987
|
+
return `You are "Omniralph", an autonomous engineer responding to ${where}.
|
|
3943
3988
|
- Do what the request asks. You may use git (commit, push) when the request calls for it.
|
|
3944
3989
|
- Don't run \`gh\` or \`glab\`: they aren't set up here. Ask for pull/merge request changes (open, update, mark ready) through \`pullRequest\` in your structured result; the orchestrator makes them.
|
|
3945
3990
|
- Only push the epic branch you are on. Never push to, or force-push, the base branch or any other branch.
|
|
3946
3991
|
${rewrite}
|
|
3947
|
-
- The \`summary\` of your structured result is posted to
|
|
3992
|
+
- The \`summary\` of your structured result is posted to ${thread}: summarise what you did, with links (e.g. the PR/MR URL).
|
|
3948
3993
|
- You may run subagents and commands in the background. To wait for them, end your turn with \`waiting: true\` in your structured result: the session stays open, you are resumed as each finishes (for up to an hour), and only your last structured result counts. Stop background processes you no longer need (e.g. dev servers) before you finish.
|
|
3949
3994
|
${GOOD_NEIGHBOR_RULE}`;
|
|
3950
3995
|
}
|
|
3996
|
+
function shipSystemAppend(source) {
|
|
3997
|
+
const where = source === "chat" ? "a chat thread" : "a Linear agent session";
|
|
3998
|
+
const thread = source === "chat" ? "the chat thread" : "the Linear thread";
|
|
3999
|
+
return `You are "Omniralph", an autonomous engineer shipping the work on a branch for ${where}.
|
|
4000
|
+
- Don't run \`git commit\`, \`git push\`, \`git stash pop\`/\`drop\` or any command that rewrites history: the orchestrator commits everything left in the worktree with the \`commit.message\` of your structured result, then pushes the branch.
|
|
4001
|
+
- Don't run \`gh\` or \`glab\`: they aren't set up here. Ask for pull/merge request changes (open, update) through \`pullRequest\` in your structured result; the orchestrator makes them after it pushes.
|
|
4002
|
+
- The \`summary\` of your structured result is posted to ${thread}.
|
|
4003
|
+
${GOOD_NEIGHBOR_RULE}`;
|
|
4004
|
+
}
|
|
3951
4005
|
function capitalize(text) {
|
|
3952
4006
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
3953
4007
|
}
|
|
@@ -3959,12 +4013,19 @@ function buildRequestPrompt(ctx) {
|
|
|
3959
4013
|
).length;
|
|
3960
4014
|
const prd = epic.kind === "single" ? "" : epic.description.trim();
|
|
3961
4015
|
const gates = uniqueCommands(ctx.qualityGates);
|
|
3962
|
-
const
|
|
4016
|
+
const chat = ctx.source === "chat";
|
|
4017
|
+
const intro = chat ? [
|
|
4018
|
+
`You are working on a request from a chat thread: ${epic.title}.`,
|
|
4019
|
+
`It is implemented on branch \`${ctx.branch}\` (base \`${ctx.baseBranch}\`) in this git worktree.`
|
|
4020
|
+
] : [
|
|
3963
4021
|
`You are working on Linear ${epic.identifier}: ${epic.title}.`,
|
|
3964
4022
|
epic.kind === "single" ? `It is implemented on branch \`${ctx.branch}\` (base \`${ctx.baseBranch}\`) in this git worktree.` : `It is a PRD epic implemented one story per commit on branch \`${ctx.branch}\` (base \`${ctx.baseBranch}\`) in this git worktree.`,
|
|
3965
4023
|
"",
|
|
3966
4024
|
`## Status: ${done}/${epic.stories.length} stories complete`,
|
|
3967
|
-
formatStoryList(epic)
|
|
4025
|
+
formatStoryList(epic)
|
|
4026
|
+
];
|
|
4027
|
+
const lines = [
|
|
4028
|
+
...intro,
|
|
3968
4029
|
"",
|
|
3969
4030
|
`- Git remote \`origin\`: ${ctx.remoteUrl ? `\`${ctx.remoteUrl}\`` : "none configured"}`,
|
|
3970
4031
|
`- ${capitalize(term)}: ${ctx.prUrl ?? "none opened yet"}`,
|
|
@@ -3980,24 +4041,53 @@ function buildRequestPrompt(ctx) {
|
|
|
3980
4041
|
...ctx.attachments ? [
|
|
3981
4042
|
"",
|
|
3982
4043
|
"## Attachments",
|
|
3983
|
-
|
|
4044
|
+
`Files attached ${chat ? "to the request" : "in Linear"}. Open the ones relevant to the request with the Read tool (it shows images):`,
|
|
3984
4045
|
ctx.attachments
|
|
3985
4046
|
] : [],
|
|
3986
4047
|
"",
|
|
3987
4048
|
REQUEST_HEADING,
|
|
3988
4049
|
...ctx.requests.map((r) => `> ${r.trim().replace(/\n/g, "\n> ")}
|
|
3989
4050
|
`),
|
|
4051
|
+
...ctx.ship ? shipInstructions(ctx, term, gates) : requestInstructions(ctx, term),
|
|
4052
|
+
...ctx.appendInstruction?.trim() ? ["", ctx.appendInstruction.trim()] : []
|
|
4053
|
+
];
|
|
4054
|
+
return lines.join("\n").trim();
|
|
4055
|
+
}
|
|
4056
|
+
function requestInstructions(ctx, term) {
|
|
4057
|
+
const chat = ctx.source === "chat";
|
|
4058
|
+
const thread = chat ? "chat thread" : "Linear thread";
|
|
4059
|
+
return [
|
|
3990
4060
|
"## How to handle it",
|
|
3991
4061
|
"- This is a direct request, not a story. Do what it asks, and nothing beyond it.",
|
|
3992
4062
|
`- You may commit, and push \`${ctx.branch}\` to \`origin\` (\`git push -u origin ${ctx.branch}\`), when the request calls for it. Never push to \`${ctx.baseBranch}\` or any other branch.`,
|
|
3993
4063
|
(ctx.historyRewrite ?? "when-asked") === "when-asked" ? `- History rewrites are allowed on \`${ctx.branch}\` when the request asks for one. For a rebase: \`git fetch origin && git rebase origin/${ctx.baseBranch}\`, resolve conflicts, run the quality gates, then \`git push --force-with-lease origin ${ctx.branch}\`. Do the rebase that was asked for; don't substitute a merge. If the lease is rejected (someone else pushed), stop and report it instead of overwriting their work.` : `- History rewrites (rebase, squash, force-push) are disabled for this repository. If the request asks for one, say so and offer to merge \`${ctx.baseBranch}\` into \`${ctx.branch}\` instead.`,
|
|
3994
|
-
ctx.remoteUrl ? `- For the ${term}, don't run \`gh\` or \`glab\`. Push \`${ctx.branch}\` first, then set \`pullRequest\` in your structured result: \`open\` opens it into \`${ctx.baseBranch}\` as a draft, \`update\` changes the open one's title or description, \`ready\` marks it ready for review. Give \`open\` a title summarising the change itself and a description of the deliverable written for reviewers who can't see Linear: what it does and why, notable changes, and any breaking changes or judgement calls
|
|
4064
|
+
ctx.remoteUrl ? `- For the ${term}, don't run \`gh\` or \`glab\`. Push \`${ctx.branch}\` first, then set \`pullRequest\` in your structured result: \`open\` opens it into \`${ctx.baseBranch}\` as a draft, \`update\` changes the open one's title or description, \`ready\` marks it ready for review. Give \`open\` a title summarising the change itself and a description of the deliverable written for reviewers who can't see ${chat ? "the chat thread" : "Linear"}: what it does and why, notable changes, and any breaking changes or judgement calls.${chat ? "" : " Don't list the user stories."}` : "- There is no `origin` remote yet, so pushing or opening a pull/merge request isn't possible until one is added.",
|
|
3995
4065
|
"- If you change code, run the quality gates and commit with a clear message.",
|
|
3996
4066
|
"- If the request is ambiguous or can't be done (e.g. missing credentials), say exactly what's missing instead of guessing.",
|
|
3997
|
-
`- Finish with a short summary for the
|
|
3998
|
-
|
|
4067
|
+
`- Finish with a short summary for the ${thread} of what you did, including any ${term} URL, as the \`summary\` of your structured result.`
|
|
4068
|
+
];
|
|
4069
|
+
}
|
|
4070
|
+
function shipInstructions(ctx, term, gates) {
|
|
4071
|
+
const stashes = ctx.ship?.stashes ?? [];
|
|
4072
|
+
const chat = ctx.source === "chat";
|
|
4073
|
+
return [
|
|
4074
|
+
"## How to handle it",
|
|
4075
|
+
`This is \`/ship\`: the work on \`${ctx.branch}\` is to be committed, pushed and put up for review. You prepare the commit; the orchestrator makes it with your message, pushes \`${ctx.branch}\` to \`origin\` and makes the ${term} change you ask for. Don't commit or push yourself.`,
|
|
4076
|
+
"",
|
|
4077
|
+
"1. See what the worktree has: `git status` and `git diff` (uncommitted changes), and `git log --oneline origin/" + ctx.branch + "..HEAD` (commits not pushed yet; the ref may not exist if the branch was never pushed).",
|
|
4078
|
+
...stashes.length > 0 ? [
|
|
4079
|
+
"2. Earlier request sessions on this branch left uncommitted work, which was stashed (newest first):",
|
|
4080
|
+
...stashes.map((s) => ` - \`${s.sha}\` (${s.date}): ${s.label}`),
|
|
4081
|
+
" Review each with `git stash show -p --include-untracked <sha>` and bring back what belongs in this commit with `git stash apply <sha>`. Never `pop` or `drop` them: the stash list is shared with other worktrees."
|
|
4082
|
+
] : ["2. No earlier request session left stashed work on this branch."],
|
|
4083
|
+
"3. If the request above says more than `/ship` (notes, a last fix), do that first.",
|
|
4084
|
+
gates.length > 0 ? `4. Run the quality gates (${gates.map((g) => `\`${g}\``).join(", ")}) and fix any failures.` : "4. Check that the change builds and its tests pass, as far as the repository lets you.",
|
|
4085
|
+
"5. Leave in the worktree only what belongs in the commit: everything left (including untracked files) is committed with `git add -A`. Delete scratch files; add generated ones to `.gitignore`.",
|
|
4086
|
+
"6. Report `commit.message` in your structured result: a one-line subject, a blank line, and a short body saying what changed and why. Leave `commit` out when there's nothing to commit (the orchestrator still pushes commits that aren't on `origin` yet).",
|
|
4087
|
+
ctx.prUrl ? `7. The ${term} is open (${ctx.prUrl}). If its title or description no longer match the branch, set \`pullRequest\` to \`update\` with a new title and description; otherwise leave \`pullRequest\` out.` : `7. No ${term} is open yet: set \`pullRequest\` to \`open\` with a title summarising the change itself and a description written for reviewers who can't see ${chat ? "the chat thread" : "Linear"} (what it does and why, notable changes, breaking changes or judgement calls).${chat ? "" : " Don't list the user stories."}`,
|
|
4088
|
+
"- If something stops you (failing gates you can't fix, a conflict, missing credentials), leave `commit` out and say exactly what's wrong in `summary`: nothing is committed or pushed then.",
|
|
4089
|
+
`- \`summary\` is posted to the ${chat ? "chat" : "Linear"} thread: say what is being committed and pushed, in a sentence or two.`
|
|
3999
4090
|
];
|
|
4000
|
-
return lines.join("\n").trim();
|
|
4001
4091
|
}
|
|
4002
4092
|
|
|
4003
4093
|
// ../../packages/ralph/src/replies.ts
|
|
@@ -4237,6 +4327,7 @@ var BACKGROUND_WAIT_TIMEOUT_MS = 60 * 6e4;
|
|
|
4237
4327
|
var WAIT_NUDGE_DELAY_MS = 3e4;
|
|
4238
4328
|
var WAIT_NUDGE_TEXT = "Nothing is running in the background any more, so there is nothing left to wait for. Check the results of the background work you started, finish the task, and report your structured result.";
|
|
4239
4329
|
var RATE_LIMIT_TEXT2 = /rate[_ ]limit|usage limit|\b429\b|too many requests/i;
|
|
4330
|
+
var PERMISSION_DENIED_TEXT = "A person had to approve this in Linear (the repository's Claude Code settings ask about it) and denied it or didn't answer in time. Don't retry it: carry on without it, or report what it blocks.";
|
|
4240
4331
|
function retryAfter2(resetsAt) {
|
|
4241
4332
|
if (resetsAt === void 0) return void 0;
|
|
4242
4333
|
const ms = resetsAt < 1e12 ? resetsAt * 1e3 : resetsAt;
|
|
@@ -4252,7 +4343,7 @@ function resultUsage(message) {
|
|
|
4252
4343
|
{ inputTokens: 0, outputTokens: 0 }
|
|
4253
4344
|
);
|
|
4254
4345
|
}
|
|
4255
|
-
function sessionOptions(request, abortController) {
|
|
4346
|
+
function sessionOptions(request, abortController, canUseTool) {
|
|
4256
4347
|
return {
|
|
4257
4348
|
...narrowPermissions(
|
|
4258
4349
|
sdkPermissions(request.policy)({ cwd: request.cwd, allowExploration: true }),
|
|
@@ -4266,7 +4357,8 @@ function sessionOptions(request, abortController) {
|
|
|
4266
4357
|
...request.additionalDirectories?.length ? { additionalDirectories: request.additionalDirectories } : {},
|
|
4267
4358
|
persistSession: request.persistSession === true,
|
|
4268
4359
|
...request.resume && { resume: request.resume },
|
|
4269
|
-
env: { ...request.env, CLAUDE_AGENT_SDK_CLIENT_APP: "omniralph-agent" }
|
|
4360
|
+
env: { ...request.env, CLAUDE_AGENT_SDK_CLIENT_APP: "omniralph-agent" },
|
|
4361
|
+
...canUseTool && { canUseTool }
|
|
4270
4362
|
};
|
|
4271
4363
|
}
|
|
4272
4364
|
var InputQueue = class {
|
|
@@ -4339,8 +4431,10 @@ async function runQuery(query, request, seen) {
|
|
|
4339
4431
|
let idleTimer;
|
|
4340
4432
|
const idleTimeoutMs = request.idleTimeoutMs ?? SESSION_IDLE_TIMEOUT_MS;
|
|
4341
4433
|
const injectionIdleTimeoutMs = request.injectionIdleTimeoutMs ?? INJECTION_IDLE_TIMEOUT_MS;
|
|
4434
|
+
let asking = 0;
|
|
4342
4435
|
const resetIdle = () => {
|
|
4343
4436
|
clearTimeout(idleTimer);
|
|
4437
|
+
if (asking > 0) return;
|
|
4344
4438
|
idleTimer = setTimeout(() => {
|
|
4345
4439
|
idle = true;
|
|
4346
4440
|
controller.abort(new Error("the session was idle"));
|
|
@@ -4427,9 +4521,35 @@ async function runQuery(query, request, seen) {
|
|
|
4427
4521
|
}
|
|
4428
4522
|
return void 0;
|
|
4429
4523
|
};
|
|
4524
|
+
const askPermission = request.askPermission;
|
|
4525
|
+
const canUseTool = askPermission ? async (toolName, toolInput, options) => {
|
|
4526
|
+
asking++;
|
|
4527
|
+
clearTimeout(idleTimer);
|
|
4528
|
+
let allowed = false;
|
|
4529
|
+
try {
|
|
4530
|
+
const rule = options.matchedAskRule;
|
|
4531
|
+
const reason = [
|
|
4532
|
+
options.title ?? options.decisionReason,
|
|
4533
|
+
rule && `It matches \`${rule.toolName}${rule.ruleContent ? `(${rule.ruleContent})` : ""}\` in the ${rule.source} settings.`
|
|
4534
|
+
].filter(Boolean).join("\n");
|
|
4535
|
+
allowed = await askPermission(
|
|
4536
|
+
{ tool: toolName, input: toolInput, ...reason && { reason } },
|
|
4537
|
+
options.signal
|
|
4538
|
+
);
|
|
4539
|
+
} catch {
|
|
4540
|
+
allowed = false;
|
|
4541
|
+
} finally {
|
|
4542
|
+
asking--;
|
|
4543
|
+
if (!waiting) resetIdle();
|
|
4544
|
+
}
|
|
4545
|
+
return allowed ? { behavior: "allow", updatedInput: toolInput } : { behavior: "deny", message: PERMISSION_DENIED_TEXT };
|
|
4546
|
+
} : void 0;
|
|
4430
4547
|
resetIdle();
|
|
4431
4548
|
try {
|
|
4432
|
-
const messages = query({
|
|
4549
|
+
const messages = query({
|
|
4550
|
+
prompt: input,
|
|
4551
|
+
options: sessionOptions(request, controller, canUseTool)
|
|
4552
|
+
});
|
|
4433
4553
|
for await (const message of messages) {
|
|
4434
4554
|
if (message.type === "system" && message.subtype === "background_tasks_changed") {
|
|
4435
4555
|
live.clear();
|
|
@@ -5459,6 +5579,122 @@ async function currentHead(worktree, before) {
|
|
|
5459
5579
|
import { mkdtemp as mkdtemp3, rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
|
|
5460
5580
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
5461
5581
|
import path4 from "node:path";
|
|
5582
|
+
|
|
5583
|
+
// src/capabilities/ralph/permissions.ts
|
|
5584
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
5585
|
+
import { z as z13 } from "zod";
|
|
5586
|
+
var PERMISSION_TIMEOUT_MS = 30 * 6e4;
|
|
5587
|
+
var PERMISSION_POLL_INTERVAL_MS = 5e3;
|
|
5588
|
+
var REQUEST_TIMEOUT_MS2 = 3e4;
|
|
5589
|
+
function sleep(ms, signal) {
|
|
5590
|
+
return new Promise((resolve2, reject) => {
|
|
5591
|
+
if (signal.aborted) {
|
|
5592
|
+
reject(signal.reason);
|
|
5593
|
+
return;
|
|
5594
|
+
}
|
|
5595
|
+
const onAbort = () => {
|
|
5596
|
+
clearTimeout(timer);
|
|
5597
|
+
reject(signal.reason);
|
|
5598
|
+
};
|
|
5599
|
+
const timer = setTimeout(() => {
|
|
5600
|
+
signal.removeEventListener("abort", onAbort);
|
|
5601
|
+
resolve2();
|
|
5602
|
+
}, ms);
|
|
5603
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5604
|
+
});
|
|
5605
|
+
}
|
|
5606
|
+
var PermissionRelay = class {
|
|
5607
|
+
constructor(options) {
|
|
5608
|
+
this.options = options;
|
|
5609
|
+
this.base = `${options.server}/api/agent/jobs/${encodeURIComponent(options.jobId)}/permissions`;
|
|
5610
|
+
}
|
|
5611
|
+
options;
|
|
5612
|
+
chain = Promise.resolve();
|
|
5613
|
+
base;
|
|
5614
|
+
/** Whether the call may run. */
|
|
5615
|
+
ask(call, signal) {
|
|
5616
|
+
const turn = this.chain.then(() => this.askNow(call, signal));
|
|
5617
|
+
this.chain = turn.catch(() => {
|
|
5618
|
+
});
|
|
5619
|
+
return turn;
|
|
5620
|
+
}
|
|
5621
|
+
async askNow(call, signal) {
|
|
5622
|
+
if (signal.aborted) return false;
|
|
5623
|
+
const log = this.options.logger.child({ tool: call.tool });
|
|
5624
|
+
const requestId = randomUUID2();
|
|
5625
|
+
const timeoutMs = this.options.timeoutMs ?? PERMISSION_TIMEOUT_MS;
|
|
5626
|
+
try {
|
|
5627
|
+
await postJson(
|
|
5628
|
+
this.options.fetch ?? fetch,
|
|
5629
|
+
this.base,
|
|
5630
|
+
{
|
|
5631
|
+
requestId,
|
|
5632
|
+
tool: call.tool,
|
|
5633
|
+
detail: toolParameter(call.input),
|
|
5634
|
+
...call.reason && { reason: call.reason.slice(0, 1e3) },
|
|
5635
|
+
timeoutSeconds: Math.max(1, Math.ceil(timeoutMs / 1e3))
|
|
5636
|
+
},
|
|
5637
|
+
z13.unknown(),
|
|
5638
|
+
this.options.jobToken()
|
|
5639
|
+
);
|
|
5640
|
+
} catch (error) {
|
|
5641
|
+
log.warn({ err: error }, "asking for a tool permission failed; denying the call");
|
|
5642
|
+
return false;
|
|
5643
|
+
}
|
|
5644
|
+
log.info({ requestId }, "asked for a tool permission in Linear");
|
|
5645
|
+
const deadline = Date.now() + timeoutMs;
|
|
5646
|
+
const interval = this.options.pollIntervalMs ?? PERMISSION_POLL_INTERVAL_MS;
|
|
5647
|
+
let failures = 0;
|
|
5648
|
+
try {
|
|
5649
|
+
while (Date.now() < deadline) {
|
|
5650
|
+
await sleep(Math.min(interval, Math.max(0, deadline - Date.now())), signal);
|
|
5651
|
+
let answer;
|
|
5652
|
+
try {
|
|
5653
|
+
answer = await this.read(requestId);
|
|
5654
|
+
failures = 0;
|
|
5655
|
+
} catch (error) {
|
|
5656
|
+
if (++failures >= 10) throw error;
|
|
5657
|
+
continue;
|
|
5658
|
+
}
|
|
5659
|
+
if (answer.status === "pending") continue;
|
|
5660
|
+
log.info({ requestId, status: answer.status }, "tool permission answered");
|
|
5661
|
+
return answer.status === "allowed";
|
|
5662
|
+
}
|
|
5663
|
+
log.info({ requestId }, "nobody answered the tool permission in time; denying the call");
|
|
5664
|
+
} catch (error) {
|
|
5665
|
+
if (!signal.aborted) log.warn({ err: error }, "reading a tool permission failed; denying it");
|
|
5666
|
+
}
|
|
5667
|
+
await this.close(requestId, log);
|
|
5668
|
+
return false;
|
|
5669
|
+
}
|
|
5670
|
+
async read(requestId) {
|
|
5671
|
+
const res = await (this.options.fetch ?? fetch)(
|
|
5672
|
+
`${this.base}/${encodeURIComponent(requestId)}`,
|
|
5673
|
+
{
|
|
5674
|
+
headers: { authorization: `Bearer ${this.options.jobToken()}` },
|
|
5675
|
+
redirect: "error",
|
|
5676
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
5677
|
+
}
|
|
5678
|
+
);
|
|
5679
|
+
if (!res.ok) throw new Error(`reading the permission answer failed with ${res.status}`);
|
|
5680
|
+
return RalphPermissionAnswer.parse(await res.json());
|
|
5681
|
+
}
|
|
5682
|
+
/** Closes the question (best effort), so a late answer isn't taken for a live one. */
|
|
5683
|
+
async close(requestId, log) {
|
|
5684
|
+
try {
|
|
5685
|
+
await (this.options.fetch ?? fetch)(`${this.base}/${encodeURIComponent(requestId)}`, {
|
|
5686
|
+
method: "DELETE",
|
|
5687
|
+
headers: { authorization: `Bearer ${this.options.jobToken()}` },
|
|
5688
|
+
redirect: "error",
|
|
5689
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
5690
|
+
});
|
|
5691
|
+
} catch (error) {
|
|
5692
|
+
log.warn({ err: error }, "closing a tool permission question failed");
|
|
5693
|
+
}
|
|
5694
|
+
}
|
|
5695
|
+
};
|
|
5696
|
+
|
|
5697
|
+
// src/capabilities/ralph/request.ts
|
|
5462
5698
|
var MAX_TEXT2 = 2e4;
|
|
5463
5699
|
function tail4(text, max) {
|
|
5464
5700
|
const trimmed = text.trim();
|
|
@@ -5516,6 +5752,19 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5516
5752
|
logger: log,
|
|
5517
5753
|
...options.fetch && { fetch: options.fetch }
|
|
5518
5754
|
});
|
|
5755
|
+
const permissions = new PermissionRelay({
|
|
5756
|
+
server: ctx.server,
|
|
5757
|
+
jobId: job.id,
|
|
5758
|
+
jobToken: ctx.jobToken,
|
|
5759
|
+
logger: log,
|
|
5760
|
+
...options.fetch && { fetch: options.fetch },
|
|
5761
|
+
...options.permissionTimeoutMs !== void 0 && {
|
|
5762
|
+
timeoutMs: options.permissionTimeoutMs
|
|
5763
|
+
},
|
|
5764
|
+
...options.permissionPollIntervalMs !== void 0 && {
|
|
5765
|
+
pollIntervalMs: options.permissionPollIntervalMs
|
|
5766
|
+
}
|
|
5767
|
+
});
|
|
5519
5768
|
const runSession = options.runSession ?? createSessionRunner();
|
|
5520
5769
|
const env = ctx.env();
|
|
5521
5770
|
const git2 = await sessionGitAccess(ctx);
|
|
@@ -5531,7 +5780,7 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5531
5780
|
signal: ctx.signal
|
|
5532
5781
|
},
|
|
5533
5782
|
async (worktree) => {
|
|
5534
|
-
const leftover = await worktree.stashWork(label("pre-run"));
|
|
5783
|
+
const leftover = payload.ship ? null : await worktree.stashWork(label("pre-run"));
|
|
5535
5784
|
if (leftover) {
|
|
5536
5785
|
log.info({ stash: leftover }, "stashed leftover work");
|
|
5537
5786
|
relay.post({
|
|
@@ -5558,9 +5807,11 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5558
5807
|
const progressFile = path4.join(progressDir, "progress.md");
|
|
5559
5808
|
try {
|
|
5560
5809
|
await writeFile4(progressFile, payload.progress);
|
|
5810
|
+
const shipStashes = payload.ship ? await requestStashes(worktree, payload) : [];
|
|
5561
5811
|
const prompt = buildRequestPrompt({
|
|
5562
5812
|
epic: requestEpic(payload),
|
|
5563
5813
|
requests: payload.requests.map((r) => r.text),
|
|
5814
|
+
source: payload.source,
|
|
5564
5815
|
branch: payload.branch,
|
|
5565
5816
|
baseBranch: payload.baseBranch,
|
|
5566
5817
|
remoteUrl: payload.repository.cloneUrl,
|
|
@@ -5572,13 +5823,16 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5572
5823
|
...attachments.prompt && { attachments: attachments.prompt },
|
|
5573
5824
|
...payload.settings.appendInstruction && {
|
|
5574
5825
|
appendInstruction: payload.settings.appendInstruction
|
|
5575
|
-
}
|
|
5826
|
+
},
|
|
5827
|
+
...payload.ship && { ship: { stashes: shipStashes } }
|
|
5576
5828
|
});
|
|
5577
5829
|
const request = {
|
|
5578
5830
|
prompt,
|
|
5579
5831
|
cwd: worktree.path,
|
|
5580
5832
|
policy: RALPH_TOOL_POLICY,
|
|
5581
|
-
systemAppend: requestSystemAppend(payload.historyRewrite
|
|
5833
|
+
systemAppend: requestSystemAppend(payload.historyRewrite, payload.source, {
|
|
5834
|
+
ship: payload.ship
|
|
5835
|
+
}),
|
|
5582
5836
|
outputSchema: REQUEST_OUTPUT_SCHEMA,
|
|
5583
5837
|
isWaiting: isWaitingRequest,
|
|
5584
5838
|
model: payload.settings.model ?? DEFAULT_STORY_MODEL,
|
|
@@ -5600,7 +5854,9 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5600
5854
|
// Replies from the Linear thread reach the live session (see `jobMessages`).
|
|
5601
5855
|
onInjector: (inject) => ctx.setMessageInjector?.(inject),
|
|
5602
5856
|
// Follow-ups continue this conversation, like Cyrus resuming its Claude session.
|
|
5603
|
-
persistSession: true
|
|
5857
|
+
persistSession: true,
|
|
5858
|
+
// The repository's Claude Code settings may `ask` about calls (e.g. `git commit`).
|
|
5859
|
+
askPermission: (call, signal) => permissions.ask(call, signal)
|
|
5604
5860
|
};
|
|
5605
5861
|
const resume = payload.resumeSessionId ?? void 0;
|
|
5606
5862
|
let session = await runSession({ ...request, ...resume && { resume } });
|
|
@@ -5620,15 +5876,22 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5620
5876
|
Math.min(Math.max(seconds, 1), MAX_LEASE_SECONDS)
|
|
5621
5877
|
);
|
|
5622
5878
|
}
|
|
5623
|
-
const stashSha = await stashQuietly2(worktree, label("unfinished"), log);
|
|
5624
5879
|
const read = session.stop === "completed" ? readRequestResult(session.structured) : void 0;
|
|
5880
|
+
const stoppedWaiting = session.stop === "completed" && isWaitingRequest(session.structured);
|
|
5881
|
+
const valid = read && !("problem" in read) && !stoppedWaiting ? read.result : void 0;
|
|
5882
|
+
const shipped = payload.ship && valid ? await ship(worktree, payload, valid, log) : void 0;
|
|
5883
|
+
const stashSha = await stashQuietly2(worktree, label("unfinished"), log);
|
|
5625
5884
|
const base = {
|
|
5626
5885
|
sessionId: session.sessionId ?? null,
|
|
5627
5886
|
...stashSha && { stashSha },
|
|
5887
|
+
...shipped?.commitSha && { commitSha: shipped.commitSha },
|
|
5888
|
+
...shipped && { pushed: shipped.pushed },
|
|
5628
5889
|
usage: session.usage,
|
|
5629
5890
|
durationMs: Date.now() - started
|
|
5630
5891
|
};
|
|
5631
|
-
|
|
5892
|
+
if (shipped?.error) {
|
|
5893
|
+
return { ...base, summary: clip3(valid?.summary ?? ""), error: clip3(shipped.error) };
|
|
5894
|
+
}
|
|
5632
5895
|
if (!read || "problem" in read || stoppedWaiting) {
|
|
5633
5896
|
const why = stoppedWaiting ? `the session was stopped while it waited for background work: ${session.error ?? "it gave up waiting"}` : read && "problem" in read ? `it ended without a valid structured result (${read.problem})` : sessionError(session);
|
|
5634
5897
|
return {
|
|
@@ -5644,19 +5907,16 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5644
5907
|
},
|
|
5645
5908
|
"request done"
|
|
5646
5909
|
);
|
|
5910
|
+
const pullRequest = read.result.pullRequest ?? shipped?.pullRequest;
|
|
5647
5911
|
return {
|
|
5648
5912
|
...base,
|
|
5649
5913
|
summary: clip3(read.result.summary),
|
|
5650
5914
|
error: null,
|
|
5651
|
-
...
|
|
5915
|
+
...pullRequest && {
|
|
5652
5916
|
pullRequest: {
|
|
5653
|
-
action:
|
|
5654
|
-
...
|
|
5655
|
-
|
|
5656
|
-
},
|
|
5657
|
-
...read.result.pullRequest.body && {
|
|
5658
|
-
body: clip3(read.result.pullRequest.body, 6e4)
|
|
5659
|
-
}
|
|
5917
|
+
action: pullRequest.action,
|
|
5918
|
+
...pullRequest.title && { title: clip3(pullRequest.title, 500) },
|
|
5919
|
+
...pullRequest.body && { body: clip3(pullRequest.body, 6e4) }
|
|
5660
5920
|
}
|
|
5661
5921
|
},
|
|
5662
5922
|
...read.result.findings && {
|
|
@@ -5680,6 +5940,111 @@ async function runRequest(job, ctx, options = {}) {
|
|
|
5680
5940
|
await relay.flush();
|
|
5681
5941
|
}
|
|
5682
5942
|
}
|
|
5943
|
+
async function requestStashes(worktree, payload) {
|
|
5944
|
+
const prefix = requestStashPrefix(payload);
|
|
5945
|
+
const entries = await worktree.listStashes();
|
|
5946
|
+
return entries.filter((e) => e.label.startsWith(prefix)).slice(0, 20).map((e) => ({ sha: e.sha, label: e.label, date: e.date }));
|
|
5947
|
+
}
|
|
5948
|
+
var FALLBACK_IDENTITY2 = ["-c", "user.name=Omniralph", "-c", "user.email=omniralph@localhost"];
|
|
5949
|
+
async function ship(worktree, payload, result, log) {
|
|
5950
|
+
const state = {};
|
|
5951
|
+
try {
|
|
5952
|
+
return await shipSteps(worktree, payload, result, log, state);
|
|
5953
|
+
} catch (error) {
|
|
5954
|
+
log.warn({ err: error }, "shipping failed");
|
|
5955
|
+
if (state.unpushedCommit) {
|
|
5956
|
+
await worktree.git(["reset", "--quiet", "HEAD~1"]).catch(() => {
|
|
5957
|
+
});
|
|
5958
|
+
}
|
|
5959
|
+
return {
|
|
5960
|
+
pushed: false,
|
|
5961
|
+
error: `shipping failed${state.unpushedCommit ? " (the commit was undone)" : ""}:
|
|
5962
|
+
|
|
5963
|
+
\`\`\`
|
|
5964
|
+
${tail4(errorText3(error), 4e3)}
|
|
5965
|
+
\`\`\``
|
|
5966
|
+
};
|
|
5967
|
+
}
|
|
5968
|
+
}
|
|
5969
|
+
async function shipSteps(worktree, payload, result, log, state) {
|
|
5970
|
+
const git2 = (args) => worktree.git(args);
|
|
5971
|
+
const tryGit = (args) => git2(args).then(
|
|
5972
|
+
(out) => out.trim(),
|
|
5973
|
+
() => null
|
|
5974
|
+
);
|
|
5975
|
+
const remoteHead = () => tryGit(["rev-parse", "--verify", "--quiet", `refs/remotes/origin/${payload.branch}`]);
|
|
5976
|
+
let commitSha;
|
|
5977
|
+
await git2(["add", "-A"]);
|
|
5978
|
+
const staged = (await git2(["diff", "--cached", "--name-only"])).trim();
|
|
5979
|
+
if (staged) {
|
|
5980
|
+
const message = result.commit?.message;
|
|
5981
|
+
if (!message) {
|
|
5982
|
+
await git2(["reset", "--quiet"]);
|
|
5983
|
+
return {
|
|
5984
|
+
pushed: false,
|
|
5985
|
+
error: "the session left uncommitted changes but no commit message, so nothing was committed or pushed"
|
|
5986
|
+
};
|
|
5987
|
+
}
|
|
5988
|
+
const identity = await tryGit(["config", "--get", "user.email"]) ? [] : FALLBACK_IDENTITY2;
|
|
5989
|
+
try {
|
|
5990
|
+
await git2([...identity, "commit", "--quiet", "-m", message]);
|
|
5991
|
+
} catch (error) {
|
|
5992
|
+
await git2(["reset", "--quiet"]).catch(() => {
|
|
5993
|
+
});
|
|
5994
|
+
return {
|
|
5995
|
+
pushed: false,
|
|
5996
|
+
error: `committing the work failed (e.g. a git hook rejected it):
|
|
5997
|
+
|
|
5998
|
+
\`\`\`
|
|
5999
|
+
${tail4(errorText3(error), 4e3)}
|
|
6000
|
+
\`\`\``
|
|
6001
|
+
};
|
|
6002
|
+
}
|
|
6003
|
+
state.unpushedCommit = "HEAD";
|
|
6004
|
+
commitSha = (await git2(["rev-parse", "HEAD"])).trim();
|
|
6005
|
+
state.unpushedCommit = commitSha;
|
|
6006
|
+
log.info({ commit: commitSha }, "committed the shipped work");
|
|
6007
|
+
}
|
|
6008
|
+
const head = (await git2(["rev-parse", "HEAD"])).trim();
|
|
6009
|
+
let pushed = false;
|
|
6010
|
+
if (await remoteHead() !== head) {
|
|
6011
|
+
try {
|
|
6012
|
+
await git2(["push", "--quiet", "-u", "origin", payload.branch]);
|
|
6013
|
+
delete state.unpushedCommit;
|
|
6014
|
+
pushed = true;
|
|
6015
|
+
log.info({ head }, "pushed the shipped branch");
|
|
6016
|
+
} catch (error) {
|
|
6017
|
+
if (commitSha) await git2(["reset", "--quiet", "HEAD~1"]).catch(() => {
|
|
6018
|
+
});
|
|
6019
|
+
delete state.unpushedCommit;
|
|
6020
|
+
return {
|
|
6021
|
+
pushed: false,
|
|
6022
|
+
error: `${commitSha ? "the work was committed, but pushing it failed, so the commit was undone" : "pushing the branch failed"}:
|
|
6023
|
+
|
|
6024
|
+
\`\`\`
|
|
6025
|
+
${tail4(errorText3(error), 4e3)}
|
|
6026
|
+
\`\`\``
|
|
6027
|
+
};
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
let pullRequest;
|
|
6031
|
+
if (!payload.prUrl && !result.pullRequest) {
|
|
6032
|
+
const ahead = await tryGit(["rev-list", "--count", `origin/${payload.baseBranch}..HEAD`]);
|
|
6033
|
+
if (ahead !== null && Number(ahead) > 0) {
|
|
6034
|
+
const [subject, ...rest] = (result.commit?.message ?? "").split("\n");
|
|
6035
|
+
const body = rest.join("\n").trim();
|
|
6036
|
+
pullRequest = {
|
|
6037
|
+
action: "open",
|
|
6038
|
+
...subject?.trim() && { title: subject.trim() },
|
|
6039
|
+
...body && { body }
|
|
6040
|
+
};
|
|
6041
|
+
}
|
|
6042
|
+
}
|
|
6043
|
+
return { ...commitSha && { commitSha }, pushed, ...pullRequest && { pullRequest } };
|
|
6044
|
+
}
|
|
6045
|
+
function errorText3(error) {
|
|
6046
|
+
return error instanceof Error ? error.message : String(error);
|
|
6047
|
+
}
|
|
5683
6048
|
async function stashQuietly2(worktree, label, log) {
|
|
5684
6049
|
try {
|
|
5685
6050
|
const sha = await worktree.stashWork(label, { signal: null });
|
|
@@ -6059,13 +6424,13 @@ import { randomBytes } from "node:crypto";
|
|
|
6059
6424
|
import { mkdir as mkdir2, open, readFile as readFile3, rename as rename2, rm as rm6, stat } from "node:fs/promises";
|
|
6060
6425
|
import { homedir } from "node:os";
|
|
6061
6426
|
import path7 from "node:path";
|
|
6062
|
-
import { z as
|
|
6063
|
-
var AgentConfig =
|
|
6064
|
-
server:
|
|
6065
|
-
agentId:
|
|
6427
|
+
import { z as z14 } from "zod";
|
|
6428
|
+
var AgentConfig = z14.object({
|
|
6429
|
+
server: z14.string(),
|
|
6430
|
+
agentId: z14.string(),
|
|
6066
6431
|
/** Rotated on every `/api/agent/token` call; reusing an old one revokes the agent. */
|
|
6067
|
-
refreshToken:
|
|
6068
|
-
workspaceRoot:
|
|
6432
|
+
refreshToken: z14.string(),
|
|
6433
|
+
workspaceRoot: z14.string()
|
|
6069
6434
|
});
|
|
6070
6435
|
function defaultConfigPath() {
|
|
6071
6436
|
return path7.join(homedir(), ".config", "omniralph", "agent.json");
|
|
@@ -6152,7 +6517,7 @@ async function writePrivateJson(file, value) {
|
|
|
6152
6517
|
}
|
|
6153
6518
|
|
|
6154
6519
|
// src/workspace/repoCache.ts
|
|
6155
|
-
import { randomUUID as
|
|
6520
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
6156
6521
|
import {
|
|
6157
6522
|
chmod,
|
|
6158
6523
|
mkdir as mkdir3,
|
|
@@ -6192,7 +6557,7 @@ exit $status
|
|
|
6192
6557
|
`;
|
|
6193
6558
|
var SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
6194
6559
|
var JOB_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
6195
|
-
var
|
|
6560
|
+
var FALLBACK_IDENTITY3 = ["-c", "user.name=Omniralph", "-c", "user.email=omniralph@localhost"];
|
|
6196
6561
|
var BranchDivergedError = class extends Error {
|
|
6197
6562
|
constructor(branch, ahead, behind) {
|
|
6198
6563
|
super(
|
|
@@ -6439,10 +6804,10 @@ var RepoCache = class {
|
|
|
6439
6804
|
);
|
|
6440
6805
|
let tip = existing;
|
|
6441
6806
|
const identity = await git2(["config", "--get", "user.email"]).then(
|
|
6442
|
-
(email) => email ? [] :
|
|
6443
|
-
() =>
|
|
6807
|
+
(email) => email ? [] : FALLBACK_IDENTITY3,
|
|
6808
|
+
() => FALLBACK_IDENTITY3
|
|
6444
6809
|
);
|
|
6445
|
-
const index = path8.join(this.workspaceRoot, TMP_DIR, `stash-index-${
|
|
6810
|
+
const index = path8.join(this.workspaceRoot, TMP_DIR, `stash-index-${randomUUID3()}`);
|
|
6446
6811
|
await mkdir3(path8.dirname(index), { recursive: true });
|
|
6447
6812
|
try {
|
|
6448
6813
|
for (const entry of [...entries].reverse()) {
|
|
@@ -6911,7 +7276,7 @@ Stash ${entry.sha} from ${entry.date}, made on top of ${base}.`;
|
|
|
6911
7276
|
return { dir, cloned: false, fetched: true };
|
|
6912
7277
|
}
|
|
6913
7278
|
async clone(repo, dir, options) {
|
|
6914
|
-
const tmp = path8.join(this.workspaceRoot, TMP_DIR,
|
|
7279
|
+
const tmp = path8.join(this.workspaceRoot, TMP_DIR, randomUUID3());
|
|
6915
7280
|
await mkdir3(path8.dirname(tmp), { recursive: true });
|
|
6916
7281
|
this.logger?.info({ repo: `${repo.provider}/${repo.fullPath}` }, "cloning repository");
|
|
6917
7282
|
try {
|
|
@@ -7786,10 +8151,10 @@ function createQueueReceiver(server, region, currentToken) {
|
|
|
7786
8151
|
|
|
7787
8152
|
// src/update.ts
|
|
7788
8153
|
import { execFile as execFile2 } from "node:child_process";
|
|
7789
|
-
import { randomUUID as
|
|
8154
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
7790
8155
|
import { readFile as readFile6, rm as rm8 } from "node:fs/promises";
|
|
7791
8156
|
import path9 from "node:path";
|
|
7792
|
-
import { z as
|
|
8157
|
+
import { z as z15 } from "zod";
|
|
7793
8158
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
7794
8159
|
var UPDATE_REQUEST_FILE = "update-request.json";
|
|
7795
8160
|
var MAX_STARTS_SINCE_PENDING = 3;
|
|
@@ -7797,18 +8162,18 @@ var CONFIRM_AFTER_MS = 6e4;
|
|
|
7797
8162
|
var DRAIN_TIMEOUT_MS = 2 * 60 * 60 * 1e3;
|
|
7798
8163
|
var INSTALL_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
7799
8164
|
var FAILED_VERSIONS_KEPT = 100;
|
|
7800
|
-
var UpdateStateFile =
|
|
8165
|
+
var UpdateStateFile = z15.object({
|
|
7801
8166
|
/** The version running before the last update (the rollback target). */
|
|
7802
|
-
previous:
|
|
8167
|
+
previous: z15.string().nullable().default(null),
|
|
7803
8168
|
/** The version installed by the last update, until it's confirmed. */
|
|
7804
|
-
pending:
|
|
8169
|
+
pending: z15.string().nullable().default(null),
|
|
7805
8170
|
/** Starts of `pending` so far. */
|
|
7806
|
-
startsSincePending:
|
|
7807
|
-
failed:
|
|
8171
|
+
startsSincePending: z15.int().min(0).default(0),
|
|
8172
|
+
failed: z15.array(z15.string()).default([]),
|
|
7808
8173
|
/** Why the last update or rollback failed. */
|
|
7809
|
-
lastError:
|
|
8174
|
+
lastError: z15.string().nullable().default(null),
|
|
7810
8175
|
/** The control panel's last `updateRequest` acted on (reported back so it's cleared). */
|
|
7811
|
-
handledRequestId:
|
|
8176
|
+
handledRequestId: z15.string().nullable().default(null)
|
|
7812
8177
|
});
|
|
7813
8178
|
function emptyState() {
|
|
7814
8179
|
return {
|
|
@@ -7826,12 +8191,12 @@ function updateStatePath(configPath) {
|
|
|
7826
8191
|
function updateRequestPath(configPath) {
|
|
7827
8192
|
return path9.join(path9.dirname(configPath), UPDATE_REQUEST_FILE);
|
|
7828
8193
|
}
|
|
7829
|
-
var LocalUpdateRequest =
|
|
7830
|
-
id:
|
|
7831
|
-
requestedAt:
|
|
8194
|
+
var LocalUpdateRequest = z15.object({
|
|
8195
|
+
id: z15.string(),
|
|
8196
|
+
requestedAt: z15.string()
|
|
7832
8197
|
});
|
|
7833
8198
|
async function writeUpdateRequest(file, now = /* @__PURE__ */ new Date()) {
|
|
7834
|
-
const request = { id:
|
|
8199
|
+
const request = { id: randomUUID4(), requestedAt: now.toISOString() };
|
|
7835
8200
|
await writePrivateJson(file, request);
|
|
7836
8201
|
return request;
|
|
7837
8202
|
}
|