@workit-dev/pi 1.3.0 → 1.4.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 +40 -11
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -28149,20 +28149,23 @@ var cwdRewrite = (command) => {
|
|
|
28149
28149
|
const rest = match?.[2];
|
|
28150
28150
|
if (!dir || !rest || dir.startsWith("-"))
|
|
28151
28151
|
return null;
|
|
28152
|
-
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "")))
|
|
28152
|
+
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "")))
|
|
28153
28153
|
return null;
|
|
28154
28154
|
const segments = segmentsOf(rest);
|
|
28155
28155
|
const [head, ...filters] = segments;
|
|
28156
28156
|
if (!head || head.words[0] !== "workit")
|
|
28157
28157
|
return null;
|
|
28158
|
-
if (head.words.some((w) => w === "--cwd" || w.startsWith("--cwd=")))
|
|
28159
|
-
return null;
|
|
28160
28158
|
if (!segments.every(clean))
|
|
28161
28159
|
return null;
|
|
28162
28160
|
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
28163
28161
|
return null;
|
|
28164
28162
|
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
28165
28163
|
return null;
|
|
28164
|
+
const at = head.words.indexOf("--cwd");
|
|
28165
|
+
if (at >= 0)
|
|
28166
|
+
return head.words[at + 1] === dir.replace(/^(['"])(.*)\1$/u, "$2") ? rest : null;
|
|
28167
|
+
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
28168
|
+
return null;
|
|
28166
28169
|
const args = rest.slice("workit".length).trimStart();
|
|
28167
28170
|
const verb = VERB_FIRST.exec(args);
|
|
28168
28171
|
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
@@ -28180,6 +28183,25 @@ var verbFirst = (command) => {
|
|
|
28180
28183
|
return null;
|
|
28181
28184
|
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
28182
28185
|
};
|
|
28186
|
+
var MUTATING_GIT2 = /^git(?: -\S+| -[Cc] \S+)* (?:commit|push|add|switch|checkout|merge|rebase|reset|cherry-pick|revert|branch .*(?:-[dDmM]|--delete|--move)\b|tag (?!-l\b|--list)|stash(?! (?:list|show)\b))/u;
|
|
28187
|
+
var cdWorkitSplit = (command) => {
|
|
28188
|
+
const match = COMPOUND2.exec(command);
|
|
28189
|
+
const dir = match?.[1];
|
|
28190
|
+
const rest = match?.[2];
|
|
28191
|
+
if (!dir || !rest || cwdRewrite(command) !== null)
|
|
28192
|
+
return null;
|
|
28193
|
+
const whole = segmentsOf(rest);
|
|
28194
|
+
const boundary = (head) => segmentsOf(head).every((s, at) => s.words.join("\x00") === whole[at]?.words.join("\x00"));
|
|
28195
|
+
for (const op of rest.matchAll(/\|\||;/gu)) {
|
|
28196
|
+
const head = rest.slice(0, op.index).trimEnd();
|
|
28197
|
+
const call = cwdRewrite(`cd ${dir} && ${head}`);
|
|
28198
|
+
if (!call || !boundary(head))
|
|
28199
|
+
continue;
|
|
28200
|
+
const next = segmentsOf(rest.slice(op.index + op[0].length))[0];
|
|
28201
|
+
return next && MUTATING_GIT2.test(next.words.join(" ")) ? call : null;
|
|
28202
|
+
}
|
|
28203
|
+
return null;
|
|
28204
|
+
};
|
|
28183
28205
|
|
|
28184
28206
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
28185
28207
|
import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync4, readSync, statSync as statSync4 } from "node:fs";
|
|
@@ -28630,6 +28652,13 @@ function decide(input, deps) {
|
|
|
28630
28652
|
const policy = canDeny ? shellPolicy(input.cwd, event.command, event.dialect) : NONE6;
|
|
28631
28653
|
if (policy.kind !== "none")
|
|
28632
28654
|
return policy;
|
|
28655
|
+
const split = canDeny ? cdWorkitSplit(event.command) : null;
|
|
28656
|
+
if (split)
|
|
28657
|
+
return {
|
|
28658
|
+
kind: "deny",
|
|
28659
|
+
reason: `Run one workit verb per call, with no raw-git fallback: \`${split}\`. If it fails, fix what its error names; do not retry with raw git.`,
|
|
28660
|
+
unblock: null
|
|
28661
|
+
};
|
|
28633
28662
|
const postTool = usable2(descriptor.events["shell.post"].support);
|
|
28634
28663
|
if (!postTool)
|
|
28635
28664
|
settlePendingCommit(input);
|
|
@@ -28891,7 +28920,7 @@ var noteModelSelect = (event, ctx) => {
|
|
|
28891
28920
|
if (next && previous && next !== previous)
|
|
28892
28921
|
switchedSessions.add(ctx.sessionManager.getSessionId());
|
|
28893
28922
|
};
|
|
28894
|
-
var modelSwitchContract = (ctx) => switchedSessions.delete(ctx.sessionManager.getSessionId()) && ctx.isProjectTrusted() ?
|
|
28923
|
+
var modelSwitchContract = (ctx) => switchedSessions.delete(ctx.sessionManager.getSessionId()) && ctx.isProjectTrusted() ? contractBlock(null) : null;
|
|
28895
28924
|
var turnContext = (ctx) => taskTurnContext(ctx);
|
|
28896
28925
|
var turnInput = (ctx) => ({
|
|
28897
28926
|
host: "pi",
|
|
@@ -28919,16 +28948,16 @@ var budgetNotice = (ctx) => {
|
|
|
28919
28948
|
const session = process.env.WORKIT_PI_WORKER_SESSION && process.env.WORKIT_SESSION_ID?.trim() || ctx.sessionManager.getSessionId();
|
|
28920
28949
|
return tickBudget(ctx.cwd, session, null) ? budgetLine(ctx.cwd, session, null) : null;
|
|
28921
28950
|
};
|
|
28951
|
+
var contractBlock = (addendum) => `<workit-contract>
|
|
28952
|
+
${invariantBootstrap()}${addendum ? `
|
|
28953
|
+
${addendum}` : ""}
|
|
28954
|
+
</workit-contract>`;
|
|
28922
28955
|
var workitContext = (ctx, taskContext = taskTurnContext(ctx)) => {
|
|
28923
28956
|
const session = ctx.sessionManager.getSessionId();
|
|
28924
28957
|
if (!ctx.isProjectTrusted())
|
|
28925
|
-
return
|
|
28926
|
-
|
|
28927
|
-
|
|
28928
|
-
return `${invariantBootstrap()}
|
|
28929
|
-
|
|
28930
|
-
Native Pi session: ${session}.${taskContext ? `
|
|
28931
|
-
${taskContext}` : ""}`;
|
|
28958
|
+
return contractBlock(`Native Pi session: ${session}. Project-local Workit state is unavailable until Pi trusts this project.`);
|
|
28959
|
+
return contractBlock(`Native Pi session: ${session}.${taskContext ? `
|
|
28960
|
+
${taskContext}` : ""}`);
|
|
28932
28961
|
};
|
|
28933
28962
|
var unfinishedTaskOffer2 = (ctx) => {
|
|
28934
28963
|
if (!ctx.isProjectTrusted() || process.env.WORKIT_PI_WORKER_ID)
|