palmier 0.2.6 → 0.2.8

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.
Files changed (46) hide show
  1. package/.github/workflows/publish.yml +24 -0
  2. package/CLAUDE.md +9 -9
  3. package/README.md +288 -288
  4. package/dist/agents/shared-prompt.js +16 -16
  5. package/dist/commands/info.js +0 -22
  6. package/dist/commands/init.js +27 -123
  7. package/dist/commands/lan.d.ts +8 -0
  8. package/dist/commands/lan.js +51 -0
  9. package/dist/commands/mcpserver.js +2 -7
  10. package/dist/commands/pair.d.ts +1 -1
  11. package/dist/commands/pair.js +52 -56
  12. package/dist/commands/run.js +36 -41
  13. package/dist/commands/serve.d.ts +1 -1
  14. package/dist/commands/serve.js +14 -33
  15. package/dist/config.js +3 -17
  16. package/dist/events.d.ts +3 -4
  17. package/dist/events.js +25 -8
  18. package/dist/index.js +8 -0
  19. package/dist/rpc-handler.js +5 -29
  20. package/dist/transports/http-transport.d.ts +1 -1
  21. package/dist/transports/http-transport.js +103 -18
  22. package/dist/types.d.ts +1 -3
  23. package/package.json +44 -36
  24. package/src/agents/claude.ts +44 -44
  25. package/src/agents/shared-prompt.ts +28 -28
  26. package/src/commands/info.ts +0 -24
  27. package/src/commands/init.ts +29 -150
  28. package/src/commands/lan.ts +58 -0
  29. package/src/commands/mcpserver.ts +2 -10
  30. package/src/commands/pair.ts +50 -63
  31. package/src/commands/run.ts +619 -633
  32. package/src/commands/serve.ts +14 -31
  33. package/src/config.ts +3 -18
  34. package/src/events.ts +23 -10
  35. package/src/index.ts +9 -0
  36. package/src/nats-client.ts +15 -15
  37. package/src/rpc-handler.ts +388 -414
  38. package/src/transports/http-transport.ts +123 -19
  39. package/src/types.ts +62 -66
  40. package/dist/commands/hook.d.ts +0 -7
  41. package/dist/commands/hook.js +0 -208
  42. package/dist/commands/task-cleanup.d.ts +0 -14
  43. package/dist/commands/task-cleanup.js +0 -84
  44. package/dist/commands/task-generation.md +0 -28
  45. package/dist/systemd.d.ts +0 -20
  46. package/dist/systemd.js +0 -145
package/dist/systemd.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { HostConfig } from "./types.js";
2
- import type { ParsedTask } from "./types.js";
3
- /**
4
- * Convert a cron expression (5-field) to a systemd OnCalendar string.
5
- * Handles basic cron patterns: minute hour day-of-month month day-of-week
6
- */
7
- export declare function cronToOnCalendar(cron: string): string;
8
- /**
9
- * Install a systemd user timer + service for a task.
10
- */
11
- export declare function installTaskTimer(config: HostConfig, task: ParsedTask): void;
12
- /**
13
- * Remove a task's systemd timer and service files.
14
- */
15
- export declare function removeTaskTimer(taskId: string): void;
16
- /**
17
- * Run systemctl --user daemon-reload.
18
- */
19
- export declare function daemonReload(): void;
20
- //# sourceMappingURL=systemd.d.ts.map
package/dist/systemd.js DELETED
@@ -1,145 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import { homedir } from "os";
4
- import { execSync } from "child_process";
5
- const UNIT_DIR = path.join(homedir(), ".config", "systemd", "user");
6
- function getTimerName(taskId) {
7
- return `palmier-task-${taskId}.timer`;
8
- }
9
- function getServiceName(taskId) {
10
- return `palmier-task-${taskId}.service`;
11
- }
12
- /**
13
- * Convert a cron expression (5-field) to a systemd OnCalendar string.
14
- * Handles basic cron patterns: minute hour day-of-month month day-of-week
15
- */
16
- export function cronToOnCalendar(cron) {
17
- const parts = cron.trim().split(/\s+/);
18
- if (parts.length !== 5) {
19
- throw new Error(`Invalid cron expression (expected 5 fields): ${cron}`);
20
- }
21
- const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
22
- // Map cron day-of-week names/numbers to systemd abbreviated names
23
- const dowMap = {
24
- "0": "Sun",
25
- "1": "Mon",
26
- "2": "Tue",
27
- "3": "Wed",
28
- "4": "Thu",
29
- "5": "Fri",
30
- "6": "Sat",
31
- "7": "Sun",
32
- };
33
- // Convert day-of-week
34
- let dow = dayOfWeek === "*" ? "*" : dayOfWeek;
35
- if (dowMap[dow]) {
36
- dow = dowMap[dow];
37
- }
38
- // Build OnCalendar string
39
- // Format: DayOfWeek Year-Month-Day Hour:Minute:Second
40
- const monthPart = month === "*" ? "*" : month.padStart(2, "0");
41
- const dayPart = dayOfMonth === "*" ? "*" : dayOfMonth.padStart(2, "0");
42
- const hourPart = hour === "*" ? "*" : hour.padStart(2, "0");
43
- const minutePart = minute === "*" ? "*" : minute.padStart(2, "0");
44
- if (dow === "*") {
45
- return `*-${monthPart}-${dayPart} ${hourPart}:${minutePart}:00`;
46
- }
47
- return `${dow} *-${monthPart}-${dayPart} ${hourPart}:${minutePart}:00`;
48
- }
49
- /**
50
- * Install a systemd user timer + service for a task.
51
- */
52
- export function installTaskTimer(config, task) {
53
- fs.mkdirSync(UNIT_DIR, { recursive: true });
54
- const taskId = task.frontmatter.id;
55
- const serviceName = getServiceName(taskId);
56
- const timerName = getTimerName(taskId);
57
- // Determine the palmier binary path
58
- const palmierBin = process.argv[1] || "palmier";
59
- // Generate service unit
60
- const serviceContent = `[Unit]
61
- Description=Palmier Task: ${taskId}
62
-
63
- [Service]
64
- Type=oneshot
65
- ExecStart=${palmierBin} run ${taskId}
66
- WorkingDirectory=${config.projectRoot}
67
- Environment=PATH=${process.env.PATH || "/usr/local/bin:/usr/bin:/bin"}
68
- `;
69
- // Write service unit (always needed for on-demand runs)
70
- fs.writeFileSync(path.join(UNIT_DIR, serviceName), serviceContent, "utf-8");
71
- daemonReload();
72
- // Only create and enable a timer if there are actual triggers
73
- const triggers = task.frontmatter.triggers || [];
74
- const onCalendarLines = [];
75
- for (const trigger of triggers) {
76
- if (trigger.type === "cron") {
77
- onCalendarLines.push(`OnCalendar=${cronToOnCalendar(trigger.value)}`);
78
- }
79
- else if (trigger.type === "once") {
80
- onCalendarLines.push(`OnActiveSec=${trigger.value}`);
81
- }
82
- }
83
- if (onCalendarLines.length > 0) {
84
- const timerContent = `[Unit]
85
- Description=Timer for Palmier Task: ${taskId}
86
-
87
- [Timer]
88
- ${onCalendarLines.join("\n")}
89
- Persistent=true
90
-
91
- [Install]
92
- WantedBy=timers.target
93
- `;
94
- fs.writeFileSync(path.join(UNIT_DIR, timerName), timerContent, "utf-8");
95
- daemonReload();
96
- try {
97
- execSync(`systemctl --user enable --now ${timerName}`, { encoding: "utf-8" });
98
- }
99
- catch (err) {
100
- const e = err;
101
- console.error(`Failed to enable timer ${timerName}: ${e.stderr || err}`);
102
- }
103
- }
104
- }
105
- /**
106
- * Remove a task's systemd timer and service files.
107
- */
108
- export function removeTaskTimer(taskId) {
109
- const timerName = getTimerName(taskId);
110
- const serviceName = getServiceName(taskId);
111
- const timerPath = path.join(UNIT_DIR, timerName);
112
- const servicePath = path.join(UNIT_DIR, serviceName);
113
- // Only stop/disable the timer if the file exists
114
- if (fs.existsSync(timerPath)) {
115
- try {
116
- execSync(`systemctl --user stop ${timerName}`, { encoding: "utf-8" });
117
- }
118
- catch {
119
- // Timer might not be running
120
- }
121
- try {
122
- execSync(`systemctl --user disable ${timerName}`, { encoding: "utf-8" });
123
- }
124
- catch {
125
- // Timer might not be enabled
126
- }
127
- fs.unlinkSync(timerPath);
128
- }
129
- if (fs.existsSync(servicePath))
130
- fs.unlinkSync(servicePath);
131
- daemonReload();
132
- }
133
- /**
134
- * Run systemctl --user daemon-reload.
135
- */
136
- export function daemonReload() {
137
- try {
138
- execSync("systemctl --user daemon-reload", { encoding: "utf-8" });
139
- }
140
- catch (err) {
141
- const e = err;
142
- console.error(`daemon-reload failed: ${e.stderr || err}`);
143
- }
144
- }
145
- //# sourceMappingURL=systemd.js.map