pk-agent 0.7.3 → 0.7.4

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/index.js CHANGED
@@ -5577,7 +5577,7 @@ var init_parser2 = __esm(() => {
5577
5577
  });
5578
5578
 
5579
5579
  // package.json
5580
- var version = "0.7.3";
5580
+ var version = "0.7.4";
5581
5581
  var init_package = () => {};
5582
5582
 
5583
5583
  // src/storage/storage.ts
@@ -11086,7 +11086,7 @@ var init_session = __esm(() => {
11086
11086
  });
11087
11087
 
11088
11088
  // src/index.ts
11089
- import { Command as Command14 } from "commander";
11089
+ import { Command as Command15 } from "commander";
11090
11090
  import chalk10 from "chalk";
11091
11091
 
11092
11092
  // src/cli/auth.ts
@@ -20301,14 +20301,305 @@ function createTestCommand() {
20301
20301
  return cmd;
20302
20302
  }
20303
20303
 
20304
+ // src/cli/tray.ts
20305
+ import { Command as Command14 } from "commander";
20306
+ import matter5 from "gray-matter";
20307
+ import YAML2 from "yaml";
20308
+ import { homedir as homedir21 } from "os";
20309
+ import { basename as basename8, join as join24, resolve as resolve25 } from "path";
20310
+ import { existsSync as existsSync17 } from "fs";
20311
+ import { mkdir as mkdir7, readFile as readFile11, readdir, writeFile as writeFile8 } from "fs/promises";
20312
+ import { spawn as spawn7 } from "child_process";
20313
+ var TOGGLEABLE_ABILITIES = [
20314
+ "filesystem",
20315
+ "bash",
20316
+ "codexSdk",
20317
+ "agentsSdk",
20318
+ "captureWindow",
20319
+ "fullstack",
20320
+ "pkAgentBuilder"
20321
+ ];
20322
+ function getGlobalAgentsDir() {
20323
+ return join24(homedir21(), ".pk-agent", "agents");
20324
+ }
20325
+ function getAbilityListFromFrontmatter(frontmatter) {
20326
+ const abilities = [];
20327
+ const tools = frontmatter.tools ?? {};
20328
+ for (const ability of TOGGLEABLE_ABILITIES) {
20329
+ if (tools[ability] !== undefined) {
20330
+ abilities.push(ability);
20331
+ }
20332
+ }
20333
+ if (frontmatter.subagents !== undefined) {
20334
+ abilities.push("subagents");
20335
+ }
20336
+ if (frontmatter.mcpServers !== undefined) {
20337
+ abilities.push("mcpServers");
20338
+ }
20339
+ if (frontmatter.schedule !== undefined) {
20340
+ abilities.push("schedule");
20341
+ }
20342
+ return abilities;
20343
+ }
20344
+ function normalizeEnabledToolValue(ability) {
20345
+ if (ability === "filesystem") {
20346
+ return [{ paths: ["${root}"], permissions: ["read"] }];
20347
+ }
20348
+ if (ability === "bash") {
20349
+ return { commands: ["echo *"] };
20350
+ }
20351
+ return true;
20352
+ }
20353
+ function serializePkAgent2(frontmatter, body) {
20354
+ const yaml = YAML2.stringify(frontmatter, {
20355
+ indent: 2,
20356
+ lineWidth: 0
20357
+ }).trimEnd();
20358
+ const normalizedBody = body.trimStart();
20359
+ if (normalizedBody.length === 0) {
20360
+ return `---
20361
+ ${yaml}
20362
+ ---
20363
+ `;
20364
+ }
20365
+ return `---
20366
+ ${yaml}
20367
+ ---
20368
+
20369
+ ${normalizedBody}
20370
+ `;
20371
+ }
20372
+ async function discoverGlobalAgents() {
20373
+ const agentsDir = getGlobalAgentsDir();
20374
+ const results = [];
20375
+ if (!existsSync17(agentsDir)) {
20376
+ return results;
20377
+ }
20378
+ const entries = await readdir(agentsDir, { withFileTypes: true });
20379
+ for (const entry of entries) {
20380
+ if (!entry.isFile() || !entry.name.endsWith(".pk-agent")) {
20381
+ continue;
20382
+ }
20383
+ const filePath = join24(agentsDir, entry.name);
20384
+ try {
20385
+ const raw = await readFile11(filePath, "utf-8");
20386
+ const parsed = matter5(raw);
20387
+ const frontmatter = parsed.data;
20388
+ results.push({
20389
+ name: basename8(entry.name, ".pk-agent"),
20390
+ file: entry.name,
20391
+ path: filePath,
20392
+ abilities: getAbilityListFromFrontmatter(frontmatter)
20393
+ });
20394
+ } catch {}
20395
+ }
20396
+ results.sort((a, b) => a.name.localeCompare(b.name));
20397
+ return results;
20398
+ }
20399
+ async function toggleGlobalAgentAbility(agentName, ability) {
20400
+ if (!TOGGLEABLE_ABILITIES.includes(ability)) {
20401
+ throw new Error(`Unsupported ability '${ability}'. Supported: ${TOGGLEABLE_ABILITIES.join(", ")}`);
20402
+ }
20403
+ const agentsDir = getGlobalAgentsDir();
20404
+ const filePath = resolve25(agentsDir, `${agentName}.pk-agent`);
20405
+ if (!existsSync17(filePath)) {
20406
+ throw new Error(`Global agent not found: ${agentName}`);
20407
+ }
20408
+ const raw = await readFile11(filePath, "utf-8");
20409
+ const parsed = matter5(raw);
20410
+ const frontmatter = parsed.data;
20411
+ const tools = { ...frontmatter.tools ?? {} };
20412
+ const typedAbility = ability;
20413
+ let enabled = false;
20414
+ if (tools[typedAbility] !== undefined) {
20415
+ delete tools[typedAbility];
20416
+ enabled = false;
20417
+ } else {
20418
+ tools[typedAbility] = normalizeEnabledToolValue(typedAbility);
20419
+ enabled = true;
20420
+ }
20421
+ if (Object.keys(tools).length === 0) {
20422
+ delete frontmatter.tools;
20423
+ } else {
20424
+ frontmatter.tools = tools;
20425
+ }
20426
+ const updated = serializePkAgent2(frontmatter, parsed.content);
20427
+ await writeFile8(filePath, updated, "utf-8");
20428
+ return { enabled };
20429
+ }
20430
+ function buildTrayScript(cliExecPath, cliScriptPath) {
20431
+ const safeCliExecPath = cliExecPath.replace(/'/g, "''");
20432
+ const safeCliScriptPath = (cliScriptPath ?? "").replace(/'/g, "''");
20433
+ return `
20434
+ Add-Type -AssemblyName System.Windows.Forms
20435
+ Add-Type -AssemblyName System.Drawing
20436
+
20437
+ $ErrorActionPreference = 'Stop'
20438
+ $cliExec = '${safeCliExecPath}'
20439
+ $cliScript = '${safeCliScriptPath}'
20440
+
20441
+ function Invoke-PkAgent {
20442
+ param([string[]]$Args)
20443
+ if ([string]::IsNullOrWhiteSpace($cliScript)) {
20444
+ & $cliExec @Args
20445
+ } else {
20446
+ & $cliExec $cliScript @Args
20447
+ }
20448
+ }
20449
+
20450
+ function Build-Menu {
20451
+ param([System.Windows.Forms.ContextMenuStrip]$Menu, [System.Windows.Forms.NotifyIcon]$Notify)
20452
+
20453
+ $Menu.Items.Clear()
20454
+ $header = New-Object System.Windows.Forms.ToolStripMenuItem
20455
+ $header.Text = 'PK-Agent Tray'
20456
+ $header.Enabled = $false
20457
+ $Menu.Items.Add($header) | Out-Null
20458
+ $Menu.Items.Add('-') | Out-Null
20459
+
20460
+ try {
20461
+ $json = Invoke-PkAgent @('tray', '--list-global-json')
20462
+ $data = $json | ConvertFrom-Json
20463
+ if ($data.agents.Count -eq 0) {
20464
+ $empty = New-Object System.Windows.Forms.ToolStripMenuItem
20465
+ $empty.Text = 'No global agents found'
20466
+ $empty.Enabled = $false
20467
+ $Menu.Items.Add($empty) | Out-Null
20468
+ } else {
20469
+ foreach ($agent in $data.agents) {
20470
+ $agentItem = New-Object System.Windows.Forms.ToolStripMenuItem
20471
+ $agentItem.Text = $agent.name
20472
+ $agentItem.ToolTipText = $agent.path
20473
+ foreach ($ability in @('filesystem','bash','codexSdk','agentsSdk','captureWindow','fullstack','pkAgentBuilder')) {
20474
+ $agentName = [string]$agent.name
20475
+ $abilityName = [string]$ability
20476
+ $abilityItem = New-Object System.Windows.Forms.ToolStripMenuItem
20477
+ $abilityItem.Text = $abilityName
20478
+ $abilityItem.Checked = $agent.abilities -contains $abilityName
20479
+ $abilityItem.Add_Click(({
20480
+ try {
20481
+ Invoke-PkAgent @('tray', '--toggle-global-ability', $agentName, $abilityName) | Out-Null
20482
+ Build-Menu -Menu $Menu -Notify $Notify
20483
+ } catch {
20484
+ [System.Windows.Forms.MessageBox]::Show($_.Exception.Message, 'pk-agent tray')
20485
+ }
20486
+ }).GetNewClosure())
20487
+ $agentItem.DropDownItems.Add($abilityItem) | Out-Null
20488
+ }
20489
+
20490
+ $details = New-Object System.Windows.Forms.ToolStripMenuItem
20491
+ $details.Enabled = $false
20492
+ if ($agent.abilities.Count -gt 0) {
20493
+ $details.Text = 'abilities: ' + ($agent.abilities -join ', ')
20494
+ } else {
20495
+ $details.Text = 'abilities: none'
20496
+ }
20497
+ $agentItem.DropDownItems.Add('-') | Out-Null
20498
+ $agentItem.DropDownItems.Add($details) | Out-Null
20499
+ $Menu.Items.Add($agentItem) | Out-Null
20500
+ }
20501
+ }
20502
+ } catch {
20503
+ $err = New-Object System.Windows.Forms.ToolStripMenuItem
20504
+ $err.Text = 'Failed to load agents'
20505
+ $err.Enabled = $false
20506
+ $Menu.Items.Add($err) | Out-Null
20507
+ }
20508
+
20509
+ $Menu.Items.Add('-') | Out-Null
20510
+
20511
+ $refresh = New-Object System.Windows.Forms.ToolStripMenuItem
20512
+ $refresh.Text = 'Refresh'
20513
+ $refresh.Add_Click({ Build-Menu -Menu $Menu -Notify $Notify })
20514
+ $Menu.Items.Add($refresh) | Out-Null
20515
+
20516
+ $openAgents = New-Object System.Windows.Forms.ToolStripMenuItem
20517
+ $openAgents.Text = 'Open global agents folder'
20518
+ $openAgents.Add_Click({
20519
+ $dir = Join-Path $HOME '.pk-agent\\agents'
20520
+ New-Item -ItemType Directory -Force -Path $dir | Out-Null
20521
+ Start-Process explorer.exe $dir
20522
+ })
20523
+ $Menu.Items.Add($openAgents) | Out-Null
20524
+
20525
+ $quit = New-Object System.Windows.Forms.ToolStripMenuItem
20526
+ $quit.Text = 'Quit'
20527
+ $quit.Add_Click({
20528
+ $Notify.Visible = $false
20529
+ [System.Windows.Forms.Application]::Exit()
20530
+ })
20531
+ $Menu.Items.Add($quit) | Out-Null
20532
+ }
20533
+
20534
+ $menu = New-Object System.Windows.Forms.ContextMenuStrip
20535
+ $notify = New-Object System.Windows.Forms.NotifyIcon
20536
+ $notify.Icon = [System.Drawing.SystemIcons]::Application
20537
+ $notify.Visible = $true
20538
+ $notify.Text = 'PK-Agent'
20539
+ $notify.ContextMenuStrip = $menu
20540
+
20541
+ Build-Menu -Menu $menu -Notify $notify
20542
+
20543
+ [System.Windows.Forms.Application]::Run()
20544
+ `;
20545
+ }
20546
+ async function launchWindowsTray() {
20547
+ const agentsDir = getGlobalAgentsDir();
20548
+ await mkdir7(agentsDir, { recursive: true });
20549
+ const cliExecPath = process.execPath;
20550
+ const cliScriptPath = process.argv[1];
20551
+ const script = buildTrayScript(cliExecPath, cliScriptPath);
20552
+ const scriptPath = join24(homedir21(), ".pk-agent", "cache", "pk-agent-tray.ps1");
20553
+ await mkdir7(join24(homedir21(), ".pk-agent", "cache"), { recursive: true });
20554
+ await writeFile8(scriptPath, script, "utf-8");
20555
+ spawn7("powershell", [
20556
+ "-NoProfile",
20557
+ "-ExecutionPolicy",
20558
+ "Bypass",
20559
+ "-File",
20560
+ scriptPath
20561
+ ], {
20562
+ detached: true,
20563
+ stdio: "ignore",
20564
+ windowsHide: true
20565
+ }).unref();
20566
+ }
20567
+ function createTrayCommand() {
20568
+ return new Command14("tray").description("Launch Windows system tray manager for global pk-agent agents").option("--list-global-json", "List global agents and abilities as JSON").option("--toggle-global-ability <values...>", "Toggle ability for a global agent: <agent> <ability>").action(async (options) => {
20569
+ if (options.listGlobalJson) {
20570
+ const agents = await discoverGlobalAgents();
20571
+ process.stdout.write(`${JSON.stringify({ agents }, null, 2)}
20572
+ `);
20573
+ return;
20574
+ }
20575
+ const toggleArgs = options.toggleGlobalAbility;
20576
+ if (toggleArgs && toggleArgs.length > 0) {
20577
+ if (toggleArgs.length !== 2) {
20578
+ throw new Error("--toggle-global-ability requires exactly 2 values: <agent> <ability>");
20579
+ }
20580
+ const [agentName, ability] = toggleArgs;
20581
+ const result = await toggleGlobalAgentAbility(agentName, ability);
20582
+ process.stdout.write(`${JSON.stringify({ agent: agentName, ability, enabled: result.enabled })}
20583
+ `);
20584
+ return;
20585
+ }
20586
+ if (process.platform !== "win32") {
20587
+ throw new Error("Systray is currently supported on Windows only.");
20588
+ }
20589
+ await launchWindowsTray();
20590
+ process.stdout.write(`[OK] PK-Agent tray launched.
20591
+ `);
20592
+ });
20593
+ }
20594
+
20304
20595
  // src/cli/worker.ts
20305
20596
  init_parser2();
20306
20597
  init_mcp();
20307
20598
  init_runner();
20308
20599
  init_logger();
20309
20600
  init_redaction();
20310
- import { resolve as resolve25, dirname as dirname17 } from "path";
20311
- import { existsSync as existsSync17 } from "fs";
20601
+ import { resolve as resolve26, dirname as dirname17 } from "path";
20602
+ import { existsSync as existsSync18 } from "fs";
20312
20603
  import * as dotenv5 from "dotenv";
20313
20604
  function toSafeChunk(chunk) {
20314
20605
  if (chunk.type === "tool-call") {
@@ -20341,8 +20632,8 @@ async function executeAgent(req, emit) {
20341
20632
  const startTime = Date.now();
20342
20633
  let mcp = [];
20343
20634
  try {
20344
- const agentPath = resolve25(req.projectRoot, req.agentPath);
20345
- if (!existsSync17(agentPath)) {
20635
+ const agentPath = resolve26(req.projectRoot, req.agentPath);
20636
+ if (!existsSync18(agentPath)) {
20346
20637
  return {
20347
20638
  id: req.id,
20348
20639
  type: "done",
@@ -20350,11 +20641,11 @@ async function executeAgent(req, emit) {
20350
20641
  error: { code: "AGENT_NOT_FOUND", message: `Agent file not found: ${req.agentPath}` }
20351
20642
  };
20352
20643
  }
20353
- const envFile = resolve25(req.projectRoot, ".env");
20354
- const envLocalFile = resolve25(req.projectRoot, ".env.local");
20355
- if (existsSync17(envLocalFile)) {
20644
+ const envFile = resolve26(req.projectRoot, ".env");
20645
+ const envLocalFile = resolve26(req.projectRoot, ".env.local");
20646
+ if (existsSync18(envLocalFile)) {
20356
20647
  dotenv5.config({ path: envLocalFile });
20357
- } else if (existsSync17(envFile)) {
20648
+ } else if (existsSync18(envFile)) {
20358
20649
  dotenv5.config({ path: envFile });
20359
20650
  }
20360
20651
  try {
@@ -20557,7 +20848,7 @@ async function runInternalWorker() {
20557
20848
  init_cli_helpers();
20558
20849
  init_pk_agent_dirs();
20559
20850
  var version2 = getVersionString();
20560
- var program = new Command14;
20851
+ var program = new Command15;
20561
20852
  try {
20562
20853
  ensurePkAgentUserDirs();
20563
20854
  ensurePkAgentProjectDirs(process.cwd());
@@ -20607,6 +20898,7 @@ program.addCommand(createRunCommand());
20607
20898
  program.addCommand(createLintCommand());
20608
20899
  program.addCommand(createConfigCommand());
20609
20900
  program.addCommand(createTestCommand());
20901
+ program.addCommand(createTrayCommand());
20610
20902
  program.addCommand(createBenchmarkCommand(), { hidden: true });
20611
20903
  if (process.argv[2] === "--internal-worker") {
20612
20904
  runInternalWorker();
@@ -20617,5 +20909,5 @@ if (process.argv[2] === "--internal-worker") {
20617
20909
  }
20618
20910
  }
20619
20911
 
20620
- //# debugId=7A021AEF99F4959564756E2164756E21
20912
+ //# debugId=18D15260DA895C9E64756E2164756E21
20621
20913
  //# sourceMappingURL=index.js.map