palmier 0.5.2 → 0.5.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.
Files changed (46) hide show
  1. package/README.md +9 -9
  2. package/dist/agents/agent-instructions.md +7 -7
  3. package/dist/agents/shared-prompt.js +1 -1
  4. package/dist/client-store.d.ts +12 -0
  5. package/dist/client-store.js +57 -0
  6. package/dist/commands/clients.d.ts +4 -0
  7. package/dist/commands/clients.js +27 -0
  8. package/dist/commands/info.js +5 -5
  9. package/dist/commands/init.js +1 -1
  10. package/dist/commands/pair.js +4 -4
  11. package/dist/commands/run.js +9 -5
  12. package/dist/commands/serve.js +1 -1
  13. package/dist/events.js +1 -1
  14. package/dist/index.js +13 -13
  15. package/dist/platform/windows.d.ts +1 -1
  16. package/dist/platform/windows.js +33 -29
  17. package/dist/rpc-handler.js +7 -4
  18. package/dist/transports/http-transport.js +7 -7
  19. package/dist/transports/nats-transport.js +4 -4
  20. package/dist/types.d.ts +2 -2
  21. package/package.json +1 -1
  22. package/src/agents/agent-instructions.md +7 -7
  23. package/src/agents/shared-prompt.ts +1 -1
  24. package/src/client-store.ts +68 -0
  25. package/src/commands/clients.ts +29 -0
  26. package/src/commands/info.ts +5 -5
  27. package/src/commands/init.ts +1 -1
  28. package/src/commands/pair.ts +4 -4
  29. package/src/commands/run.ts +8 -5
  30. package/src/commands/serve.ts +1 -1
  31. package/src/events.ts +1 -1
  32. package/src/index.ts +13 -13
  33. package/src/platform/windows.ts +29 -29
  34. package/src/rpc-handler.ts +7 -4
  35. package/src/transports/http-transport.ts +7 -7
  36. package/src/transports/nats-transport.ts +4 -4
  37. package/src/types.ts +3 -3
  38. package/test/agent-instructions.test.ts +22 -5
  39. package/test/agent-output-parsing.test.ts +12 -0
  40. package/test/windows-xml.test.ts +2 -0
  41. package/dist/commands/sessions.d.ts +0 -4
  42. package/dist/commands/sessions.js +0 -27
  43. package/dist/session-store.d.ts +0 -12
  44. package/dist/session-store.js +0 -57
  45. package/src/commands/sessions.ts +0 -29
  46. package/src/session-store.ts +0 -68
package/README.md CHANGED
@@ -46,9 +46,9 @@ All `palmier` commands should be run from a dedicated Palmier root directory (e.
46
46
  |---|---|
47
47
  | `palmier init` | Interactive setup wizard |
48
48
  | `palmier pair` | Generate an OTP code to pair a new device |
49
- | `palmier sessions list` | List active session tokens |
50
- | `palmier sessions revoke <token>` | Revoke a specific session token |
51
- | `palmier sessions revoke-all` | Revoke all session tokens |
49
+ | `palmier clients list` | List active client tokens |
50
+ | `palmier clients revoke <token>` | Revoke a specific client token |
51
+ | `palmier clients revoke-all` | Revoke all client tokens |
52
52
  | `palmier info` | Show host connection info (address, mode) |
53
53
  | `palmier serve` | Run the persistent RPC handler (default command) |
54
54
  | `palmier restart` | Restart the palmier serve daemon |
@@ -70,17 +70,17 @@ Local access (`http://localhost:<port>`) works immediately — no pairing needed
70
70
 
71
71
  For LAN or server mode, run `palmier pair` on the host to generate an OTP code. Enter it in the PWA — either at `http://<host-ip>:<port>` (LAN mode) or `https://app.palmier.me` (server mode).
72
72
 
73
- ### Managing sessions
73
+ ### Managing clients
74
74
 
75
75
  ```bash
76
76
  # List all paired devices
77
- palmier sessions list
77
+ palmier clients list
78
78
 
79
79
  # Revoke a specific device's access
80
- palmier sessions revoke <token>
80
+ palmier clients revoke <token>
81
81
 
82
- # Revoke all sessions (unpair all devices)
83
- palmier sessions revoke-all
82
+ # Revoke all clients (unpair all devices)
83
+ palmier clients revoke-all
84
84
  ```
85
85
 
86
86
  The `init` command:
@@ -126,7 +126,7 @@ palmier restart
126
126
  ## How It Works
127
127
 
128
128
  - The host runs as a **background daemon** (systemd user service on Linux, Registry Run key on Windows), staying alive via `palmier serve`.
129
- - **Device access** — localhost is always trusted (no pairing needed). LAN and server mode devices communicate via direct HTTP or NATS respectively, and must pair via OTP to get a session token.
129
+ - **Device access** — localhost is always trusted (no pairing needed). LAN and server mode devices communicate via direct HTTP or NATS respectively, and must pair via OTP to get a client token.
130
130
  - **Tasks** are stored locally as Markdown files in a `tasks/` directory. Each task has a name, prompt, execution plan, and optional schedules (cron schedules or one-time dates).
131
131
  - **Plan generation** is automatic — when you create or update a task, the host invokes your chosen agent CLI to generate an execution plan and name.
132
132
  - **Schedules** are backed by systemd timers (Linux) or Task Scheduler (Windows). You can enable/disable them without deleting the task, and any task can still be run manually at any time.
@@ -2,19 +2,19 @@ You are an AI agent executing a task on behalf of the user via the Palmier platf
2
2
 
3
3
  ## Reporting Output
4
4
 
5
- If you generate report or output files, print each file path on its own line using this exact format (no code block):
6
- `[PALMIER_REPORT] <filename>`
5
+ If you generate report or output files, print each file path on its own line using this exact format:
6
+ [PALMIER_REPORT] <filename>
7
7
 
8
8
  ## Completion
9
9
 
10
- When you are done, output exactly one of these markers as the very last line (no code block, no other text on the same line):
11
- - Success: `[PALMIER_TASK_SUCCESS]`
12
- - Failure: `[PALMIER_TASK_FAILURE]`
10
+ When you are done, output exactly one of these markers as the very last line (no other text on the same line):
11
+ [PALMIER_TASK_SUCCESS]
12
+ [PALMIER_TASK_FAILURE]
13
13
 
14
14
  ## Permissions
15
15
 
16
- If the task fails because a tool was denied or you lack the required permissions, print each required permission on its own line using this exact format (no code block):
17
- `[PALMIER_PERMISSION] <tool_name> | <description>`
16
+ If the task fails because a tool was denied or you lack the required permissions, print each required permission on its own line using this exact format:
17
+ [PALMIER_PERMISSION] <tool_name> | <description>
18
18
 
19
19
  ## HTTP Endpoints
20
20
 
@@ -8,7 +8,7 @@ const AGENT_INSTRUCTIONS_TEMPLATE = fs.readFileSync(path.join(__dirname, "agent-
8
8
  * Agent instructions with the serve daemon's HTTP port and task ID baked in.
9
9
  */
10
10
  export function getAgentInstructions(taskId, skipPermissions) {
11
- const port = loadConfig().httpPort ?? 7400;
11
+ const port = loadConfig().httpPort ?? 9966;
12
12
  let instructions = AGENT_INSTRUCTIONS_TEMPLATE
13
13
  .replace(/\{\{PORT\}\}/g, String(port))
14
14
  .replace(/\{\{TASK_ID\}\}/g, taskId);
@@ -0,0 +1,12 @@
1
+ export interface ClientEntry {
2
+ token: string;
3
+ createdAt: string;
4
+ label?: string;
5
+ }
6
+ export declare function loadClients(): ClientEntry[];
7
+ export declare function addClient(label?: string): ClientEntry;
8
+ export declare function revokeClient(token: string): boolean;
9
+ export declare function revokeAllClients(): number;
10
+ export declare function validateClient(token: string): boolean;
11
+ export declare function hasClients(): boolean;
12
+ //# sourceMappingURL=client-store.d.ts.map
@@ -0,0 +1,57 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { randomBytes } from "crypto";
4
+ import { CONFIG_DIR } from "./config.js";
5
+ const CLIENTS_FILE = path.join(CONFIG_DIR, "clients.json");
6
+ function readFile() {
7
+ try {
8
+ if (!fs.existsSync(CLIENTS_FILE))
9
+ return [];
10
+ const raw = fs.readFileSync(CLIENTS_FILE, "utf-8");
11
+ return JSON.parse(raw);
12
+ }
13
+ catch {
14
+ return [];
15
+ }
16
+ }
17
+ function writeFile(clients) {
18
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
19
+ fs.writeFileSync(CLIENTS_FILE, JSON.stringify(clients, null, 2), "utf-8");
20
+ }
21
+ export function loadClients() {
22
+ return readFile();
23
+ }
24
+ export function addClient(label) {
25
+ const clients = readFile();
26
+ const entry = {
27
+ token: randomBytes(32).toString("hex"),
28
+ createdAt: new Date().toISOString(),
29
+ ...(label ? { label } : {}),
30
+ };
31
+ clients.push(entry);
32
+ writeFile(clients);
33
+ return entry;
34
+ }
35
+ export function revokeClient(token) {
36
+ const clients = readFile();
37
+ const idx = clients.findIndex((c) => c.token === token);
38
+ if (idx === -1)
39
+ return false;
40
+ clients.splice(idx, 1);
41
+ writeFile(clients);
42
+ return true;
43
+ }
44
+ export function revokeAllClients() {
45
+ const clients = readFile();
46
+ const count = clients.length;
47
+ writeFile([]);
48
+ return count;
49
+ }
50
+ export function validateClient(token) {
51
+ const clients = readFile();
52
+ return clients.some((c) => c.token === token);
53
+ }
54
+ export function hasClients() {
55
+ return readFile().length > 0;
56
+ }
57
+ //# sourceMappingURL=client-store.js.map
@@ -0,0 +1,4 @@
1
+ export declare function clientsListCommand(): Promise<void>;
2
+ export declare function clientsRevokeCommand(token: string): Promise<void>;
3
+ export declare function clientsRevokeAllCommand(): Promise<void>;
4
+ //# sourceMappingURL=clients.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { loadClients, revokeClient, revokeAllClients } from "../client-store.js";
2
+ export async function clientsListCommand() {
3
+ const clients = loadClients();
4
+ if (clients.length === 0) {
5
+ console.log("No active clients.");
6
+ return;
7
+ }
8
+ console.log(`${clients.length} active client(s):\n`);
9
+ for (const c of clients) {
10
+ const label = c.label ? ` (${c.label})` : "";
11
+ console.log(` ${c.token}${label} created ${c.createdAt}`);
12
+ }
13
+ }
14
+ export async function clientsRevokeCommand(token) {
15
+ if (revokeClient(token)) {
16
+ console.log("Client revoked.");
17
+ }
18
+ else {
19
+ console.error("Client not found.");
20
+ process.exit(1);
21
+ }
22
+ }
23
+ export async function clientsRevokeAllCommand() {
24
+ const count = revokeAllClients();
25
+ console.log(`Revoked ${count} client(s).`);
26
+ }
27
+ //# sourceMappingURL=clients.js.map
@@ -1,11 +1,11 @@
1
1
  import { loadConfig } from "../config.js";
2
- import { loadSessions } from "../session-store.js";
2
+ import { loadClients } from "../client-store.js";
3
3
  /**
4
4
  * Print host connection info for setting up clients.
5
5
  */
6
6
  export async function infoCommand() {
7
7
  const config = loadConfig();
8
- const sessions = loadSessions();
8
+ const clients = loadClients();
9
9
  console.log(`Host ID: ${config.hostId}`);
10
10
  console.log(`Project root: ${config.projectRoot}`);
11
11
  // Detected agents
@@ -15,9 +15,9 @@ export async function infoCommand() {
15
15
  else {
16
16
  console.log(`Agents: (none detected — run \`palmier agents\`)`);
17
17
  }
18
- // Sessions
19
- console.log(`Sessions: ${sessions.length} active`);
20
- if (sessions.length === 0) {
18
+ // Clients
19
+ console.log(`Clients: ${clients.length} active`);
20
+ if (clients.length === 0) {
21
21
  console.log("");
22
22
  console.log("No paired clients. Run `palmier pair` to connect a device.");
23
23
  }
@@ -33,7 +33,7 @@ export async function initCommand() {
33
33
  // LAN mode
34
34
  const lanAnswer = await ask("Enable LAN access (direct HTTP from local network)? (y/N): ");
35
35
  const lanEnabled = lanAnswer.trim().toLowerCase() === "y";
36
- let httpPort = 7400;
36
+ let httpPort = 9966;
37
37
  const portLabel = lanEnabled ? "HTTP port for local and LAN access" : "HTTP port for local access";
38
38
  const portAnswer = await ask(`${portLabel} (default ${httpPort}): `);
39
39
  const parsed = parseInt(portAnswer.trim(), 10);
@@ -2,7 +2,7 @@ import * as http from "node:http";
2
2
  import { StringCodec } from "nats";
3
3
  import { loadConfig } from "../config.js";
4
4
  import { connectNats } from "../nats-client.js";
5
- import { addSession } from "../session-store.js";
5
+ import { addClient } from "../client-store.js";
6
6
  const CODE_CHARS = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"; // no O/0/I/1/L
7
7
  const CODE_LENGTH = 6;
8
8
  export const PAIRING_EXPIRY_MS = 5 * 60 * 1000; // 5 minutes
@@ -12,10 +12,10 @@ export function generatePairingCode() {
12
12
  return Array.from(bytes, (b) => CODE_CHARS[b % CODE_CHARS.length]).join("");
13
13
  }
14
14
  function buildPairResponse(config, label) {
15
- const session = addSession(label);
15
+ const client = addClient(label);
16
16
  return {
17
17
  hostId: config.hostId,
18
- sessionToken: session.token,
18
+ clientToken: client.token,
19
19
  };
20
20
  }
21
21
  /**
@@ -56,7 +56,7 @@ function httpPairRegister(port, code) {
56
56
  export async function pairCommand() {
57
57
  const config = loadConfig();
58
58
  const code = generatePairingCode();
59
- const httpPort = config.httpPort ?? 7400;
59
+ const httpPort = config.httpPort ?? 9966;
60
60
  let paired = false;
61
61
  function onPaired() {
62
62
  paired = true;
@@ -39,7 +39,7 @@ async function invokeAgentWithRetries(ctx, invokeTask) {
39
39
  console.log(`[invoke] ${command} ${displayArgs.join(" ")}${stdin ? ` (stdin: ${truncate(stdin, 100)})` : ""}`);
40
40
  const result = await spawnCommand(command, args, {
41
41
  cwd: getRunDir(ctx.taskDir, ctx.runId),
42
- env: { ...ctx.guiEnv, PALMIER_TASK_ID: ctx.task.frontmatter.id, PALMIER_RUN_DIR: getRunDir(ctx.taskDir, ctx.runId), PALMIER_HTTP_PORT: String(ctx.config.httpPort ?? 7400) },
42
+ env: { ...ctx.guiEnv, PALMIER_TASK_ID: ctx.task.frontmatter.id, PALMIER_RUN_DIR: getRunDir(ctx.taskDir, ctx.runId), PALMIER_HTTP_PORT: String(ctx.config.httpPort ?? 9966) },
43
43
  echoStdout: true,
44
44
  resolveOnFailure: true,
45
45
  stdin,
@@ -248,7 +248,7 @@ async function runCommandTriggeredMode(ctx) {
248
248
  await publishHostEvent(ctx.nc, ctx.config.hostId, ctx.taskId, { event_type: "result-updated", run_id: ctx.runId });
249
249
  const child = spawnStreamingCommand(commandStr, {
250
250
  cwd: getRunDir(ctx.taskDir, ctx.runId),
251
- env: { ...ctx.guiEnv, PALMIER_TASK_ID: ctx.task.frontmatter.id, PALMIER_RUN_DIR: getRunDir(ctx.taskDir, ctx.runId), PALMIER_HTTP_PORT: String(ctx.config.httpPort ?? 7400) },
251
+ env: { ...ctx.guiEnv, PALMIER_TASK_ID: ctx.task.frontmatter.id, PALMIER_RUN_DIR: getRunDir(ctx.taskDir, ctx.runId), PALMIER_HTTP_PORT: String(ctx.config.httpPort ?? 9966) },
252
252
  });
253
253
  let linesProcessed = 0;
254
254
  let invocationsSucceeded = 0;
@@ -365,7 +365,7 @@ async function publishTaskEvent(nc, config, taskDir, taskId, eventType, taskName
365
365
  await publishHostEvent(nc, config.hostId, taskId, payload);
366
366
  }
367
367
  async function requestPermission(config, task, taskDir, requiredPermissions) {
368
- const port = config.httpPort ?? 7400;
368
+ const port = config.httpPort ?? 9966;
369
369
  const res = await fetch(`http://localhost:${port}/request-permission`, {
370
370
  method: "POST",
371
371
  headers: { "Content-Type": "application/json" },
@@ -387,7 +387,7 @@ async function requestPermission(config, task, taskDir, requiredPermissions) {
387
387
  return response;
388
388
  }
389
389
  async function requestConfirmation(config, task, taskDir) {
390
- const port = config.httpPort ?? 7400;
390
+ const port = config.httpPort ?? 9966;
391
391
  const res = await fetch(`http://localhost:${port}/request-confirmation`, {
392
392
  method: "POST",
393
393
  headers: { "Content-Type": "application/json" },
@@ -414,7 +414,8 @@ export function parseReportFiles(output) {
414
414
  let match;
415
415
  while ((match = regex.exec(output)) !== null) {
416
416
  const name = match[1].trim();
417
- if (name)
417
+ // Skip placeholder examples echoed from the prompt (e.g. "<filename>")
418
+ if (name && !name.startsWith("<"))
418
419
  files.push(name);
419
420
  }
420
421
  return files;
@@ -429,6 +430,9 @@ export function parsePermissions(output) {
429
430
  let match;
430
431
  while ((match = regex.exec(output)) !== null) {
431
432
  const raw = match[1].trim();
433
+ // Skip placeholder examples echoed from the prompt (e.g. "<tool_name> | <description>")
434
+ if (raw.startsWith("<"))
435
+ continue;
432
436
  const sep = raw.indexOf("|");
433
437
  if (sep !== -1) {
434
438
  perms.push({ name: raw.slice(0, sep).trim(), description: raw.slice(sep + 1).trim() });
@@ -99,7 +99,7 @@ export async function serveCommand() {
99
99
  });
100
100
  }, POLL_INTERVAL_MS);
101
101
  const handleRpc = createRpcHandler(config, nc);
102
- const httpPort = config.httpPort ?? 7400;
102
+ const httpPort = config.httpPort ?? 9966;
103
103
  // Start NATS transport (loops forever, fire-and-forget)
104
104
  if (nc) {
105
105
  startNatsTransport(config, handleRpc, nc);
package/dist/events.js CHANGED
@@ -14,7 +14,7 @@ export async function publishHostEvent(nc, hostId, taskId, payload) {
14
14
  console.log(`[nats] ${subject} →`, payload);
15
15
  }
16
16
  const config = loadConfig();
17
- const port = config.httpPort ?? 7400;
17
+ const port = config.httpPort ?? 9966;
18
18
  try {
19
19
  await fetch(`http://localhost:${port}/event`, {
20
20
  method: "POST",
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { runCommand } from "./commands/run.js";
10
10
  import { serveCommand } from "./commands/serve.js";
11
11
  import { pairCommand } from "./commands/pair.js";
12
12
  import { restartCommand } from "./commands/restart.js";
13
- import { sessionsListCommand, sessionsRevokeCommand, sessionsRevokeAllCommand } from "./commands/sessions.js";
13
+ import { clientsListCommand, clientsRevokeCommand, clientsRevokeAllCommand } from "./commands/clients.js";
14
14
  const __dirname = dirname(fileURLToPath(import.meta.url));
15
15
  const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
16
16
  const program = new Command();
@@ -54,26 +54,26 @@ program
54
54
  .action(async () => {
55
55
  await pairCommand();
56
56
  });
57
- const sessionsCmd = program
58
- .command("sessions")
59
- .description("Manage paired client sessions");
60
- sessionsCmd
57
+ const clientsCmd = program
58
+ .command("clients")
59
+ .description("Manage paired clients");
60
+ clientsCmd
61
61
  .command("list")
62
- .description("List active sessions")
62
+ .description("List active clients")
63
63
  .action(async () => {
64
- await sessionsListCommand();
64
+ await clientsListCommand();
65
65
  });
66
- sessionsCmd
66
+ clientsCmd
67
67
  .command("revoke <token>")
68
- .description("Revoke a session by token")
68
+ .description("Revoke a client by token")
69
69
  .action(async (token) => {
70
- await sessionsRevokeCommand(token);
70
+ await clientsRevokeCommand(token);
71
71
  });
72
- sessionsCmd
72
+ clientsCmd
73
73
  .command("revoke-all")
74
- .description("Revoke all sessions")
74
+ .description("Revoke all clients")
75
75
  .action(async () => {
76
- await sessionsRevokeAllCommand();
76
+ await clientsRevokeAllCommand();
77
77
  });
78
78
  // No subcommand → default to serve
79
79
  if (process.argv.length <= 2) {
@@ -20,7 +20,7 @@ export declare function buildTaskXml(tr: string, triggers: string[]): string;
20
20
  export declare class WindowsPlatform implements PlatformService {
21
21
  installDaemon(config: HostConfig): void;
22
22
  restartDaemon(): Promise<void>;
23
- /** Create or update the Task Scheduler entry for the daemon. */
23
+ /** Create or update the Task Scheduler entry for the daemon (requires elevation for S4U). */
24
24
  private ensureDaemonTask;
25
25
  /** Start the daemon via Task Scheduler (runs outside any session's job object). */
26
26
  private startDaemonTask;
@@ -6,7 +6,6 @@ import { getTaskDir, readTaskStatus } from "../task.js";
6
6
  const TASK_PREFIX = "\\Palmier\\PalmierTask-";
7
7
  const DAEMON_TASK_NAME = "PalmierDaemon";
8
8
  const DAEMON_PID_FILE = path.join(CONFIG_DIR, "daemon.pid");
9
- const DAEMON_VBS_FILE = path.join(CONFIG_DIR, "daemon.vbs");
10
9
  const DOW_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
11
10
  /**
12
11
  * Convert a cron expression or "once" trigger to Task Scheduler XML trigger elements.
@@ -55,6 +54,12 @@ export function buildTaskXml(tr, triggers) {
55
54
  return [
56
55
  `<?xml version="1.0" encoding="UTF-16"?>`,
57
56
  `<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">`,
57
+ ` <Principals>`,
58
+ ` <Principal>`,
59
+ ` <LogonType>S4U</LogonType>`,
60
+ ` <RunLevel>LeastPrivilege</RunLevel>`,
61
+ ` </Principal>`,
62
+ ` </Principals>`,
58
63
  ` <Settings>`,
59
64
  ` <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>`,
60
65
  ` <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>`,
@@ -77,22 +82,16 @@ function schtasksTaskName(taskId) {
77
82
  export class WindowsPlatform {
78
83
  installDaemon(config) {
79
84
  const script = process.argv[1] || "palmier";
80
- // Create the Task Scheduler entry for the daemon
85
+ // Create the Task Scheduler entry for the daemon (BootTrigger starts it at system boot)
81
86
  this.ensureDaemonTask(script);
82
- // Registry Run key triggers the Task Scheduler entry on logon,
83
- // so the daemon always runs outside any session's job object.
84
- const regValue = `schtasks /run /tn "\\Palmier\\${DAEMON_TASK_NAME}"`;
87
+ // Remove old Registry Run key if upgrading
85
88
  try {
86
89
  execFileSync("reg", [
87
- "add", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
88
- "/v", DAEMON_TASK_NAME, "/t", "REG_SZ", "/d", regValue, "/f",
90
+ "delete", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
91
+ "/v", DAEMON_TASK_NAME, "/f",
89
92
  ], { encoding: "utf-8", stdio: "pipe" });
90
- console.log(`Registry Run key "${DAEMON_TASK_NAME}" installed (runs at logon).`);
91
- }
92
- catch (err) {
93
- console.error(`Warning: failed to install registry run entry: ${err}`);
94
- console.error("You may need to start palmier serve manually.");
95
93
  }
94
+ catch { /* key may not exist */ }
96
95
  // Start the daemon now
97
96
  this.startDaemonTask();
98
97
  console.log("\nHost initialization complete!");
@@ -133,19 +132,20 @@ export class WindowsPlatform {
133
132
  }
134
133
  this.startDaemonTask();
135
134
  }
136
- /** Create or update the Task Scheduler entry for the daemon. */
135
+ /** Create or update the Task Scheduler entry for the daemon (requires elevation for S4U). */
137
136
  ensureDaemonTask(script) {
138
- const vbs = `CreateObject("WScript.Shell").Run """${process.execPath}"" ""${script}"" serve", 0, False`;
139
- fs.writeFileSync(DAEMON_VBS_FILE, vbs, "utf-8");
140
- const wscript = `${process.env.SYSTEMROOT || "C:\\Windows"}\\System32\\wscript.exe`;
141
137
  const tn = `\\Palmier\\${DAEMON_TASK_NAME}`;
142
- const tr = `"${wscript}" "${DAEMON_VBS_FILE}"`;
143
- const xml = buildTaskXml(tr, [`<TimeTrigger><StartBoundary>2000-01-01T00:00:00</StartBoundary></TimeTrigger>`]);
138
+ const tr = `"${process.execPath}" "${script}" serve`;
139
+ const xml = buildTaskXml(tr, [`<BootTrigger><Enabled>true</Enabled></BootTrigger>`]);
144
140
  const xmlPath = path.join(CONFIG_DIR, "daemon-task.xml");
145
141
  try {
146
142
  const bom = Buffer.from([0xFF, 0xFE]);
147
143
  fs.writeFileSync(xmlPath, Buffer.concat([bom, Buffer.from(xml, "utf16le")]));
148
- execFileSync("schtasks", ["/create", "/tn", tn, "/xml", xmlPath, "/f"], { encoding: "utf-8", windowsHide: true, stdio: "pipe" });
144
+ // S4U LogonType requires elevation spawn schtasks via RunAs
145
+ const args = `/create /tn "${tn}" /xml "${xmlPath}" /f`;
146
+ execFileSync("powershell", [
147
+ "-Command", `Start-Process -Verb RunAs -Wait -FilePath schtasks -ArgumentList '${args}'`,
148
+ ], { encoding: "utf-8", windowsHide: true, stdio: "pipe" });
149
149
  }
150
150
  catch (err) {
151
151
  const e = err;
@@ -157,6 +157,12 @@ export class WindowsPlatform {
157
157
  }
158
158
  catch { /* ignore */ }
159
159
  }
160
+ // Cleanup old VBS launcher if upgrading
161
+ const oldVbs = path.join(CONFIG_DIR, "daemon.vbs");
162
+ try {
163
+ fs.unlinkSync(oldVbs);
164
+ }
165
+ catch { /* ignore */ }
160
166
  }
161
167
  /** Start the daemon via Task Scheduler (runs outside any session's job object). */
162
168
  startDaemonTask() {
@@ -174,12 +180,7 @@ export class WindowsPlatform {
174
180
  const taskId = task.frontmatter.id;
175
181
  const tn = schtasksTaskName(taskId);
176
182
  const script = process.argv[1] || "palmier";
177
- // Write a VBS launcher so the task runs without a visible console window
178
- const vbsPath = path.join(CONFIG_DIR, `task-${taskId}.vbs`);
179
- const vbs = `CreateObject("WScript.Shell").Run """${process.execPath}"" ""${script}"" run ${taskId}", 0, True`;
180
- fs.writeFileSync(vbsPath, vbs, "utf-8");
181
- const wscript = `${process.env.SYSTEMROOT || "C:\\Windows"}\\System32\\wscript.exe`;
182
- const tr = `"${wscript}" "${vbsPath}"`;
183
+ const tr = `"${process.execPath}" "${script}" run ${taskId}`;
183
184
  // Build trigger XML elements
184
185
  const triggerElements = [];
185
186
  if (task.frontmatter.triggers_enabled) {
@@ -198,6 +199,8 @@ export class WindowsPlatform {
198
199
  }
199
200
  // Write XML and register via schtasks — gives us full control over
200
201
  // settings like MultipleInstancesPolicy that schtasks flags don't expose.
202
+ // S4U LogonType ensures no console window. Works without elevation
203
+ // because the daemon (which calls this) runs elevated.
201
204
  const xml = buildTaskXml(tr, triggerElements);
202
205
  const xmlPath = path.join(CONFIG_DIR, `task-${taskId}.xml`);
203
206
  try {
@@ -218,6 +221,11 @@ export class WindowsPlatform {
218
221
  }
219
222
  catch { /* ignore */ }
220
223
  }
224
+ // Cleanup old VBS launcher if upgrading
225
+ try {
226
+ fs.unlinkSync(path.join(CONFIG_DIR, `task-${taskId}.vbs`));
227
+ }
228
+ catch { /* ignore */ }
221
229
  }
222
230
  removeTaskTimer(taskId) {
223
231
  const tn = schtasksTaskName(taskId);
@@ -227,10 +235,6 @@ export class WindowsPlatform {
227
235
  catch {
228
236
  // Task might not exist — that's fine
229
237
  }
230
- try {
231
- fs.unlinkSync(path.join(CONFIG_DIR, `task-${taskId}.vbs`));
232
- }
233
- catch { /* ignore */ }
234
238
  }
235
239
  async startTask(taskId) {
236
240
  const tn = schtasksTaskName(taskId);
@@ -10,7 +10,7 @@ import { getPlatform } from "./platform/index.js";
10
10
  import { spawnCommand } from "./spawn-command.js";
11
11
  import crossSpawn from "cross-spawn";
12
12
  import { getAgent } from "./agents/agent.js";
13
- import { validateSession } from "./session-store.js";
13
+ import { validateClient } from "./client-store.js";
14
14
  import { publishHostEvent } from "./events.js";
15
15
  import { currentVersion, performUpdate } from "./update-checker.js";
16
16
  import { parseReportFiles, parseTaskOutcome, stripPalmierMarkers } from "./commands/run.js";
@@ -140,8 +140,8 @@ export function createRpcHandler(config, nc) {
140
140
  };
141
141
  }
142
142
  async function handleRpc(request) {
143
- // Session token validation: skip for trusted localhost requests
144
- if (!request.localhost && (!request.sessionToken || !validateSession(request.sessionToken))) {
143
+ // Client token validation: skip for trusted localhost requests
144
+ if (!request.localhost && (!request.clientToken || !validateClient(request.clientToken))) {
145
145
  return { error: "Unauthorized" };
146
146
  }
147
147
  switch (request.method) {
@@ -212,8 +212,11 @@ export function createRpcHandler(config, nc) {
212
212
  existing.frontmatter.triggers_enabled = params.triggers_enabled;
213
213
  if (params.requires_confirmation !== undefined)
214
214
  existing.frontmatter.requires_confirmation = params.requires_confirmation;
215
- if (params.yolo_mode !== undefined)
215
+ if (params.yolo_mode !== undefined) {
216
216
  existing.frontmatter.yolo_mode = params.yolo_mode || undefined;
217
+ if (params.yolo_mode)
218
+ delete existing.frontmatter.permissions;
219
+ }
217
220
  if (params.command !== undefined) {
218
221
  if (params.command) {
219
222
  existing.frontmatter.command = params.command;
@@ -1,7 +1,7 @@
1
1
  import * as http from "node:http";
2
2
  import * as os from "os";
3
3
  import { StringCodec } from "nats";
4
- import { validateSession, addSession } from "../session-store.js";
4
+ import { validateClient, addClient } from "../client-store.js";
5
5
  import { registerPending } from "../pending-requests.js";
6
6
  import * as fs from "node:fs";
7
7
  import { getTaskDir, parseTaskFile, spliceUserMessage } from "../task.js";
@@ -115,9 +115,9 @@ export async function startHttpTransport(config, handleRpc, port, nc, pairingCod
115
115
  const auth = req.headers.authorization;
116
116
  if (!auth || !auth.startsWith("Bearer "))
117
117
  return false;
118
- return validateSession(auth.slice(7));
118
+ return validateClient(auth.slice(7));
119
119
  }
120
- function extractSessionToken(req) {
120
+ function extractClientToken(req) {
121
121
  const auth = req.headers.authorization;
122
122
  if (!auth || !auth.startsWith("Bearer "))
123
123
  return undefined;
@@ -368,11 +368,11 @@ export async function startHttpTransport(config, handleRpc, port, nc, pairingCod
368
368
  sendJson(res, 401, { error: "Invalid code" });
369
369
  return;
370
370
  }
371
- const session = addSession(label);
371
+ const client = addClient(label);
372
372
  const ip = detectLanIp();
373
373
  const response = {
374
374
  hostId: config.hostId,
375
- sessionToken: session.token,
375
+ clientToken: client.token,
376
376
  directUrl: `http://${ip}:${port}`,
377
377
  };
378
378
  clearTimeout(pending.timer);
@@ -449,10 +449,10 @@ export async function startHttpTransport(config, handleRpc, port, nc, pairingCod
449
449
  sendJson(res, 400, { error: "Invalid JSON" });
450
450
  return;
451
451
  }
452
- const sessionToken = extractSessionToken(req);
452
+ const clientToken = extractClientToken(req);
453
453
  console.log(`[http] RPC: ${method}`);
454
454
  try {
455
- const response = await handleRpc({ method, params, sessionToken, localhost: isLocalhost(req) });
455
+ const response = await handleRpc({ method, params, clientToken, localhost: isLocalhost(req) });
456
456
  console.log(`[http] RPC done: ${method}`, JSON.stringify(response).slice(0, 200));
457
457
  sendJson(res, 200, response);
458
458
  }
@@ -39,13 +39,13 @@ export async function startNatsTransport(config, handleRpc, nc) {
39
39
  }
40
40
  }
41
41
  }
42
- // Extract sessionToken from params (PWA includes it in the payload)
43
- const sessionToken = typeof params.sessionToken === "string" ? params.sessionToken : undefined;
44
- delete params.sessionToken;
42
+ // Extract clientToken from params (PWA includes it in the payload)
43
+ const clientToken = typeof params.clientToken === "string" ? params.clientToken : undefined;
44
+ delete params.clientToken;
45
45
  console.log(`[nats] RPC: ${method}`);
46
46
  let response;
47
47
  try {
48
- response = await handleRpc({ method, params, sessionToken });
48
+ response = await handleRpc({ method, params, clientToken });
49
49
  }
50
50
  catch (err) {
51
51
  console.error(`[nats] RPC error (${method}):`, err);
package/dist/types.d.ts CHANGED
@@ -67,8 +67,8 @@ export interface ConversationMessage {
67
67
  export interface RpcMessage {
68
68
  method: string;
69
69
  params: Record<string, unknown>;
70
- sessionToken?: string;
71
- /** Trusted localhost request — skip session validation. */
70
+ clientToken?: string;
71
+ /** Trusted localhost request — skip client validation. */
72
72
  localhost?: boolean;
73
73
  }
74
74
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "palmier",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Palmier host CLI - provisions, executes tasks, and serves NATS RPC",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hongxu Cai",