@workit-dev/pi 1.6.0 → 1.6.1
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/workit.js +125 -6
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -20586,7 +20586,10 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
|
|
|
20586
20586
|
continue;
|
|
20587
20587
|
const action = rawAction(invocation);
|
|
20588
20588
|
const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
|
|
20589
|
-
repo: {
|
|
20589
|
+
repo: {
|
|
20590
|
+
dir: path27.resolve(cwd, invocation.dir ?? "."),
|
|
20591
|
+
branch: null
|
|
20592
|
+
},
|
|
20590
20593
|
workit: false
|
|
20591
20594
|
} : null);
|
|
20592
20595
|
if (action && at)
|
|
@@ -20633,6 +20636,109 @@ var pkillSelfMatch = (command, dialect) => {
|
|
|
20633
20636
|
}
|
|
20634
20637
|
return null;
|
|
20635
20638
|
};
|
|
20639
|
+
var policyDeclared = () => {
|
|
20640
|
+
try {
|
|
20641
|
+
return !!readConfigTyped().config?.branchPolicy?.protected?.length;
|
|
20642
|
+
} catch {
|
|
20643
|
+
return false;
|
|
20644
|
+
}
|
|
20645
|
+
};
|
|
20646
|
+
var word = (text) => /^[\w./@%+:,=-]+$/u.test(text) ? text : shellQuote(text);
|
|
20647
|
+
var HEREDOC = /^cat <<(['"])(\w+)\1\n([\s\S]*)\n\2\n?$/u;
|
|
20648
|
+
var messageOf = (segment, index) => {
|
|
20649
|
+
const text = segment.words[index];
|
|
20650
|
+
if (text === undefined)
|
|
20651
|
+
return null;
|
|
20652
|
+
if (!segment.expands?.includes(index))
|
|
20653
|
+
return text;
|
|
20654
|
+
const sub = segment.subs?.find((each) => text === `$(${each})`);
|
|
20655
|
+
const match = sub === undefined ? null : HEREDOC.exec(sub);
|
|
20656
|
+
if (!match || match[3].split(`
|
|
20657
|
+
`).includes(match[2]))
|
|
20658
|
+
return null;
|
|
20659
|
+
return match[3].replace(/\n+$/u, "");
|
|
20660
|
+
};
|
|
20661
|
+
var cdCommitCall = (input, command, target, repo) => {
|
|
20662
|
+
const { top, git, dir: store } = repo.location;
|
|
20663
|
+
if (!top || !git || git.gitDir === path27.dirname(store) || repoAt(input.cwd)?.location.top === top)
|
|
20664
|
+
return null;
|
|
20665
|
+
const bare = command.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "").replaceAll("&&", "");
|
|
20666
|
+
if (/[;|&<>`$()\n\\]/u.test(bare))
|
|
20667
|
+
return null;
|
|
20668
|
+
const [cd, ...rest] = segmentsOf(command);
|
|
20669
|
+
const commit = rest.at(-1);
|
|
20670
|
+
if (cd?.words[0] !== "cd" || cd.words.length !== 2 || cd.expands?.length || !commit)
|
|
20671
|
+
return null;
|
|
20672
|
+
if (path27.resolve(input.cwd, cd.words[1]) !== target)
|
|
20673
|
+
return null;
|
|
20674
|
+
if (rest.some((each) => each.redirects.length || each.stdin?.length || each.group))
|
|
20675
|
+
return null;
|
|
20676
|
+
const adds = rest.slice(0, -1);
|
|
20677
|
+
if (!adds.length || commit.words[0] !== "git" || commit.words[1] !== "commit")
|
|
20678
|
+
return null;
|
|
20679
|
+
const paths = [];
|
|
20680
|
+
let all = false;
|
|
20681
|
+
for (const add of adds) {
|
|
20682
|
+
const [tool, verb, ...args] = add.words;
|
|
20683
|
+
if (tool !== "git" || verb !== "add" || add.expands?.length || add.subs?.length)
|
|
20684
|
+
return null;
|
|
20685
|
+
const named = args.filter((arg) => !["-A", "--all", "--"].includes(arg));
|
|
20686
|
+
if (named.some((arg) => arg.startsWith("-") || /[*?[\]]/u.test(arg)))
|
|
20687
|
+
return null;
|
|
20688
|
+
if (!named.length && !args.some((arg) => arg === "-A" || arg === "--all"))
|
|
20689
|
+
return null;
|
|
20690
|
+
if (named.length)
|
|
20691
|
+
paths.push(...named);
|
|
20692
|
+
else
|
|
20693
|
+
all = true;
|
|
20694
|
+
}
|
|
20695
|
+
const messages = [];
|
|
20696
|
+
let allowEmpty = false;
|
|
20697
|
+
for (let index = 2;index < commit.words.length; index++) {
|
|
20698
|
+
const arg = commit.words[index];
|
|
20699
|
+
let message = null;
|
|
20700
|
+
if (arg === "--allow-empty") {
|
|
20701
|
+
allowEmpty = true;
|
|
20702
|
+
continue;
|
|
20703
|
+
}
|
|
20704
|
+
if (arg === "-m" || arg === "--message")
|
|
20705
|
+
message = messageOf(commit, ++index);
|
|
20706
|
+
else if (!commit.expands?.includes(index) && /^(?:-m|--message=)./u.test(arg))
|
|
20707
|
+
message = arg.replace(/^(?:-m|--message=)/u, "");
|
|
20708
|
+
if (!message || message.startsWith("-"))
|
|
20709
|
+
return null;
|
|
20710
|
+
messages.push(message);
|
|
20711
|
+
}
|
|
20712
|
+
if (!messages.length)
|
|
20713
|
+
return null;
|
|
20714
|
+
if (!all) {
|
|
20715
|
+
const staged = spawnSync15("git", ["diff", "--cached", "--quiet"], {
|
|
20716
|
+
cwd: target,
|
|
20717
|
+
timeout: 5000
|
|
20718
|
+
});
|
|
20719
|
+
if (staged.status !== 0)
|
|
20720
|
+
return null;
|
|
20721
|
+
}
|
|
20722
|
+
return [
|
|
20723
|
+
`workit git --cwd ${word(target)} commit`,
|
|
20724
|
+
...messages.map((message) => `-m ${shellQuote(message)}`),
|
|
20725
|
+
...allowEmpty ? ["--allow-empty"] : [],
|
|
20726
|
+
all ? "--all" : `-- ${[...new Set(paths)].map(word).join(" ")}`
|
|
20727
|
+
].join(" ");
|
|
20728
|
+
};
|
|
20729
|
+
var commitRefusal = (input, command, dialect, { action, repo, invocation, workit }) => {
|
|
20730
|
+
if (action.kind !== "commit" || !(workit || policyDeclared()))
|
|
20731
|
+
return null;
|
|
20732
|
+
const switches = workitInvocations(command, dialect).length > 0 || rawInvocations(command, dialect).some((raw) => ["switch", "checkout", "worktree"].includes(raw.args[0] ?? ""));
|
|
20733
|
+
let guarded = false;
|
|
20734
|
+
try {
|
|
20735
|
+
guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
|
|
20736
|
+
} catch {}
|
|
20737
|
+
if (guarded && !switches)
|
|
20738
|
+
return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. Branch first: ${quote("workit git branch --kind feature --slug <slug>")} (uncommitted changes come along), then ${quote("workit git commit -m '<msg>' -- <paths>")}.`;
|
|
20739
|
+
const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path27.resolve(input.cwd, invocation.dir), repo);
|
|
20740
|
+
return call && `workit: no ${quote("cd … &&")} chain; run ${quote(call)}.`;
|
|
20741
|
+
};
|
|
20636
20742
|
function rawGitPre(input, command, options = {}) {
|
|
20637
20743
|
try {
|
|
20638
20744
|
const dialect = dialectOf(input);
|
|
@@ -20648,6 +20754,11 @@ function rawGitPre(input, command, options = {}) {
|
|
|
20648
20754
|
if (refused)
|
|
20649
20755
|
return deny(refused);
|
|
20650
20756
|
}
|
|
20757
|
+
for (const found of located) {
|
|
20758
|
+
const refused = commitRefusal(input, command, dialect, found);
|
|
20759
|
+
if (refused)
|
|
20760
|
+
return deny(refused);
|
|
20761
|
+
}
|
|
20651
20762
|
for (const { action, repo, invocation, workit } of located) {
|
|
20652
20763
|
if (!workit)
|
|
20653
20764
|
continue;
|
|
@@ -28872,7 +28983,11 @@ var usageLimitOnStop = (input, agentId, text) => {
|
|
|
28872
28983
|
return;
|
|
28873
28984
|
if (!firstSighting(`subagent-stop:${input.session.id}:${agentId ?? ""}`))
|
|
28874
28985
|
return;
|
|
28875
|
-
recordUsageLimit(text, {
|
|
28986
|
+
recordUsageLimit(text, {
|
|
28987
|
+
cwd: input.cwd,
|
|
28988
|
+
host: input.host,
|
|
28989
|
+
model: input.model ?? null
|
|
28990
|
+
});
|
|
28876
28991
|
} catch {}
|
|
28877
28992
|
};
|
|
28878
28993
|
var subagentSession = (session, agentId) => [session, agentId].filter((part) => Boolean(part)).join(":").replace(/[^A-Za-z0-9_.:@/+-]/g, "-").slice(0, 128);
|
|
@@ -28968,9 +29083,6 @@ function decide(input, deps) {
|
|
|
28968
29083
|
const postTool = usable2(descriptor.events["shell.post"].support);
|
|
28969
29084
|
if (!postTool)
|
|
28970
29085
|
settlePendingCommit(input);
|
|
28971
|
-
const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
|
|
28972
|
-
if (raw.kind === "deny")
|
|
28973
|
-
return raw;
|
|
28974
29086
|
const userOnly = userOnlyWorkitCall(event.command, event.dialect);
|
|
28975
29087
|
if (userOnly) {
|
|
28976
29088
|
if (input.host === "claude_code")
|
|
@@ -28991,6 +29103,9 @@ function decide(input, deps) {
|
|
|
28991
29103
|
if (confined.kind === "deny")
|
|
28992
29104
|
return confined;
|
|
28993
29105
|
}
|
|
29106
|
+
const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
|
|
29107
|
+
if (raw.kind === "deny")
|
|
29108
|
+
return raw;
|
|
28994
29109
|
const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
|
|
28995
29110
|
const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
|
|
28996
29111
|
if (gate.kind === "deny")
|
|
@@ -29053,7 +29168,11 @@ function decide(input, deps) {
|
|
|
29053
29168
|
trackJudge(input, event.agentId, true);
|
|
29054
29169
|
seedStanding({
|
|
29055
29170
|
...input,
|
|
29056
|
-
session: {
|
|
29171
|
+
session: {
|
|
29172
|
+
...input.session,
|
|
29173
|
+
agentId: event.agentId,
|
|
29174
|
+
agentType: event.agentType
|
|
29175
|
+
}
|
|
29057
29176
|
});
|
|
29058
29177
|
deps.budget?.start(input, event.agentId, event.agentType);
|
|
29059
29178
|
return {
|