palmier 0.3.4 → 0.3.5
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/.github/workflows/ci.yml +1 -1
- package/dist/agents/copilot.js +1 -1
- package/dist/commands/run.d.ts +21 -0
- package/dist/commands/run.js +4 -4
- package/dist/platform/linux.d.ts +12 -0
- package/dist/platform/linux.js +1 -1
- package/dist/platform/windows.d.ts +17 -0
- package/dist/platform/windows.js +2 -2
- package/dist/task.d.ts +4 -0
- package/dist/task.js +1 -1
- package/package.json +2 -1
- package/src/agents/copilot.ts +1 -1
- package/src/commands/run.ts +4 -4
- package/src/platform/linux.ts +1 -1
- package/src/platform/windows.ts +2 -2
- package/src/task.ts +1 -1
- package/test/agent-output-parsing.test.ts +74 -0
- package/test/linux-cron.test.ts +41 -0
- package/test/pairing.test.ts +35 -0
- package/test/task-parsing.test.ts +83 -0
- package/test/tsconfig.json +9 -0
- package/test/windows-xml.test.ts +88 -0
package/.github/workflows/ci.yml
CHANGED
package/dist/agents/copilot.js
CHANGED
package/dist/commands/run.d.ts
CHANGED
|
@@ -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
|
package/dist/commands/run.js
CHANGED
|
@@ -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";
|
package/dist/platform/linux.d.ts
CHANGED
|
@@ -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>;
|
package/dist/platform/linux.js
CHANGED
|
@@ -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>;
|
package/dist/platform/windows.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.3.5",
|
|
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
|
},
|
package/src/agents/copilot.ts
CHANGED
package/src/commands/run.ts
CHANGED
|
@@ -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";
|
package/src/platform/linux.ts
CHANGED
|
@@ -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}`);
|
package/src/platform/windows.ts
CHANGED
|
@@ -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,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
|
+
});
|