palmier 0.3.4 → 0.3.6

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.
@@ -13,4 +13,4 @@ jobs:
13
13
  cache: npm
14
14
  - run: npm ci
15
15
  - run: npm run build
16
- # - run: npm test
16
+ - run: npm test
package/README.md CHANGED
@@ -52,7 +52,6 @@ All `palmier` commands should be run from a dedicated Palmier root directory (e.
52
52
  | `palmier restart` | Restart the palmier serve daemon |
53
53
  | `palmier run <task-id>` | Execute a specific task |
54
54
  | `palmier mcpserver` | Start an MCP server exposing Palmier tools (stdio transport) |
55
- | `palmier agents` | Re-detect installed agent CLIs and update config |
56
55
 
57
56
  ## Setup
58
57
 
@@ -88,7 +87,7 @@ The `init` command:
88
87
  - Installs a background daemon (systemd user service on Linux, Registry Run key on Windows)
89
88
  - Auto-enters pair mode to connect your first device
90
89
 
91
- To re-detect agents after installing or removing a CLI, run `palmier agents`.
90
+ Agents are re-detected on every daemon start. Run `palmier restart` after installing or removing a CLI.
92
91
 
93
92
  ### Verifying the Service
94
93
 
@@ -170,7 +169,7 @@ src/
170
169
  lan.ts # On-demand LAN server
171
170
  sessions.ts # Session token management CLI (list, revoke, revoke-all)
172
171
  info.ts # Print host connection info
173
- agents.ts # Re-detect installed agent CLIs
172
+
174
173
  serve.ts # Transport selection, startup, and crash detection polling
175
174
  restart.ts # Daemon restart (cross-platform)
176
175
  run.ts # Single task execution
@@ -16,7 +16,8 @@ export class CopilotAgent {
16
16
  const args = ["-p", prompt];
17
17
  const allPerms = [...(task.frontmatter.permissions ?? []), ...(extraPermissions ?? [])];
18
18
  if (allPerms.length > 0) {
19
- args.push("--allow-tool", allPerms.map((p) => p.name).join(","));
19
+ args.push(`--allow-tool='${allPerms.map((p) => p.name).join(",")}'`);
20
+ ;
20
21
  }
21
22
  if (retryPrompt) {
22
23
  args.push("--continue");
@@ -25,7 +26,7 @@ export class CopilotAgent {
25
26
  }
26
27
  async init() {
27
28
  try {
28
- execSync("gh copilot -v", { stdio: "ignore", shell: SHELL });
29
+ execSync("copilot -v", { stdio: "ignore", shell: SHELL });
29
30
  }
30
31
  catch {
31
32
  return false;
@@ -1,5 +1,26 @@
1
+ import type { TaskRunningState, RequiredPermission } from "../types.js";
1
2
  /**
2
3
  * Execute a task by ID.
3
4
  */
4
5
  export declare function runCommand(taskId: string): Promise<void>;
6
+ /**
7
+ * Extract report file names from agent output.
8
+ * Looks for lines matching: [PALMIER_REPORT] <filename>
9
+ */
10
+ export declare function parseReportFiles(output: string): string[];
11
+ /**
12
+ * Extract required permissions from agent output.
13
+ * Looks for lines matching: [PALMIER_PERMISSION] <tool> | <description>
14
+ */
15
+ export declare function parsePermissions(output: string): RequiredPermission[];
16
+ /**
17
+ * Extract user input requests from agent output.
18
+ * Looks for lines matching: [PALMIER_INPUT] <description>
19
+ */
20
+ export declare function parseInputRequests(output: string): string[];
21
+ /**
22
+ * Parse the agent's output for success/failure markers.
23
+ * Falls back to "finished" if no marker is found.
24
+ */
25
+ export declare function parseTaskOutcome(output: string): TaskRunningState;
5
26
  //# sourceMappingURL=run.d.ts.map
@@ -405,7 +405,7 @@ async function requestConfirmation(nc, config, task, taskDir) {
405
405
  * Extract report file names from agent output.
406
406
  * Looks for lines matching: [PALMIER_REPORT] <filename>
407
407
  */
408
- function parseReportFiles(output) {
408
+ export function parseReportFiles(output) {
409
409
  const regex = new RegExp(`^\\${TASK_REPORT_PREFIX}\\s+(.+)$`, "gm");
410
410
  const files = [];
411
411
  let match;
@@ -420,7 +420,7 @@ function parseReportFiles(output) {
420
420
  * Extract required permissions from agent output.
421
421
  * Looks for lines matching: [PALMIER_PERMISSION] <tool> | <description>
422
422
  */
423
- function parsePermissions(output) {
423
+ export function parsePermissions(output) {
424
424
  const regex = new RegExp(`^\\${TASK_PERMISSION_PREFIX}\\s+(.+)$`, "gm");
425
425
  const perms = [];
426
426
  let match;
@@ -440,7 +440,7 @@ function parsePermissions(output) {
440
440
  * Extract user input requests from agent output.
441
441
  * Looks for lines matching: [PALMIER_INPUT] <description>
442
442
  */
443
- function parseInputRequests(output) {
443
+ export function parseInputRequests(output) {
444
444
  const regex = new RegExp(`^\\${TASK_INPUT_PREFIX}\\s+(.+)$`, "gm");
445
445
  const inputs = [];
446
446
  let match;
@@ -455,7 +455,7 @@ function parseInputRequests(output) {
455
455
  * Parse the agent's output for success/failure markers.
456
456
  * Falls back to "finished" if no marker is found.
457
457
  */
458
- function parseTaskOutcome(output) {
458
+ export function parseTaskOutcome(output) {
459
459
  const lastChunk = output.slice(-500);
460
460
  if (lastChunk.includes(TASK_FAILURE_MARKER))
461
461
  return "failed";
@@ -8,6 +8,8 @@ import { getTaskDir, readTaskStatus, writeTaskStatus, appendHistory, parseTaskFi
8
8
  import { publishHostEvent } from "../events.js";
9
9
  import { getPlatform } from "../platform/index.js";
10
10
  import { checkForUpdate } from "../update-checker.js";
11
+ import { detectAgents } from "../agents/agent.js";
12
+ import { saveConfig } from "../config.js";
11
13
  import { CONFIG_DIR } from "../config.js";
12
14
  const POLL_INTERVAL_MS = 30_000;
13
15
  const DAEMON_PID_FILE = path.join(CONFIG_DIR, "daemon.pid");
@@ -72,6 +74,11 @@ export async function serveCommand() {
72
74
  // Write PID so `palmier restart` can find us regardless of how we were started
73
75
  fs.writeFileSync(DAEMON_PID_FILE, String(process.pid), "utf-8");
74
76
  console.log("Starting...");
77
+ // Re-detect agents on every daemon start
78
+ const agents = await detectAgents();
79
+ config.agents = agents;
80
+ saveConfig(config);
81
+ console.log(`Detected agents: ${agents.map((a) => a.key).join(", ") || "none"}`);
75
82
  const nc = await connectNats(config);
76
83
  // Reconcile any tasks stuck from before daemon started
77
84
  await checkStaleTasks(config, nc);
package/dist/index.js CHANGED
@@ -9,7 +9,6 @@ import { infoCommand } from "./commands/info.js";
9
9
  import { runCommand } from "./commands/run.js";
10
10
  import { serveCommand } from "./commands/serve.js";
11
11
  import { mcpserverCommand } from "./commands/mcpserver.js";
12
- import { agentsCommand } from "./commands/agents.js";
13
12
  import { pairCommand } from "./commands/pair.js";
14
13
  import { lanCommand } from "./commands/lan.js";
15
14
  import { restartCommand } from "./commands/restart.js";
@@ -57,12 +56,6 @@ program
57
56
  .action(async () => {
58
57
  await mcpserverCommand();
59
58
  });
60
- program
61
- .command("agents")
62
- .description("Re-detect installed agent CLIs and update config")
63
- .action(async () => {
64
- await agentsCommand();
65
- });
66
59
  program
67
60
  .command("pair")
68
61
  .description("Generate a pairing code for connecting a PWA client")
@@ -1,5 +1,17 @@
1
1
  import type { PlatformService } from "./platform.js";
2
2
  import type { HostConfig, ParsedTask } from "../types.js";
3
+ /**
4
+ * Convert a cron expression to a systemd OnCalendar string.
5
+ *
6
+ * Only the 4 cron patterns the PWA UI can produce are supported:
7
+ * hourly: "0 * * * *"
8
+ * daily: "MM HH * * *"
9
+ * weekly: "MM HH * * D"
10
+ * monthly: "MM HH D * *"
11
+ * Arbitrary cron expressions (ranges, lists, steps beyond hourly) are NOT
12
+ * handled because the UI never generates them.
13
+ */
14
+ export declare function cronToOnCalendar(cron: string): string;
3
15
  export declare class LinuxPlatform implements PlatformService {
4
16
  installDaemon(config: HostConfig): void;
5
17
  restartDaemon(): Promise<void>;
@@ -22,7 +22,7 @@ function getServiceName(taskId) {
22
22
  * Arbitrary cron expressions (ranges, lists, steps beyond hourly) are NOT
23
23
  * handled because the UI never generates them.
24
24
  */
25
- function cronToOnCalendar(cron) {
25
+ export function cronToOnCalendar(cron) {
26
26
  const parts = cron.trim().split(/\s+/);
27
27
  if (parts.length !== 5) {
28
28
  throw new Error(`Invalid cron expression (expected 5 fields): ${cron}`);
@@ -1,5 +1,22 @@
1
1
  import type { PlatformService } from "./platform.js";
2
2
  import type { HostConfig, ParsedTask } from "../types.js";
3
+ /**
4
+ * Convert a cron expression or "once" trigger to Task Scheduler XML trigger elements.
5
+ *
6
+ * Only these cron patterns (produced by the PWA UI) are handled:
7
+ * hourly: "0 * * * *"
8
+ * daily: "MM HH * * *"
9
+ * weekly: "MM HH * * D"
10
+ * monthly: "MM HH D * *"
11
+ */
12
+ export declare function triggerToXml(trigger: {
13
+ type: string;
14
+ value: string;
15
+ }): string;
16
+ /**
17
+ * Build a complete Task Scheduler XML definition.
18
+ */
19
+ export declare function buildTaskXml(tr: string, triggers: string[]): string;
3
20
  export declare class WindowsPlatform implements PlatformService {
4
21
  installDaemon(config: HostConfig): void;
5
22
  restartDaemon(): Promise<void>;
@@ -25,7 +25,7 @@ const DOW_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Frid
25
25
  * weekly: "MM HH * * D"
26
26
  * monthly: "MM HH D * *"
27
27
  */
28
- function triggerToXml(trigger) {
28
+ export function triggerToXml(trigger) {
29
29
  if (trigger.type === "once") {
30
30
  // ISO datetime "2026-03-28T09:00"
31
31
  return `<TimeTrigger><StartBoundary>${trigger.value}:00</StartBoundary></TimeTrigger>`;
@@ -56,7 +56,7 @@ function triggerToXml(trigger) {
56
56
  /**
57
57
  * Build a complete Task Scheduler XML definition.
58
58
  */
59
- function buildTaskXml(tr, triggers) {
59
+ export function buildTaskXml(tr, triggers) {
60
60
  const [command, ...argParts] = tr.match(/"[^"]*"|[^\s]+/g) ?? [];
61
61
  const commandStr = command?.replace(/"/g, "") ?? "";
62
62
  const argsStr = argParts.map((a) => a.replace(/"/g, "")).join(" ");
package/dist/task.d.ts CHANGED
@@ -3,6 +3,10 @@ import type { ParsedTask, TaskStatus, HistoryEntry } from "./types.js";
3
3
  * Parse a TASK.md file from the given task directory.
4
4
  */
5
5
  export declare function parseTaskFile(taskDir: string): ParsedTask;
6
+ /**
7
+ * Parse TASK.md content string into frontmatter + body.
8
+ */
9
+ export declare function parseTaskContent(content: string): ParsedTask;
6
10
  /**
7
11
  * Write a TASK.md file to the given task directory.
8
12
  * Creates the directory if it doesn't exist.
package/dist/task.js CHANGED
@@ -15,7 +15,7 @@ export function parseTaskFile(taskDir) {
15
15
  /**
16
16
  * Parse TASK.md content string into frontmatter + body.
17
17
  */
18
- function parseTaskContent(content) {
18
+ export function parseTaskContent(content) {
19
19
  const fmRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
20
20
  const match = content.match(fmRegex);
21
21
  if (!match) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "palmier",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Palmier host CLI - provisions, executes tasks, and serves NATS RPC",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hongxu Cai",
@@ -21,6 +21,7 @@
21
21
  "scripts": {
22
22
  "dev": "tsx src/index.ts",
23
23
  "build": "tsc && node -e \"require('fs').cpSync('src/commands/plan-generation.md','dist/commands/plan-generation.md')\"",
24
+ "test": "tsx --test test/**/*.test.ts",
24
25
  "prepare": "npm run build",
25
26
  "start": "node dist/index.js"
26
27
  },
@@ -21,7 +21,7 @@ export class CopilotAgent implements AgentTool {
21
21
 
22
22
  const allPerms = [...(task.frontmatter.permissions ?? []), ...(extraPermissions ?? [])];
23
23
  if (allPerms.length > 0) {
24
- args.push("--allow-tool", allPerms.map((p) => p.name).join(","));
24
+ args.push(`--allow-tool='${allPerms.map((p) => p.name).join(",")}'`);;
25
25
  }
26
26
 
27
27
  if (retryPrompt) { args.push("--continue"); }
@@ -30,7 +30,7 @@ export class CopilotAgent implements AgentTool {
30
30
 
31
31
  async init(): Promise<boolean> {
32
32
  try {
33
- execSync("gh copilot -v", { stdio: "ignore", shell: SHELL });
33
+ execSync("copilot -v", { stdio: "ignore", shell: SHELL });
34
34
  } catch {
35
35
  return false;
36
36
  }
@@ -536,7 +536,7 @@ async function requestConfirmation(
536
536
  * Extract report file names from agent output.
537
537
  * Looks for lines matching: [PALMIER_REPORT] <filename>
538
538
  */
539
- function parseReportFiles(output: string): string[] {
539
+ export function parseReportFiles(output: string): string[] {
540
540
  const regex = new RegExp(`^\\${TASK_REPORT_PREFIX}\\s+(.+)$`, "gm");
541
541
  const files: string[] = [];
542
542
  let match;
@@ -551,7 +551,7 @@ function parseReportFiles(output: string): string[] {
551
551
  * Extract required permissions from agent output.
552
552
  * Looks for lines matching: [PALMIER_PERMISSION] <tool> | <description>
553
553
  */
554
- function parsePermissions(output: string): RequiredPermission[] {
554
+ export function parsePermissions(output: string): RequiredPermission[] {
555
555
  const regex = new RegExp(`^\\${TASK_PERMISSION_PREFIX}\\s+(.+)$`, "gm");
556
556
  const perms: RequiredPermission[] = [];
557
557
  let match;
@@ -571,7 +571,7 @@ function parsePermissions(output: string): RequiredPermission[] {
571
571
  * Extract user input requests from agent output.
572
572
  * Looks for lines matching: [PALMIER_INPUT] <description>
573
573
  */
574
- function parseInputRequests(output: string): string[] {
574
+ export function parseInputRequests(output: string): string[] {
575
575
  const regex = new RegExp(`^\\${TASK_INPUT_PREFIX}\\s+(.+)$`, "gm");
576
576
  const inputs: string[] = [];
577
577
  let match;
@@ -586,7 +586,7 @@ function parseInputRequests(output: string): string[] {
586
586
  * Parse the agent's output for success/failure markers.
587
587
  * Falls back to "finished" if no marker is found.
588
588
  */
589
- function parseTaskOutcome(output: string): TaskRunningState {
589
+ export function parseTaskOutcome(output: string): TaskRunningState {
590
590
  const lastChunk = output.slice(-500);
591
591
  if (lastChunk.includes(TASK_FAILURE_MARKER)) return "failed";
592
592
  if (lastChunk.includes(TASK_SUCCESS_MARKER)) return "finished";
@@ -8,6 +8,8 @@ import { getTaskDir, readTaskStatus, writeTaskStatus, appendHistory, parseTaskFi
8
8
  import { publishHostEvent } from "../events.js";
9
9
  import { getPlatform } from "../platform/index.js";
10
10
  import { checkForUpdate } from "../update-checker.js";
11
+ import { detectAgents } from "../agents/agent.js";
12
+ import { saveConfig } from "../config.js";
11
13
  import type { HostConfig } from "../types.js";
12
14
  import { CONFIG_DIR } from "../config.js";
13
15
  import type { NatsConnection } from "nats";
@@ -89,6 +91,12 @@ export async function serveCommand(): Promise<void> {
89
91
 
90
92
  console.log("Starting...");
91
93
 
94
+ // Re-detect agents on every daemon start
95
+ const agents = await detectAgents();
96
+ config.agents = agents;
97
+ saveConfig(config);
98
+ console.log(`Detected agents: ${agents.map((a) => a.key).join(", ") || "none"}`);
99
+
92
100
  const nc = await connectNats(config);
93
101
 
94
102
  // Reconcile any tasks stuck from before daemon started
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ import { infoCommand } from "./commands/info.js";
10
10
  import { runCommand } from "./commands/run.js";
11
11
  import { serveCommand } from "./commands/serve.js";
12
12
  import { mcpserverCommand } from "./commands/mcpserver.js";
13
- import { agentsCommand } from "./commands/agents.js";
13
+
14
14
  import { pairCommand } from "./commands/pair.js";
15
15
  import { lanCommand } from "./commands/lan.js";
16
16
  import { restartCommand } from "./commands/restart.js";
@@ -68,13 +68,6 @@ program
68
68
  await mcpserverCommand();
69
69
  });
70
70
 
71
- program
72
- .command("agents")
73
- .description("Re-detect installed agent CLIs and update config")
74
- .action(async () => {
75
- await agentsCommand();
76
- });
77
-
78
71
  program
79
72
  .command("pair")
80
73
  .description("Generate a pairing code for connecting a PWA client")
@@ -29,7 +29,7 @@ function getServiceName(taskId: string): string {
29
29
  * Arbitrary cron expressions (ranges, lists, steps beyond hourly) are NOT
30
30
  * handled because the UI never generates them.
31
31
  */
32
- function cronToOnCalendar(cron: string): string {
32
+ export function cronToOnCalendar(cron: string): string {
33
33
  const parts = cron.trim().split(/\s+/);
34
34
  if (parts.length !== 5) {
35
35
  throw new Error(`Invalid cron expression (expected 5 fields): ${cron}`);
@@ -32,7 +32,7 @@ const DOW_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Frid
32
32
  * weekly: "MM HH * * D"
33
33
  * monthly: "MM HH D * *"
34
34
  */
35
- function triggerToXml(trigger: { type: string; value: string }): string {
35
+ export function triggerToXml(trigger: { type: string; value: string }): string {
36
36
  if (trigger.type === "once") {
37
37
  // ISO datetime "2026-03-28T09:00"
38
38
  return `<TimeTrigger><StartBoundary>${trigger.value}:00</StartBoundary></TimeTrigger>`;
@@ -68,7 +68,7 @@ function triggerToXml(trigger: { type: string; value: string }): string {
68
68
  /**
69
69
  * Build a complete Task Scheduler XML definition.
70
70
  */
71
- function buildTaskXml(tr: string, triggers: string[]): string {
71
+ export function buildTaskXml(tr: string, triggers: string[]): string {
72
72
  const [command, ...argParts] = tr.match(/"[^"]*"|[^\s]+/g) ?? [];
73
73
  const commandStr = command?.replace(/"/g, "") ?? "";
74
74
  const argsStr = argParts.map((a) => a.replace(/"/g, "")).join(" ");
package/src/task.ts CHANGED
@@ -20,7 +20,7 @@ export function parseTaskFile(taskDir: string): ParsedTask {
20
20
  /**
21
21
  * Parse TASK.md content string into frontmatter + body.
22
22
  */
23
- function parseTaskContent(content: string): ParsedTask {
23
+ export function parseTaskContent(content: string): ParsedTask {
24
24
  const fmRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
25
25
  const match = content.match(fmRegex);
26
26
 
@@ -0,0 +1,74 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { parseTaskOutcome, parseReportFiles, parsePermissions, parseInputRequests } from "../src/commands/run.js";
4
+
5
+ describe("parseTaskOutcome", () => {
6
+ it("returns 'finished' for success marker", () => {
7
+ assert.equal(parseTaskOutcome("some output\n[PALMIER_TASK_SUCCESS]"), "finished");
8
+ });
9
+
10
+ it("returns 'failed' for failure marker", () => {
11
+ assert.equal(parseTaskOutcome("some output\n[PALMIER_TASK_FAILURE]"), "failed");
12
+ });
13
+
14
+ it("returns 'finished' when no marker is present", () => {
15
+ assert.equal(parseTaskOutcome("just some regular output"), "finished");
16
+ });
17
+
18
+ it("returns 'failed' when both markers present (failure takes priority)", () => {
19
+ assert.equal(parseTaskOutcome("[PALMIER_TASK_SUCCESS]\n[PALMIER_TASK_FAILURE]"), "failed");
20
+ });
21
+
22
+ it("only looks at last 500 chars", () => {
23
+ const padding = "x".repeat(600);
24
+ assert.equal(parseTaskOutcome("[PALMIER_TASK_FAILURE]" + padding), "finished");
25
+ });
26
+ });
27
+
28
+ describe("parseReportFiles", () => {
29
+ it("extracts report file names", () => {
30
+ const output = "doing work\n[PALMIER_REPORT] report.md\nmore work\n[PALMIER_REPORT] summary.md";
31
+ assert.deepEqual(parseReportFiles(output), ["report.md", "summary.md"]);
32
+ });
33
+
34
+ it("returns empty array when no reports", () => {
35
+ assert.deepEqual(parseReportFiles("no reports here"), []);
36
+ });
37
+
38
+ it("trims whitespace from file names", () => {
39
+ assert.deepEqual(parseReportFiles("[PALMIER_REPORT] report.md "), ["report.md"]);
40
+ });
41
+ });
42
+
43
+ describe("parsePermissions", () => {
44
+ it("extracts permissions with name and description", () => {
45
+ const output = "[PALMIER_PERMISSION] Read | Read file contents\n[PALMIER_PERMISSION] Bash(npm test) | Run tests";
46
+ const perms = parsePermissions(output);
47
+ assert.equal(perms.length, 2);
48
+ assert.deepEqual(perms[0], { name: "Read", description: "Read file contents" });
49
+ assert.deepEqual(perms[1], { name: "Bash(npm test)", description: "Run tests" });
50
+ });
51
+
52
+ it("handles permission without description", () => {
53
+ const perms = parsePermissions("[PALMIER_PERMISSION] Write");
54
+ assert.deepEqual(perms, [{ name: "Write", description: "" }]);
55
+ });
56
+
57
+ it("returns empty array when no permissions", () => {
58
+ assert.deepEqual(parsePermissions("no permissions"), []);
59
+ });
60
+ });
61
+
62
+ describe("parseInputRequests", () => {
63
+ it("extracts input descriptions", () => {
64
+ const output = "[PALMIER_INPUT] What is the API key?\n[PALMIER_INPUT] Database connection string?";
65
+ assert.deepEqual(parseInputRequests(output), [
66
+ "What is the API key?",
67
+ "Database connection string?",
68
+ ]);
69
+ });
70
+
71
+ it("returns empty array when no inputs", () => {
72
+ assert.deepEqual(parseInputRequests("no inputs"), []);
73
+ });
74
+ });
@@ -0,0 +1,41 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { cronToOnCalendar } from "../src/platform/linux.js";
4
+
5
+ describe("cronToOnCalendar", () => {
6
+ it("converts hourly cron", () => {
7
+ assert.equal(cronToOnCalendar("0 * * * *"), "*-*-* *:00:00");
8
+ });
9
+
10
+ it("converts daily cron", () => {
11
+ assert.equal(cronToOnCalendar("30 9 * * *"), "*-*-* 09:30:00");
12
+ });
13
+
14
+ it("converts weekly Monday cron", () => {
15
+ assert.equal(cronToOnCalendar("0 10 * * 1"), "Mon *-*-* 10:00:00");
16
+ });
17
+
18
+ it("converts weekly Sunday (day 0)", () => {
19
+ assert.equal(cronToOnCalendar("0 8 * * 0"), "Sun *-*-* 08:00:00");
20
+ });
21
+
22
+ it("converts weekly Sunday (day 7)", () => {
23
+ assert.equal(cronToOnCalendar("0 8 * * 7"), "Sun *-*-* 08:00:00");
24
+ });
25
+
26
+ it("converts monthly cron", () => {
27
+ assert.equal(cronToOnCalendar("0 14 15 * *"), "*-*-15 14:00:00");
28
+ });
29
+
30
+ it("pads single-digit hours and minutes", () => {
31
+ assert.equal(cronToOnCalendar("5 3 * * *"), "*-*-* 03:05:00");
32
+ });
33
+
34
+ it("throws on invalid cron expression", () => {
35
+ assert.throws(() => cronToOnCalendar("bad"), /Invalid cron/);
36
+ });
37
+
38
+ it("throws on too few fields", () => {
39
+ assert.throws(() => cronToOnCalendar("0 * *"), /Invalid cron/);
40
+ });
41
+ });
@@ -0,0 +1,35 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { generatePairingCode, PAIRING_EXPIRY_MS } from "../src/commands/pair.js";
4
+
5
+ describe("generatePairingCode", () => {
6
+ it("generates a 6-character code", () => {
7
+ const code = generatePairingCode();
8
+ assert.equal(code.length, 6);
9
+ });
10
+
11
+ it("only contains allowed characters (no O/0/I/1/L)", () => {
12
+ const allowed = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
13
+ for (let i = 0; i < 50; i++) {
14
+ const code = generatePairingCode();
15
+ for (const ch of code) {
16
+ assert.ok(allowed.includes(ch), `Character '${ch}' is not in allowed set`);
17
+ }
18
+ }
19
+ });
20
+
21
+ it("generates unique codes", () => {
22
+ const codes = new Set<string>();
23
+ for (let i = 0; i < 100; i++) {
24
+ codes.add(generatePairingCode());
25
+ }
26
+ // With 30^6 ≈ 729M possibilities, 100 codes should all be unique
27
+ assert.equal(codes.size, 100);
28
+ });
29
+ });
30
+
31
+ describe("PAIRING_EXPIRY_MS", () => {
32
+ it("is 5 minutes", () => {
33
+ assert.equal(PAIRING_EXPIRY_MS, 5 * 60 * 1000);
34
+ });
35
+ });
@@ -0,0 +1,83 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { parseTaskContent } from "../src/task.js";
4
+
5
+ describe("parseTaskContent", () => {
6
+ it("parses valid frontmatter and body", () => {
7
+ const content = `---
8
+ id: abc123
9
+ name: Test Task
10
+ user_prompt: Do something
11
+ agent: claude
12
+ triggers: []
13
+ triggers_enabled: true
14
+ requires_confirmation: false
15
+ ---
16
+ This is the task body.`;
17
+
18
+ const result = parseTaskContent(content);
19
+ assert.equal(result.frontmatter.id, "abc123");
20
+ assert.equal(result.frontmatter.name, "Test Task");
21
+ assert.equal(result.frontmatter.agent, "claude");
22
+ assert.equal(result.body, "This is the task body.");
23
+ });
24
+
25
+ it("defaults agent to claude when not specified", () => {
26
+ const content = `---
27
+ id: abc123
28
+ user_prompt: Do something
29
+ triggers: []
30
+ triggers_enabled: true
31
+ requires_confirmation: false
32
+ ---`;
33
+
34
+ const result = parseTaskContent(content);
35
+ assert.equal(result.frontmatter.agent, "claude");
36
+ });
37
+
38
+ it("defaults triggers_enabled to true", () => {
39
+ const content = `---
40
+ id: abc123
41
+ user_prompt: Do something
42
+ triggers: []
43
+ requires_confirmation: false
44
+ ---`;
45
+
46
+ const result = parseTaskContent(content);
47
+ assert.equal(result.frontmatter.triggers_enabled, true);
48
+ });
49
+
50
+ it("derives name from user_prompt when not specified", () => {
51
+ const content = `---
52
+ id: abc123
53
+ user_prompt: A very long prompt that should be truncated to sixty characters maximum length here
54
+ triggers: []
55
+ triggers_enabled: true
56
+ requires_confirmation: false
57
+ ---`;
58
+
59
+ const result = parseTaskContent(content);
60
+ assert.equal(result.frontmatter.name.length, 60);
61
+ });
62
+
63
+ it("throws on missing frontmatter delimiters", () => {
64
+ assert.throws(() => parseTaskContent("no frontmatter here"), /missing valid YAML/);
65
+ });
66
+
67
+ it("throws on missing id", () => {
68
+ assert.throws(() => parseTaskContent("---\nname: test\n---\n"), /must include at least: id/);
69
+ });
70
+
71
+ it("handles empty body", () => {
72
+ const content = `---
73
+ id: abc123
74
+ user_prompt: test
75
+ triggers: []
76
+ triggers_enabled: true
77
+ requires_confirmation: false
78
+ ---`;
79
+
80
+ const result = parseTaskContent(content);
81
+ assert.equal(result.body, "");
82
+ });
83
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "..",
5
+ "noEmit": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["./**/*", "../src/**/*"]
9
+ }
@@ -0,0 +1,88 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { triggerToXml, buildTaskXml } from "../src/platform/windows.js";
4
+
5
+ describe("triggerToXml", () => {
6
+ it("converts a once trigger to TimeTrigger", () => {
7
+ const xml = triggerToXml({ type: "once", value: "2026-03-28T09:00" });
8
+ assert.equal(xml, "<TimeTrigger><StartBoundary>2026-03-28T09:00:00</StartBoundary></TimeTrigger>");
9
+ });
10
+
11
+ it("converts hourly cron to TimeTrigger with PT1H repetition", () => {
12
+ const xml = triggerToXml({ type: "cron", value: "0 * * * *" });
13
+ assert.ok(xml.includes("<Interval>PT1H</Interval>"), "should have hourly interval");
14
+ assert.ok(xml.includes("<TimeTrigger>"), "should be a TimeTrigger");
15
+ });
16
+
17
+ it("converts daily cron to CalendarTrigger with DaysInterval", () => {
18
+ const xml = triggerToXml({ type: "cron", value: "30 9 * * *" });
19
+ assert.ok(xml.includes("<ScheduleByDay>"), "should use ScheduleByDay");
20
+ assert.ok(xml.includes("<DaysInterval>1</DaysInterval>"), "should have interval 1");
21
+ assert.ok(xml.includes("T09:30:00"), "should encode time as 09:30");
22
+ });
23
+
24
+ it("converts weekly cron to CalendarTrigger with DaysOfWeek", () => {
25
+ const xml = triggerToXml({ type: "cron", value: "0 10 * * 1" });
26
+ assert.ok(xml.includes("<ScheduleByWeek>"), "should use ScheduleByWeek");
27
+ assert.ok(xml.includes("<Monday />"), "day 1 should be Monday");
28
+ assert.ok(xml.includes("T10:00:00"), "should encode time as 10:00");
29
+ });
30
+
31
+ it("converts weekly cron for Sunday (day 0)", () => {
32
+ const xml = triggerToXml({ type: "cron", value: "0 8 * * 0" });
33
+ assert.ok(xml.includes("<Sunday />"), "day 0 should be Sunday");
34
+ });
35
+
36
+ it("converts weekly cron for Sunday (day 7)", () => {
37
+ const xml = triggerToXml({ type: "cron", value: "0 8 * * 7" });
38
+ assert.ok(xml.includes("<Sunday />"), "day 7 should also be Sunday");
39
+ });
40
+
41
+ it("converts monthly cron to CalendarTrigger with DaysOfMonth", () => {
42
+ const xml = triggerToXml({ type: "cron", value: "0 14 15 * *" });
43
+ assert.ok(xml.includes("<ScheduleByMonth>"), "should use ScheduleByMonth");
44
+ assert.ok(xml.includes("<Day>15</Day>"), "should have day 15");
45
+ assert.ok(xml.includes("T14:00:00"), "should encode time as 14:00");
46
+ // All months should be listed
47
+ assert.ok(xml.includes("<January />"), "should include January");
48
+ assert.ok(xml.includes("<December />"), "should include December");
49
+ });
50
+
51
+ it("throws on invalid cron expression", () => {
52
+ assert.throws(() => triggerToXml({ type: "cron", value: "bad" }), /Invalid cron/);
53
+ });
54
+ });
55
+
56
+ describe("buildTaskXml", () => {
57
+ it("produces valid XML structure with StopExisting policy", () => {
58
+ const tr = '"C:\\Program Files\\nodejs\\node.exe" "C:\\palmier\\dist\\index.js" run abc123';
59
+ const triggers = ['<TimeTrigger><StartBoundary>2000-01-01T00:00:00</StartBoundary></TimeTrigger>'];
60
+ const xml = buildTaskXml(tr, triggers);
61
+
62
+ assert.ok(xml.includes('<?xml version="1.0" encoding="UTF-16"?>'), "should have XML declaration");
63
+ assert.ok(xml.includes("<MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>"), "should set StopExisting");
64
+ assert.ok(xml.includes("<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>"), "should allow on battery");
65
+ assert.ok(xml.includes("<Command>C:\\Program Files\\nodejs\\node.exe</Command>"), "should extract command");
66
+ assert.ok(xml.includes("<Arguments>C:\\palmier\\dist\\index.js run abc123</Arguments>"), "should extract arguments");
67
+ });
68
+
69
+ it("handles multiple triggers", () => {
70
+ const tr = '"node" "palmier" run test';
71
+ const triggers = [
72
+ '<TimeTrigger><StartBoundary>2000-01-01T09:00:00</StartBoundary></TimeTrigger>',
73
+ '<CalendarTrigger><StartBoundary>2000-01-01T14:00:00</StartBoundary></CalendarTrigger>',
74
+ ];
75
+ const xml = buildTaskXml(tr, triggers);
76
+
77
+ assert.ok(xml.includes("<Triggers><TimeTrigger>"), "should contain first trigger");
78
+ assert.ok(xml.includes("</TimeTrigger><CalendarTrigger>"), "triggers should be concatenated");
79
+ });
80
+
81
+ it("parses command with spaces in path", () => {
82
+ const tr = '"C:\\Program Files\\nodejs\\node.exe" "C:\\My Folder\\script.js" serve';
83
+ const xml = buildTaskXml(tr, []);
84
+
85
+ assert.ok(xml.includes("<Command>C:\\Program Files\\nodejs\\node.exe</Command>"));
86
+ assert.ok(xml.includes("<Arguments>C:\\My Folder\\script.js serve</Arguments>"));
87
+ });
88
+ });
@@ -1,2 +0,0 @@
1
- export declare function agentsCommand(): Promise<void>;
2
- //# sourceMappingURL=agents.d.ts.map
@@ -1,30 +0,0 @@
1
- import { loadConfig, saveConfig } from "../config.js";
2
- import { detectAgents } from "../agents/agent.js";
3
- import { getPlatform } from "../platform/index.js";
4
- export async function agentsCommand() {
5
- const config = loadConfig();
6
- const oldKeys = (config.agents ?? []).map((a) => a.key).sort().join(",");
7
- console.log("Detecting installed agents...");
8
- const agents = await detectAgents();
9
- config.agents = agents;
10
- saveConfig(config);
11
- if (agents.length === 0) {
12
- console.log("No agent CLIs detected.");
13
- }
14
- else {
15
- console.log("Detected agents:");
16
- for (const a of agents) {
17
- console.log(` ${a.key} — ${a.label}`);
18
- }
19
- }
20
- // Restart daemon if agent list changed so the UI picks it up immediately
21
- const newKeys = agents.map((a) => a.key).sort().join(",");
22
- if (newKeys !== oldKeys) {
23
- try {
24
- console.log("Agent list changed, restarting daemon...");
25
- await getPlatform().restartDaemon();
26
- }
27
- catch { /* daemon may not be running yet */ }
28
- }
29
- }
30
- //# sourceMappingURL=agents.js.map
@@ -1,31 +0,0 @@
1
- import { loadConfig, saveConfig } from "../config.js";
2
- import { detectAgents } from "../agents/agent.js";
3
- import { getPlatform } from "../platform/index.js";
4
-
5
- export async function agentsCommand(): Promise<void> {
6
- const config = loadConfig();
7
- const oldKeys = (config.agents ?? []).map((a) => a.key).sort().join(",");
8
-
9
- console.log("Detecting installed agents...");
10
- const agents = await detectAgents();
11
- config.agents = agents;
12
- saveConfig(config);
13
-
14
- if (agents.length === 0) {
15
- console.log("No agent CLIs detected.");
16
- } else {
17
- console.log("Detected agents:");
18
- for (const a of agents) {
19
- console.log(` ${a.key} — ${a.label}`);
20
- }
21
- }
22
-
23
- // Restart daemon if agent list changed so the UI picks it up immediately
24
- const newKeys = agents.map((a) => a.key).sort().join(",");
25
- if (newKeys !== oldKeys) {
26
- try {
27
- console.log("Agent list changed, restarting daemon...");
28
- await getPlatform().restartDaemon();
29
- } catch { /* daemon may not be running yet */ }
30
- }
31
- }