@workit-dev/pi 1.8.2 → 1.9.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/workit.js +311 -1
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -29361,6 +29361,313 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
|
|
|
29361
29361
|
return agentModelDecision(cwd, checked.input, { change: checked.change, permissionMode });
|
|
29362
29362
|
};
|
|
29363
29363
|
|
|
29364
|
+
// packages/workit-core/src/hooks/ytrack-word.ts
|
|
29365
|
+
var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
|
|
29366
|
+
var namesYtrack = (text) => {
|
|
29367
|
+
const bare = text.replace(/['"\\]/g, "");
|
|
29368
|
+
return YTRACK_WORD.test(bare) || YTRACK_WORD.test(bare.replace(/`/g, ""));
|
|
29369
|
+
};
|
|
29370
|
+
|
|
29371
|
+
// packages/workit-core/src/hooks/ytrack-guard.ts
|
|
29372
|
+
var name2 = (word = "") => (word.split(/[\\/]/).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd)$|@.*$/g, "");
|
|
29373
|
+
var quote2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
29374
|
+
var minutesOf = (text = "") => {
|
|
29375
|
+
if (/^\d+$/.test(text.trim()))
|
|
29376
|
+
return Number(text) > 0 ? Number(text) : null;
|
|
29377
|
+
let total = 0;
|
|
29378
|
+
const rest = text.replace(/(\d+(?:\.\d+)?)\s*(h|hours?|m|mins?|minutes?)(?![a-z])/gi, (_, n, unit) => {
|
|
29379
|
+
total += Number(n) * (/^h/i.test(unit) ? 60 : 1);
|
|
29380
|
+
return "";
|
|
29381
|
+
});
|
|
29382
|
+
return rest.trim() || !Number.isInteger(total) || total <= 0 ? null : total;
|
|
29383
|
+
};
|
|
29384
|
+
var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
|
|
29385
|
+
var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
|
|
29386
|
+
var standsAlone = (args, at) => {
|
|
29387
|
+
const before = args[at - 1] ?? "";
|
|
29388
|
+
const end = args.indexOf("--");
|
|
29389
|
+
return (end < 0 || at < end) && (!before.startsWith("-") || before.includes("=") || BARE.has(before));
|
|
29390
|
+
};
|
|
29391
|
+
var flagged = (args, flag) => args.some((arg, at) => flag.test(arg) && standsAlone(args, at));
|
|
29392
|
+
var asksHelp2 = (args) => flagged(args, /^(?:--help|-h)$/);
|
|
29393
|
+
var GROUPS = {
|
|
29394
|
+
issue: "issue",
|
|
29395
|
+
"work-item": "work-item",
|
|
29396
|
+
workitem: "work-item",
|
|
29397
|
+
api: "api"
|
|
29398
|
+
};
|
|
29399
|
+
var ASKS = /^(?:post|put|patch|delete)$/i;
|
|
29400
|
+
var BODY = /^(?:-[fF]|--(?:field|raw-field|input))(?:=|$)|^-[fF]./;
|
|
29401
|
+
var QUIET = /^--(?:debug|no-color|json|jq)$/;
|
|
29402
|
+
var CARRIES = {
|
|
29403
|
+
note: { "--body": "body", "-b": "body", "--body-file": "file" },
|
|
29404
|
+
time: { "--duration": "duration", "--text": "text", "--date": "date" },
|
|
29405
|
+
create: {
|
|
29406
|
+
"--project": "project",
|
|
29407
|
+
"-p": "project",
|
|
29408
|
+
"--summary": "summary",
|
|
29409
|
+
"-s": "summary",
|
|
29410
|
+
"--description": "description",
|
|
29411
|
+
"--description-file": "file"
|
|
29412
|
+
}
|
|
29413
|
+
};
|
|
29414
|
+
var gap = (part) => ({ workit: null, gap: part });
|
|
29415
|
+
var pair = (flag, value) => value.startsWith("-") ? `${flag}=${quote2(value)}` : `${flag} ${quote2(value)}`;
|
|
29416
|
+
var mapWrite = (verb, args) => {
|
|
29417
|
+
const values = {};
|
|
29418
|
+
const operands = [];
|
|
29419
|
+
for (let at = 0;at < args.length; at++) {
|
|
29420
|
+
const arg = args[at];
|
|
29421
|
+
if (!arg.startsWith("-") || arg === "-") {
|
|
29422
|
+
operands.push(arg);
|
|
29423
|
+
continue;
|
|
29424
|
+
}
|
|
29425
|
+
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
29426
|
+
const flag = eq > 0 ? arg.slice(0, eq) : arg;
|
|
29427
|
+
const value = eq > 0 ? arg.slice(eq + 1) : VALUE.has(flag) ? args[++at] : undefined;
|
|
29428
|
+
if (QUIET.test(flag))
|
|
29429
|
+
continue;
|
|
29430
|
+
const key = CARRIES[verb][flag];
|
|
29431
|
+
if (!key || value === undefined || key in values)
|
|
29432
|
+
return gap(`\`${flag}\``);
|
|
29433
|
+
if (/[$`]|^~/.test(value))
|
|
29434
|
+
return gap(`the value of \`${flag}\`, which the shell expands when it runs`);
|
|
29435
|
+
values[key] = value;
|
|
29436
|
+
}
|
|
29437
|
+
const [issue, ...more] = operands.slice(2);
|
|
29438
|
+
const v = values;
|
|
29439
|
+
if (verb === "create") {
|
|
29440
|
+
if (issue !== undefined)
|
|
29441
|
+
return gap(`the operand \`${issue}\``);
|
|
29442
|
+
if (v.project === undefined || v.summary === undefined)
|
|
29443
|
+
return gap("a missing --project or --summary");
|
|
29444
|
+
if (v.description !== undefined && v.file !== undefined)
|
|
29445
|
+
return gap("both --description and --description-file");
|
|
29446
|
+
if (v.file === "-")
|
|
29447
|
+
return gap("text read from standard input");
|
|
29448
|
+
return {
|
|
29449
|
+
workit: [
|
|
29450
|
+
"workit youtrack create",
|
|
29451
|
+
pair("--project", v.project),
|
|
29452
|
+
pair("--summary", v.summary),
|
|
29453
|
+
v.description === undefined ? "" : pair("--description", v.description),
|
|
29454
|
+
v.file === undefined ? "" : pair("--file", v.file)
|
|
29455
|
+
].filter(Boolean).join(" ")
|
|
29456
|
+
};
|
|
29457
|
+
}
|
|
29458
|
+
if (issue === undefined || more.length || !/^[A-Z]+-\d+$/.test(issue))
|
|
29459
|
+
return gap("the issue, which must be one id like ABC-123");
|
|
29460
|
+
if (verb === "note") {
|
|
29461
|
+
if (v.body === undefined === (v.file === undefined))
|
|
29462
|
+
return gap("a comment that needs exactly one of --body or --body-file");
|
|
29463
|
+
if (v.file === "-")
|
|
29464
|
+
return gap("text read from standard input");
|
|
29465
|
+
if (v.body !== undefined && !v.body.trim())
|
|
29466
|
+
return gap("an empty --body");
|
|
29467
|
+
return {
|
|
29468
|
+
workit: `workit youtrack note ${issue} ${v.body === undefined ? pair("--file", v.file) : pair("--markdown", v.body)}`
|
|
29469
|
+
};
|
|
29470
|
+
}
|
|
29471
|
+
const minutes = minutesOf(v.duration);
|
|
29472
|
+
if (minutes === null)
|
|
29473
|
+
return gap(`\`--duration ${v.duration ?? ""}\`, which is no whole number of minutes`);
|
|
29474
|
+
if (v.date !== undefined && !/^(?:auto|\d{4}-\d{2}-\d{2})$/.test(v.date))
|
|
29475
|
+
return gap(`\`--date ${v.date}\``);
|
|
29476
|
+
return {
|
|
29477
|
+
workit: [
|
|
29478
|
+
`workit youtrack time ${issue} --minutes ${minutes}`,
|
|
29479
|
+
v.text === undefined ? "" : pair("--text", v.text),
|
|
29480
|
+
v.date === undefined ? "" : pair("--date", v.date)
|
|
29481
|
+
].filter(Boolean).join(" ")
|
|
29482
|
+
};
|
|
29483
|
+
};
|
|
29484
|
+
var UNCOVERED = { workit: null, gap: "" };
|
|
29485
|
+
var classify2 = (args) => {
|
|
29486
|
+
if (asksHelp2(args))
|
|
29487
|
+
return null;
|
|
29488
|
+
const lenient = args.filter((arg, at) => !arg.startsWith("-") && !VALUE.has(args[at - 1] ?? ""));
|
|
29489
|
+
const strict = args.filter((arg, at) => !arg.startsWith("-") && standsAlone(args, at));
|
|
29490
|
+
return judge(args, lenient) ?? judge(args, strict);
|
|
29491
|
+
};
|
|
29492
|
+
var judge = (args, words) => {
|
|
29493
|
+
const group = GROUPS[words[0] ?? ""];
|
|
29494
|
+
const verb = words[1] ?? "";
|
|
29495
|
+
if (group === "api") {
|
|
29496
|
+
const methods = args.flatMap((arg, at) => /^(?:-X|--method)$/.test(arg) ? [{ value: args[at + 1] ?? "", alone: standsAlone(args, at) }] : /^(?:-X.|--method=)/.test(arg) ? [{ value: arg.replace(/^(?:-X=?|--method=)/, ""), alone: standsAlone(args, at) }] : []);
|
|
29497
|
+
if (methods.some((method) => ASKS.test(method.value)))
|
|
29498
|
+
return UNCOVERED;
|
|
29499
|
+
if (methods.some((method) => method.alone))
|
|
29500
|
+
return null;
|
|
29501
|
+
return args.some((a) => BODY.test(a)) ? UNCOVERED : null;
|
|
29502
|
+
}
|
|
29503
|
+
if (group === "work-item" && /^(?:add|create)$/.test(verb))
|
|
29504
|
+
return mapWrite("time", args);
|
|
29505
|
+
if (group === "work-item")
|
|
29506
|
+
return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
|
|
29507
|
+
if (group !== "issue")
|
|
29508
|
+
return null;
|
|
29509
|
+
if (verb === "comment")
|
|
29510
|
+
return mapWrite("note", args);
|
|
29511
|
+
if (verb === "create")
|
|
29512
|
+
return mapWrite("create", args);
|
|
29513
|
+
if (verb === "command")
|
|
29514
|
+
return flagged(args, /^--dry-run$/) ? null : UNCOVERED;
|
|
29515
|
+
return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
|
|
29516
|
+
};
|
|
29517
|
+
var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
|
|
29518
|
+
var MAX_DEPTH2 = 4;
|
|
29519
|
+
var READ = new Map;
|
|
29520
|
+
var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wrapper, loop, substitution or script around it can change or repeat it)");
|
|
29521
|
+
var ungrant = (write) => write.workit ? { command: write.command, ...NOT_PLAIN } : write;
|
|
29522
|
+
var ytrackArgs = (line, found, depth, names, plain) => {
|
|
29523
|
+
const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
|
|
29524
|
+
const tail = workitCheckTail(line);
|
|
29525
|
+
if (tail) {
|
|
29526
|
+
inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
|
|
29527
|
+
return true;
|
|
29528
|
+
}
|
|
29529
|
+
const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
|
|
29530
|
+
const script = flag > 0 ? line[flag + 1] : name2(line[0]) === "eval" ? line.slice(1).join(" ") : undefined;
|
|
29531
|
+
if (script !== undefined) {
|
|
29532
|
+
inner(script);
|
|
29533
|
+
return true;
|
|
29534
|
+
}
|
|
29535
|
+
let at = 0;
|
|
29536
|
+
let called = false;
|
|
29537
|
+
const runner = name2(line[0]);
|
|
29538
|
+
if (/^(?:npx|bunx|pnpx)$/.test(runner) || /^(?:p?npm|yarn)$/.test(runner) && /^(?:dlx|exec|x)$/.test(line[1] ?? "")) {
|
|
29539
|
+
at = runner.endsWith("x") ? 1 : 2;
|
|
29540
|
+
for (;line[at]?.startsWith("-"); at++) {
|
|
29541
|
+
if (/^(?:-c|--call)$/.test(line[at])) {
|
|
29542
|
+
inner(line[at + 1] ?? "");
|
|
29543
|
+
called = true;
|
|
29544
|
+
}
|
|
29545
|
+
if (/^(?:-[pc]|--package|--call)$/.test(line[at]))
|
|
29546
|
+
at++;
|
|
29547
|
+
}
|
|
29548
|
+
}
|
|
29549
|
+
const resolved = /^(?:\$\(|`)\s*(?:which|command\s+-v|type\s+-[pP])\s+ytrack\s*[)`]$/.test(line[at] ?? "");
|
|
29550
|
+
const alias = names.get(line[at] ?? "");
|
|
29551
|
+
if (name2(line[at]) !== "ytrack" && !resolved && !alias)
|
|
29552
|
+
return called;
|
|
29553
|
+
const argv = [...alias ?? [], ...line.slice(at + 1)];
|
|
29554
|
+
const write = classify2(argv);
|
|
29555
|
+
if (write) {
|
|
29556
|
+
const one = { command: ["ytrack", ...argv].map(quote2).join(" "), ...write };
|
|
29557
|
+
found.push(plain ? one : ungrant(one));
|
|
29558
|
+
}
|
|
29559
|
+
return true;
|
|
29560
|
+
};
|
|
29561
|
+
var aliases = (command) => {
|
|
29562
|
+
const found = new Map;
|
|
29563
|
+
for (const [, alias, a, b, c] of command.matchAll(/\balias\s+([\w.-]+)=(?:'([^']*)'|"([^"]*)"|([^\s;&|)]+))/g)) {
|
|
29564
|
+
const value = a ?? b ?? c ?? "";
|
|
29565
|
+
if (/^(?:\S*\/)?ytrack(?:\s|$)/.test(value))
|
|
29566
|
+
found.set(alias, value.split(/\s+/).slice(1));
|
|
29567
|
+
}
|
|
29568
|
+
for (const [, a, b, body] of command.matchAll(/(?:\bfunction\s+([\w.-]+)(?:\s*\(\s*\))?|\b([\w.-]+)\s*\(\s*\))\s*\{([^}]*)\}/g))
|
|
29569
|
+
if (/(?:^|[\s;&|])(?:\S*\/)?ytrack\s/.test(body ?? ""))
|
|
29570
|
+
found.set(a ?? b ?? "", []);
|
|
29571
|
+
return found;
|
|
29572
|
+
};
|
|
29573
|
+
var PASS = /^(?:command|exec|nohup|setsid|time|nice|ionice|stdbuf|chronic|unbuffer|timeout)$/;
|
|
29574
|
+
var COMPOUND3 = /^(?:for|select|while|until|repeat|do|done|function|case|foreach|coproc)$/;
|
|
29575
|
+
var passed = (words) => {
|
|
29576
|
+
let at = 0;
|
|
29577
|
+
for (;at < words.length; at++) {
|
|
29578
|
+
const word = words[at];
|
|
29579
|
+
if (/^[A-Za-z_]\w*=/.test(word))
|
|
29580
|
+
return [];
|
|
29581
|
+
if (!PASS.test(word))
|
|
29582
|
+
break;
|
|
29583
|
+
if (/^(?:exec|command)$/.test(word) && words[at + 1]?.startsWith("-"))
|
|
29584
|
+
return [];
|
|
29585
|
+
while (/^(?:-|\d)/.test(words[at + 1] ?? ""))
|
|
29586
|
+
at++;
|
|
29587
|
+
}
|
|
29588
|
+
return words.slice(at);
|
|
29589
|
+
};
|
|
29590
|
+
var plainLines = (command, dialect) => {
|
|
29591
|
+
let first = null;
|
|
29592
|
+
const later = [];
|
|
29593
|
+
for (const segment of segmentsOf(command, dialect)) {
|
|
29594
|
+
if (segment.group || segment.unanalyzable || segment.subs?.length)
|
|
29595
|
+
return null;
|
|
29596
|
+
if (COMPOUND3.test(segment.words[0] ?? ""))
|
|
29597
|
+
return null;
|
|
29598
|
+
if (segment.words.some((word) => /^YTRACK_\w*=/.test(word)))
|
|
29599
|
+
return null;
|
|
29600
|
+
const names = namesYtrack([...segment.words, ...segment.stdin ?? []].join(" "));
|
|
29601
|
+
if (first === null) {
|
|
29602
|
+
if (!names || segment.expands?.length)
|
|
29603
|
+
return null;
|
|
29604
|
+
first = passed(segment.words);
|
|
29605
|
+
} else if (names)
|
|
29606
|
+
later.push(segment.words);
|
|
29607
|
+
}
|
|
29608
|
+
return first ? { first, later } : null;
|
|
29609
|
+
};
|
|
29610
|
+
var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
|
|
29611
|
+
if (!namesYtrack(command))
|
|
29612
|
+
return [];
|
|
29613
|
+
if (depth > MAX_DEPTH2)
|
|
29614
|
+
throw new Error("ytrack nested too deep");
|
|
29615
|
+
const key = `${plain}\x00${dialect}\x00${command}`;
|
|
29616
|
+
const known = READ.get(key);
|
|
29617
|
+
if (known)
|
|
29618
|
+
return known;
|
|
29619
|
+
let found = [];
|
|
29620
|
+
const lines = plain ? plainLines(command, dialect) : null;
|
|
29621
|
+
const none = new Map;
|
|
29622
|
+
if (!lines || !ytrackArgs(lines.first, found, depth, none, true) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
|
|
29623
|
+
found = [];
|
|
29624
|
+
for (const line of commandLines(command, dialect))
|
|
29625
|
+
ytrackArgs(line, found, depth, aliases(command), false);
|
|
29626
|
+
}
|
|
29627
|
+
READ.set(key, found);
|
|
29628
|
+
if (READ.size > 64)
|
|
29629
|
+
READ.delete(READ.keys().next().value);
|
|
29630
|
+
return found;
|
|
29631
|
+
};
|
|
29632
|
+
var writesMode = (cwd) => resolveRuntimeWorkspaceVcs(cwd)?.youtrack?.writes;
|
|
29633
|
+
var ytrackGate = (cwd, command, dialect, ask) => {
|
|
29634
|
+
let writes;
|
|
29635
|
+
try {
|
|
29636
|
+
const merged = new Map;
|
|
29637
|
+
for (const write of ytrackWrites(command, dialect)) {
|
|
29638
|
+
const seen = merged.get(write.command);
|
|
29639
|
+
merged.set(write.command, !seen || !write.workit ? write : !seen.workit ? seen : ungrant(write));
|
|
29640
|
+
}
|
|
29641
|
+
writes = [...merged.values()];
|
|
29642
|
+
} catch {
|
|
29643
|
+
if (writesMode(cwd) === "auto")
|
|
29644
|
+
return null;
|
|
29645
|
+
return {
|
|
29646
|
+
kind: "deny",
|
|
29647
|
+
reason: `Workit could not analyse this command, which names ytrack: run each ytrack call as its own plain command so a YouTrack write can ask the user first (#780).`,
|
|
29648
|
+
unblock: null
|
|
29649
|
+
};
|
|
29650
|
+
}
|
|
29651
|
+
if (!writes.length || writesMode(cwd) === "auto")
|
|
29652
|
+
return null;
|
|
29653
|
+
const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
|
|
29654
|
+
const bare = writes.filter((write) => !write.workit).map((write) => `\`${write.command}\` (${write.gap ? `Workit cannot carry ${write.gap} into a workit youtrack call` : "no workit youtrack verb covers it"})`);
|
|
29655
|
+
if (!calls.length && ask)
|
|
29656
|
+
return {
|
|
29657
|
+
kind: "ask",
|
|
29658
|
+
reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
|
|
29659
|
+
};
|
|
29660
|
+
const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
|
|
29661
|
+
const run = calls.length ? ` Run ${calls.join(", then ")} instead: it asks the user first. When it answers approval_needed, run exactly the \`workit approve <id>\` it names, now, with nothing around it (no 2>&1, pipe or echo), so the host asks the user; then rerun the workit call once.` : "";
|
|
29662
|
+
const user = bare.length ? ` For ${bare.join(", ")}, the user decides: ask the user, and if they agree they run it in their own terminal.` : "";
|
|
29663
|
+
const rerun = writes.some((write) => write.gap === NOT_PLAIN.gap) ? " To get the named workit youtrack call instead, rerun the ytrack call as one plain command, with no wrapper, loop, substitution or script around it." : "";
|
|
29664
|
+
return {
|
|
29665
|
+
kind: "deny",
|
|
29666
|
+
reason: `${why}${run}${user}${rerun}`,
|
|
29667
|
+
unblock: writes[0]?.workit ?? null
|
|
29668
|
+
};
|
|
29669
|
+
};
|
|
29670
|
+
|
|
29364
29671
|
// packages/workit-core/src/hooks/handle.ts
|
|
29365
29672
|
var usable2 = (value) => value === "native" || value === "partial";
|
|
29366
29673
|
var NONE6 = { kind: "none" };
|
|
@@ -29486,6 +29793,9 @@ function decide(input, deps) {
|
|
|
29486
29793
|
const policy = canDeny ? shellPolicy(input.cwd, event.command, event.dialect) : NONE6;
|
|
29487
29794
|
if (policy.kind !== "none")
|
|
29488
29795
|
return policy;
|
|
29796
|
+
const ytrack = canDeny ? ytrackGate(input.cwd, event.command, event.dialect ?? "posix", input.host === "claude_code") : null;
|
|
29797
|
+
if (ytrack)
|
|
29798
|
+
return ytrack;
|
|
29489
29799
|
const split = canDeny ? cdWorkitSplit(event.command) : null;
|
|
29490
29800
|
if (split)
|
|
29491
29801
|
return {
|
|
@@ -29621,7 +29931,7 @@ function decide(input, deps) {
|
|
|
29621
29931
|
}
|
|
29622
29932
|
}
|
|
29623
29933
|
// packages/workit-core/src/hooks/deadline.ts
|
|
29624
|
-
var
|
|
29934
|
+
var QUIET2 = new Set([
|
|
29625
29935
|
"stop",
|
|
29626
29936
|
"subagent.stop",
|
|
29627
29937
|
"shell.post",
|