@damian87/omp 0.5.0 → 0.7.0
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/skills/schedule/SKILL.md +71 -0
- package/.github/skills/team/SKILL.md +82 -57
- package/.github/skills/team/scripts/team-launch.sh +140 -42
- package/README.md +21 -2
- package/catalog/skills-general.json +2 -2
- package/dist/src/cli.d.ts +1 -7
- package/dist/src/cli.js +128 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/registry.d.ts +3 -0
- package/dist/src/commands/registry.js +11 -0
- package/dist/src/commands/registry.js.map +1 -0
- package/dist/src/commands/suggest.d.ts +19 -0
- package/dist/src/commands/suggest.js +158 -0
- package/dist/src/commands/suggest.js.map +1 -0
- package/dist/src/commands/types.d.ts +16 -0
- package/dist/src/commands/types.js +2 -0
- package/dist/src/commands/types.js.map +1 -0
- package/dist/src/instructions-memory.js +8 -15
- package/dist/src/instructions-memory.js.map +1 -1
- package/dist/src/schedule/commands.d.ts +34 -0
- package/dist/src/schedule/commands.js +130 -0
- package/dist/src/schedule/commands.js.map +1 -0
- package/dist/src/schedule/installer.d.ts +20 -0
- package/dist/src/schedule/installer.js +76 -0
- package/dist/src/schedule/installer.js.map +1 -0
- package/dist/src/schedule/installers/crontab.d.ts +17 -0
- package/dist/src/schedule/installers/crontab.js +112 -0
- package/dist/src/schedule/installers/crontab.js.map +1 -0
- package/dist/src/schedule/installers/launchd.d.ts +22 -0
- package/dist/src/schedule/installers/launchd.js +125 -0
- package/dist/src/schedule/installers/launchd.js.map +1 -0
- package/dist/src/schedule/installers/systemd.d.ts +15 -0
- package/dist/src/schedule/installers/systemd.js +136 -0
- package/dist/src/schedule/installers/systemd.js.map +1 -0
- package/dist/src/schedule/job-store.d.ts +21 -0
- package/dist/src/schedule/job-store.js +102 -0
- package/dist/src/schedule/job-store.js.map +1 -0
- package/dist/src/schedule/lock.d.ts +9 -0
- package/dist/src/schedule/lock.js +83 -0
- package/dist/src/schedule/lock.js.map +1 -0
- package/dist/src/schedule/paths.d.ts +15 -0
- package/dist/src/schedule/paths.js +36 -0
- package/dist/src/schedule/paths.js.map +1 -0
- package/dist/src/schedule/runner.d.ts +8 -0
- package/dist/src/schedule/runner.js +151 -0
- package/dist/src/schedule/runner.js.map +1 -0
- package/dist/src/schedule/types.d.ts +60 -0
- package/dist/src/schedule/types.js +5 -0
- package/dist/src/schedule/types.js.map +1 -0
- package/dist/src/team/index.d.ts +1 -0
- package/dist/src/team/index.js +1 -0
- package/dist/src/team/index.js.map +1 -1
- package/dist/src/team/pane-monitor.d.ts +39 -0
- package/dist/src/team/pane-monitor.js +128 -0
- package/dist/src/team/pane-monitor.js.map +1 -0
- package/dist/src/team/runtime.js +12 -1
- package/dist/src/team/runtime.js.map +1 -1
- package/dist/src/team/tmux.d.ts +12 -0
- package/dist/src/team/tmux.js +38 -0
- package/dist/src/team/tmux.js.map +1 -1
- package/docs/research/2026-06-01-schedule-cron-feature.md +346 -0
- package/package.json +2 -1
- package/scripts/lib/schedule-results.mjs +88 -0
- package/scripts/session-start.mjs +8 -0
|
@@ -2,33 +2,24 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { ompRoot } from "./omp-root.js";
|
|
4
4
|
import { readRepoGoal } from "./goal.js";
|
|
5
|
-
import {
|
|
5
|
+
import { noteIndex } from "./project-memory.js";
|
|
6
6
|
// Copilot CLI does not execute plugin lifecycle hooks (verified: neither
|
|
7
7
|
// SessionStart nor UserPromptSubmit fire), so we can't inject memory via hooks.
|
|
8
|
-
// Copilot DOES read .github/copilot-instructions.md, so we render
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// Copilot DOES read .github/copilot-instructions.md, so we render a lightweight
|
|
9
|
+
// pointer block there. The block keeps repo goal visible but leaves project
|
|
10
|
+
// memory and daily logs on demand to avoid bloating or over-steering context.
|
|
11
11
|
const START = "<!-- omp:memory:start -->";
|
|
12
12
|
const END = "<!-- omp:memory:end -->";
|
|
13
|
-
const MAX_DIRECTIVES = 20;
|
|
14
13
|
function instructionsPath(cwd) {
|
|
15
14
|
return join(ompRoot(cwd), ".github", "copilot-instructions.md");
|
|
16
15
|
}
|
|
17
16
|
function renderBlock(cwd) {
|
|
18
17
|
const goal = readRepoGoal(cwd);
|
|
19
|
-
const directives = readDirectives(cwd);
|
|
20
18
|
const notes = noteIndex(cwd);
|
|
21
|
-
const lines = [START, "##
|
|
19
|
+
const lines = [START, "## oh-my-copilot project context"];
|
|
22
20
|
if (goal)
|
|
23
21
|
lines.push("", `**Repo goal:** ${goal}`);
|
|
24
|
-
|
|
25
|
-
lines.push("", "**Directives — must follow this session:**");
|
|
26
|
-
for (const d of directives.slice(0, MAX_DIRECTIVES))
|
|
27
|
-
lines.push(`- ${d}`);
|
|
28
|
-
if (directives.length > MAX_DIRECTIVES)
|
|
29
|
-
lines.push(`- (+${directives.length - MAX_DIRECTIVES} more — \`omp project-memory read\`)`);
|
|
30
|
-
}
|
|
31
|
-
lines.push("", `**On demand:** \`omp project-memory index\` (${notes.length} note${notes.length === 1 ? "" : "s"}) · \`omp project-memory read <id>\` · \`omp daily-log read\``, END);
|
|
22
|
+
lines.push("", "Project memory is available on demand:", "- `omp project-memory read` for project hints and the note index", "- `omp project-memory read <id>` for a specific note body", "- `omp daily-log read` for recent daily context", "", `Available note index: ${notes.length} note${notes.length === 1 ? "" : "s"}.`, END);
|
|
32
23
|
return lines.join("\n");
|
|
33
24
|
}
|
|
34
25
|
/**
|
|
@@ -38,6 +29,8 @@ function renderBlock(cwd) {
|
|
|
38
29
|
*/
|
|
39
30
|
export function syncInstructionsMemory(cwd) {
|
|
40
31
|
const p = instructionsPath(cwd);
|
|
32
|
+
if (process.env.OMP_DISABLE_INSTRUCTIONS_MEMORY)
|
|
33
|
+
return { path: p, wrote: false };
|
|
41
34
|
const block = renderBlock(cwd);
|
|
42
35
|
try {
|
|
43
36
|
const content = existsSync(p) ? readFileSync(p, "utf8") : "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions-memory.js","sourceRoot":"","sources":["../../src/instructions-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"instructions-memory.js","sourceRoot":"","sources":["../../src/instructions-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAE9E,MAAM,KAAK,GAAG,2BAA2B,CAAC;AAC1C,MAAM,GAAG,GAAG,yBAAyB,CAAC;AAEtC,SAAS,gBAAgB,CAAC,GAAW;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,yBAAyB,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,MAA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0,0 +1,34 @@
|
|
|
1
|
+
import { type OsBackend, type ScheduleAddOptions, type ScheduleJob } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the absolute path of the `omp` wrapper to write into OS entries.
|
|
4
|
+
* The dist `.js` (process.argv[1]) is a last resort because launchd/cron need
|
|
5
|
+
* the executable wrapper, not the script.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveOmpBinPath(): string;
|
|
8
|
+
export interface AddResult {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
job?: ScheduleJob;
|
|
11
|
+
backend?: OsBackend;
|
|
12
|
+
messages: string[];
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function addScheduleJob(stateCwd: string, opts: ScheduleAddOptions): AddResult;
|
|
16
|
+
export interface JobView extends ScheduleJob {
|
|
17
|
+
osInstalled: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function listScheduleJobs(stateCwd: string): JobView[];
|
|
20
|
+
export interface RemoveResult {
|
|
21
|
+
removed: boolean;
|
|
22
|
+
uninstalled: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function removeScheduleJob(stateCwd: string, id: string): RemoveResult;
|
|
25
|
+
export interface StatusView {
|
|
26
|
+
job?: ScheduleJob;
|
|
27
|
+
osInstalled: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function getScheduleStatus(stateCwd: string, id: string): StatusView;
|
|
30
|
+
/** Run handler entry used by `omp schedule run|run-now`. Missing job → clean no-op (exit 0). */
|
|
31
|
+
export declare function runScheduleById(stateCwd: string, id: string): Promise<{
|
|
32
|
+
ok: boolean;
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, statSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { getInstalledStatus, installJob, uninstallJob } from "./installer.js";
|
|
4
|
+
import { deleteJob, listJobs, readJob, writeJob } from "./job-store.js";
|
|
5
|
+
import { ensureScheduleDirs, jobFilePath, jobLockPath, resolveSchedulePaths, } from "./paths.js";
|
|
6
|
+
import { runScheduledJob } from "./runner.js";
|
|
7
|
+
import { DEFAULT_TIMEOUT_MS, DEFAULT_TTL_HOURS, } from "./types.js";
|
|
8
|
+
const ID_RE = /^[a-zA-Z0-9_-]+$/;
|
|
9
|
+
const CRON_RE = /^\S+\s+\S+\s+\S+\s+\S+\s+\S+$/; // exactly 5 whitespace-separated fields
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the absolute path of the `omp` wrapper to write into OS entries.
|
|
12
|
+
* The dist `.js` (process.argv[1]) is a last resort because launchd/cron need
|
|
13
|
+
* the executable wrapper, not the script.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveOmpBinPath() {
|
|
16
|
+
const fromEnv = process.env.OMP_BIN;
|
|
17
|
+
if (fromEnv)
|
|
18
|
+
return fromEnv;
|
|
19
|
+
try {
|
|
20
|
+
const which = execFileSync("which", ["omp"], { encoding: "utf8" }).trim();
|
|
21
|
+
if (which)
|
|
22
|
+
return which;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// not on PATH
|
|
26
|
+
}
|
|
27
|
+
return process.argv[1] ?? "omp";
|
|
28
|
+
}
|
|
29
|
+
export function addScheduleJob(stateCwd, opts) {
|
|
30
|
+
const messages = [];
|
|
31
|
+
if (!ID_RE.test(opts.id)) {
|
|
32
|
+
return { ok: false, messages, error: `invalid --id "${opts.id}" (use letters, digits, _ or -)` };
|
|
33
|
+
}
|
|
34
|
+
if (!CRON_RE.test(opts.cron)) {
|
|
35
|
+
return { ok: false, messages, error: `invalid --cron "${opts.cron}" (expected 5 fields)` };
|
|
36
|
+
}
|
|
37
|
+
const agentCwd = opts.cwd ?? stateCwd;
|
|
38
|
+
if (!existsSync(agentCwd) || !statSync(agentCwd).isDirectory()) {
|
|
39
|
+
return { ok: false, messages, error: `--cwd does not exist or is not a directory: ${agentCwd}` };
|
|
40
|
+
}
|
|
41
|
+
const paths = resolveSchedulePaths(stateCwd);
|
|
42
|
+
ensureScheduleDirs(paths);
|
|
43
|
+
const allowAllTools = opts.allowAllTools ?? false;
|
|
44
|
+
// TTL precedence: explicit --ttl-hours wins; else a --max-runs-only job has no
|
|
45
|
+
// TTL (run-count bounds it); else fall back to the default 72h TTL.
|
|
46
|
+
const expiresAt = opts.ttlHours !== undefined
|
|
47
|
+
? new Date(Date.now() + opts.ttlHours * 3_600_000).toISOString()
|
|
48
|
+
: opts.maxRuns !== undefined
|
|
49
|
+
? undefined
|
|
50
|
+
: new Date(Date.now() + DEFAULT_TTL_HOURS * 3_600_000).toISOString();
|
|
51
|
+
const job = {
|
|
52
|
+
id: opts.id,
|
|
53
|
+
cron: opts.cron,
|
|
54
|
+
prompt: opts.prompt,
|
|
55
|
+
bin: opts.bin ?? "copilot",
|
|
56
|
+
model: opts.model,
|
|
57
|
+
cwd: agentCwd,
|
|
58
|
+
timeoutMs: opts.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
59
|
+
allowAllTools,
|
|
60
|
+
createdAt: new Date().toISOString(),
|
|
61
|
+
expiresAt,
|
|
62
|
+
maxRuns: opts.maxRuns,
|
|
63
|
+
runCount: 0,
|
|
64
|
+
backend: "crontab",
|
|
65
|
+
ompBinPath: resolveOmpBinPath(),
|
|
66
|
+
active: true,
|
|
67
|
+
};
|
|
68
|
+
if (opts.dryRun) {
|
|
69
|
+
messages.push(`[dry-run] would install job "${job.id}" (cron ${job.cron}) for agent ${job.bin} in ${job.cwd}`);
|
|
70
|
+
return { ok: true, job, messages };
|
|
71
|
+
}
|
|
72
|
+
// Clean replace: if a job with this id already exists, uninstall its OS entry by
|
|
73
|
+
// the RECORDED backend first. The new install's detected backend may differ (e.g.
|
|
74
|
+
// a prior crontab-fallback re-added with a simple cron resolves to launchd), which
|
|
75
|
+
// would otherwise orphan the old entry.
|
|
76
|
+
const existing = readJob(jobFilePath(paths.jobsDir, job.id));
|
|
77
|
+
if (existing)
|
|
78
|
+
uninstallJob(existing.id, existing.backend);
|
|
79
|
+
writeJob(jobFilePath(paths.jobsDir, job.id), job);
|
|
80
|
+
const result = installJob(job, paths.logsDir, paths.cwd);
|
|
81
|
+
job.backend = result.backend;
|
|
82
|
+
writeJob(jobFilePath(paths.jobsDir, job.id), job); // persist resolved backend
|
|
83
|
+
messages.push(`scheduled "${job.id}" via ${job.backend} (cron ${job.cron})`);
|
|
84
|
+
if (allowAllTools) {
|
|
85
|
+
messages.push(`⚠ WARNING: "${job.id}" runs UNATTENDED with full tool access (--allow-all-tools) in ${job.cwd}. Ensure the prompt is safe.`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
messages.push(`note: "${job.id}" runs without --allow-all-tools, so in unattended (-p, no TTY) mode the agent is limited to read-only/allowlisted tools. Re-add with --allow-all-tools if it must act.`);
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, job, backend: job.backend, messages };
|
|
91
|
+
}
|
|
92
|
+
export function listScheduleJobs(stateCwd) {
|
|
93
|
+
const paths = resolveSchedulePaths(stateCwd);
|
|
94
|
+
return listJobs(paths.jobsDir).map((job) => ({ ...job, osInstalled: getInstalledStatus(job.id, job.backend) }));
|
|
95
|
+
}
|
|
96
|
+
export function removeScheduleJob(stateCwd, id) {
|
|
97
|
+
const paths = resolveSchedulePaths(stateCwd);
|
|
98
|
+
const jobPath = jobFilePath(paths.jobsDir, id);
|
|
99
|
+
const job = readJob(jobPath);
|
|
100
|
+
if (!job)
|
|
101
|
+
return { removed: false, uninstalled: false };
|
|
102
|
+
uninstallJob(id, job.backend);
|
|
103
|
+
deleteJob(jobPath);
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(jobLockPath(paths.jobsDir, id));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// no lock to clean
|
|
109
|
+
}
|
|
110
|
+
// results + logs are intentionally preserved for audit
|
|
111
|
+
return { removed: true, uninstalled: true };
|
|
112
|
+
}
|
|
113
|
+
export function getScheduleStatus(stateCwd, id) {
|
|
114
|
+
const paths = resolveSchedulePaths(stateCwd);
|
|
115
|
+
const job = readJob(jobFilePath(paths.jobsDir, id));
|
|
116
|
+
return { job, osInstalled: job ? getInstalledStatus(id, job.backend) : false };
|
|
117
|
+
}
|
|
118
|
+
/** Run handler entry used by `omp schedule run|run-now`. Missing job → clean no-op (exit 0). */
|
|
119
|
+
export async function runScheduleById(stateCwd, id) {
|
|
120
|
+
const paths = resolveSchedulePaths(stateCwd);
|
|
121
|
+
const job = readJob(jobFilePath(paths.jobsDir, id));
|
|
122
|
+
if (!job) {
|
|
123
|
+
return { ok: true, message: `schedule run: job "${id}" not found (orphan OS entry?); no-op` };
|
|
124
|
+
}
|
|
125
|
+
const result = await runScheduledJob(job, paths, {
|
|
126
|
+
onExpire: (j) => uninstallJob(j.id, j.backend),
|
|
127
|
+
});
|
|
128
|
+
return { ok: result.status !== "error", message: `run "${id}" → ${result.status}: ${result.summary}` };
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/schedule/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAIlB,MAAM,YAAY,CA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,KAAK,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACpD,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,kBAAkB,CAAC,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AACjF,CAAC;AAED,gGAAgG;AAChG,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,EAAU;IAChE,MAAM,KAAK,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACpD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,uCAAuC,EAAE,CAAC;IAChG,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,KAAK,EAAE;QAC/C,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;KAC/C,CAAC,CAAC;IACH,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;AACzG,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OsBackend, ScheduleJob } from "./types.js";
|
|
2
|
+
export interface DetectOptions {
|
|
3
|
+
platform?: NodeJS.Platform;
|
|
4
|
+
hasSystemctl?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Pick the native backend for this host. Inputs are injectable for testing. */
|
|
7
|
+
export declare function detectOsBackend(opts?: DetectOptions): OsBackend;
|
|
8
|
+
export interface InstallResult {
|
|
9
|
+
backend: OsBackend;
|
|
10
|
+
installed: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Install the OS-scheduler entry for a job. On launchd, a cron expression that
|
|
14
|
+
* StartCalendarInterval cannot express falls back to crontab — the chosen
|
|
15
|
+
* backend is returned so the caller can persist it on the job.
|
|
16
|
+
*/
|
|
17
|
+
export declare function installJob(job: ScheduleJob, logsDir: string, stateRoot: string, opts?: DetectOptions): InstallResult;
|
|
18
|
+
/** Uninstall by the job's recorded backend. Idempotent — never throws if absent. */
|
|
19
|
+
export declare function uninstallJob(id: string, backend: OsBackend): void;
|
|
20
|
+
export declare function getInstalledStatus(id: string, backend: OsBackend): boolean;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { cronToLaunchdInterval, installLaunchd, statusLaunchd, uninstallLaunchd } from "./installers/launchd.js";
|
|
3
|
+
import { installCrontab, statusCrontab, uninstallCrontab } from "./installers/crontab.js";
|
|
4
|
+
import { installSystemd, statusSystemd, uninstallSystemd } from "./installers/systemd.js";
|
|
5
|
+
function systemctlAvailable() {
|
|
6
|
+
try {
|
|
7
|
+
execFileSync("systemctl", ["--user", "--version"], { stdio: "ignore" });
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Pick the native backend for this host. Inputs are injectable for testing. */
|
|
15
|
+
export function detectOsBackend(opts = {}) {
|
|
16
|
+
const platform = opts.platform ?? process.platform;
|
|
17
|
+
if (platform === "darwin")
|
|
18
|
+
return "launchd";
|
|
19
|
+
const hasSystemctl = opts.hasSystemctl ?? systemctlAvailable();
|
|
20
|
+
if (hasSystemctl)
|
|
21
|
+
return "systemd";
|
|
22
|
+
return "crontab";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Install the OS-scheduler entry for a job. On launchd, a cron expression that
|
|
26
|
+
* StartCalendarInterval cannot express falls back to crontab — the chosen
|
|
27
|
+
* backend is returned so the caller can persist it on the job.
|
|
28
|
+
*/
|
|
29
|
+
export function installJob(job, logsDir, stateRoot, opts = {}) {
|
|
30
|
+
const backend = detectOsBackend(opts);
|
|
31
|
+
// Replace semantics: clear any prior entry for this id first.
|
|
32
|
+
uninstallJob(job.id, backend);
|
|
33
|
+
if (backend === "launchd") {
|
|
34
|
+
const sched = cronToLaunchdInterval(job.cron);
|
|
35
|
+
if (sched === null) {
|
|
36
|
+
// launchd can't express this cron — fall back to crontab.
|
|
37
|
+
installCrontab(job, logsDir, stateRoot);
|
|
38
|
+
return { backend: "crontab", installed: true };
|
|
39
|
+
}
|
|
40
|
+
installLaunchd(job, sched, logsDir, stateRoot);
|
|
41
|
+
return { backend: "launchd", installed: true };
|
|
42
|
+
}
|
|
43
|
+
if (backend === "systemd") {
|
|
44
|
+
installSystemd(job, stateRoot);
|
|
45
|
+
return { backend: "systemd", installed: true };
|
|
46
|
+
}
|
|
47
|
+
installCrontab(job, logsDir, stateRoot);
|
|
48
|
+
return { backend: "crontab", installed: true };
|
|
49
|
+
}
|
|
50
|
+
/** Uninstall by the job's recorded backend. Idempotent — never throws if absent. */
|
|
51
|
+
export function uninstallJob(id, backend) {
|
|
52
|
+
try {
|
|
53
|
+
if (backend === "launchd")
|
|
54
|
+
uninstallLaunchd(id);
|
|
55
|
+
else if (backend === "systemd")
|
|
56
|
+
uninstallSystemd(id);
|
|
57
|
+
else
|
|
58
|
+
uninstallCrontab(id);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// best effort — entry may already be gone
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function getInstalledStatus(id, backend) {
|
|
65
|
+
try {
|
|
66
|
+
if (backend === "launchd")
|
|
67
|
+
return statusLaunchd(id);
|
|
68
|
+
if (backend === "systemd")
|
|
69
|
+
return statusSystemd(id);
|
|
70
|
+
return statusCrontab(id);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=installer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installer.js","sourceRoot":"","sources":["../../../src/schedule/installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACjH,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQ1F,SAAS,kBAAkB;IACzB,IAAI,CAAC;QACH,YAAY,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,eAAe,CAAC,OAAsB,EAAE;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IACnD,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,kBAAkB,EAAE,CAAC;IAC/D,IAAI,YAAY;QAAE,OAAO,SAAS,CAAC;IACnC,OAAO,SAAS,CAAC;AACnB,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,GAAgB,EAChB,OAAe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AAM,CAAC;QACP,0CAA0C;IAC5C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,EAAU,EAAE,OAAkB;IAC/D,IAAI,CAAC;QACH,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,aAAa,CAAC,EAAE,CAAC,CAAC;QACpD,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,aAAa,CAAC,EAAE,CAAC,CAAC;QACpD,OAAO,aAAa,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ScheduleJob } from "../types.js";
|
|
2
|
+
export declare const BLOCK_BEGIN = "# BEGIN omp-schedule";
|
|
3
|
+
export declare const BLOCK_END = "# END omp-schedule";
|
|
4
|
+
/** The crontab command line for a job (without the id marker). */
|
|
5
|
+
export declare function crontabEntryLine(job: ScheduleJob, logsDir: string, stateRoot: string): string;
|
|
6
|
+
/** Parse the managed block of an existing crontab into an ordered id→line map. */
|
|
7
|
+
export declare function parseManagedBlock(existing: string): Map<string, string>;
|
|
8
|
+
/** Pure: add or replace the entry for `id` in the managed block. */
|
|
9
|
+
export declare function applyCrontabBlock(existing: string, id: string, entryLine: string): string;
|
|
10
|
+
/** Pure: remove the entry for `id`; drops the block markers when it empties. */
|
|
11
|
+
export declare function removeCrontabEntry(existing: string, id: string): string;
|
|
12
|
+
export declare function hasCrontabEntry(existing: string, id: string): boolean;
|
|
13
|
+
export declare function readCrontab(): string;
|
|
14
|
+
export declare function writeCrontab(content: string): void;
|
|
15
|
+
export declare function installCrontab(job: ScheduleJob, logsDir: string, stateRoot: string): string;
|
|
16
|
+
export declare function uninstallCrontab(id: string): void;
|
|
17
|
+
export declare function statusCrontab(id: string): boolean;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
export const BLOCK_BEGIN = "# BEGIN omp-schedule";
|
|
4
|
+
export const BLOCK_END = "# END omp-schedule";
|
|
5
|
+
const ID_PREFIX = "# omp:";
|
|
6
|
+
/** Single-quote a value for safe shell interpolation. */
|
|
7
|
+
function shq(s) {
|
|
8
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
9
|
+
}
|
|
10
|
+
/** The crontab command line for a job (without the id marker). */
|
|
11
|
+
export function crontabEntryLine(job, logsDir, stateRoot) {
|
|
12
|
+
const logFile = join(logsDir, job.id, `${job.id}.cron.log`);
|
|
13
|
+
// `omp schedule run` resolves state from --root (independent of the agent cwd).
|
|
14
|
+
return `${job.cron} ${shq(job.ompBinPath)} schedule run --id ${job.id} --root ${shq(stateRoot)} >> ${shq(logFile)} 2>&1`;
|
|
15
|
+
}
|
|
16
|
+
/** Parse the managed block of an existing crontab into an ordered id→line map. */
|
|
17
|
+
export function parseManagedBlock(existing) {
|
|
18
|
+
const out = new Map();
|
|
19
|
+
const lines = existing.split("\n");
|
|
20
|
+
let inBlock = false;
|
|
21
|
+
let currentId;
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
if (line.trim() === BLOCK_BEGIN) {
|
|
24
|
+
inBlock = true;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (line.trim() === BLOCK_END) {
|
|
28
|
+
inBlock = false;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (!inBlock)
|
|
32
|
+
continue;
|
|
33
|
+
if (line.startsWith(ID_PREFIX)) {
|
|
34
|
+
currentId = line.slice(ID_PREFIX.length).trim();
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (currentId && line.trim()) {
|
|
38
|
+
out.set(currentId, line);
|
|
39
|
+
currentId = undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Strip the managed block, returning everything outside it (trimmed). */
|
|
45
|
+
function stripManagedBlock(existing) {
|
|
46
|
+
const lines = existing.split("\n");
|
|
47
|
+
const kept = [];
|
|
48
|
+
let inBlock = false;
|
|
49
|
+
for (const line of lines) {
|
|
50
|
+
if (line.trim() === BLOCK_BEGIN) {
|
|
51
|
+
inBlock = true;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (line.trim() === BLOCK_END) {
|
|
55
|
+
inBlock = false;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (!inBlock)
|
|
59
|
+
kept.push(line);
|
|
60
|
+
}
|
|
61
|
+
return kept.join("\n").trim();
|
|
62
|
+
}
|
|
63
|
+
/** Render a fresh crontab from outside-block content + the managed entries. */
|
|
64
|
+
function render(outside, entries) {
|
|
65
|
+
if (entries.size === 0) {
|
|
66
|
+
return outside ? `${outside}\n` : "";
|
|
67
|
+
}
|
|
68
|
+
const block = [BLOCK_BEGIN];
|
|
69
|
+
for (const [id, line] of entries) {
|
|
70
|
+
block.push(`${ID_PREFIX}${id}`, line);
|
|
71
|
+
}
|
|
72
|
+
block.push(BLOCK_END);
|
|
73
|
+
return `${outside ? `${outside}\n\n` : ""}${block.join("\n")}\n`;
|
|
74
|
+
}
|
|
75
|
+
/** Pure: add or replace the entry for `id` in the managed block. */
|
|
76
|
+
export function applyCrontabBlock(existing, id, entryLine) {
|
|
77
|
+
const entries = parseManagedBlock(existing);
|
|
78
|
+
entries.set(id, entryLine);
|
|
79
|
+
return render(stripManagedBlock(existing), entries);
|
|
80
|
+
}
|
|
81
|
+
/** Pure: remove the entry for `id`; drops the block markers when it empties. */
|
|
82
|
+
export function removeCrontabEntry(existing, id) {
|
|
83
|
+
const entries = parseManagedBlock(existing);
|
|
84
|
+
entries.delete(id);
|
|
85
|
+
return render(stripManagedBlock(existing), entries);
|
|
86
|
+
}
|
|
87
|
+
export function hasCrontabEntry(existing, id) {
|
|
88
|
+
return parseManagedBlock(existing).has(id);
|
|
89
|
+
}
|
|
90
|
+
export function readCrontab() {
|
|
91
|
+
try {
|
|
92
|
+
return execSync("crontab -l 2>/dev/null", { encoding: "utf8" });
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return ""; // no crontab yet
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function writeCrontab(content) {
|
|
99
|
+
execSync("crontab -", { input: content });
|
|
100
|
+
}
|
|
101
|
+
export function installCrontab(job, logsDir, stateRoot) {
|
|
102
|
+
const next = applyCrontabBlock(readCrontab(), job.id, crontabEntryLine(job, logsDir, stateRoot));
|
|
103
|
+
writeCrontab(next);
|
|
104
|
+
return "crontab";
|
|
105
|
+
}
|
|
106
|
+
export function uninstallCrontab(id) {
|
|
107
|
+
writeCrontab(removeCrontabEntry(readCrontab(), id));
|
|
108
|
+
}
|
|
109
|
+
export function statusCrontab(id) {
|
|
110
|
+
return hasCrontabEntry(readCrontab(), id);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=crontab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crontab.js","sourceRoot":"","sources":["../../../../src/schedule/installers/crontab.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,CAAC,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAClD,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAC9C,MAAM,SAAS,GAAG,QAAQ,CAAC;AAE3B,yDAAyD;AACzD,SAAS,GAAG,CAAC,CAAS;IACpB,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AACzC,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,gBAAgB,CAAC,GAAgB,EAAE,OAAe,EAAE,SAAiB;IACnF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,GAAG,CA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B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAU;IACzC,YAAY,CAAC,kBAAkB,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAAU;IACtC,OAAO,eAAe,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ScheduleJob } from "../types.js";
|
|
2
|
+
export declare function launchdLabel(id: string): string;
|
|
3
|
+
export declare function launchdPlistPath(id: string): string;
|
|
4
|
+
export interface LaunchdSchedule {
|
|
5
|
+
startInterval?: number;
|
|
6
|
+
startCalendarInterval?: {
|
|
7
|
+
Minute?: number;
|
|
8
|
+
Hour?: number;
|
|
9
|
+
Weekday?: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Translate a simple 5-field cron to a launchd schedule. Returns null for
|
|
14
|
+
* patterns launchd's StartCalendarInterval cannot cleanly express (lists,
|
|
15
|
+
* ranges, multi-step) — the caller then falls back to crontab.
|
|
16
|
+
*/
|
|
17
|
+
export declare function cronToLaunchdInterval(cron: string): LaunchdSchedule | null;
|
|
18
|
+
/** Generate the LaunchAgent plist XML. Deliberately omits KeepAlive (timer jobs must not auto-restart). */
|
|
19
|
+
export declare function generatePlist(job: ScheduleJob, sched: LaunchdSchedule, logsDir: string, stateRoot: string): string;
|
|
20
|
+
export declare function installLaunchd(job: ScheduleJob, sched: LaunchdSchedule, logsDir: string, stateRoot: string): void;
|
|
21
|
+
export declare function uninstallLaunchd(id: string): void;
|
|
22
|
+
export declare function statusLaunchd(id: string): boolean;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
export function launchdLabel(id) {
|
|
6
|
+
return `com.omp.schedule.${id}`;
|
|
7
|
+
}
|
|
8
|
+
export function launchdPlistPath(id) {
|
|
9
|
+
return join(homedir(), "Library", "LaunchAgents", `${launchdLabel(id)}.plist`);
|
|
10
|
+
}
|
|
11
|
+
const STEP_EVERY_MIN = /^\*\/(\d+)$/;
|
|
12
|
+
/**
|
|
13
|
+
* Translate a simple 5-field cron to a launchd schedule. Returns null for
|
|
14
|
+
* patterns launchd's StartCalendarInterval cannot cleanly express (lists,
|
|
15
|
+
* ranges, multi-step) — the caller then falls back to crontab.
|
|
16
|
+
*/
|
|
17
|
+
export function cronToLaunchdInterval(cron) {
|
|
18
|
+
const parts = cron.trim().split(/\s+/);
|
|
19
|
+
if (parts.length !== 5)
|
|
20
|
+
return null;
|
|
21
|
+
const [min, hour, dom, mon, dow] = parts;
|
|
22
|
+
// every N minutes: */N * * * *
|
|
23
|
+
const minStep = STEP_EVERY_MIN.exec(min);
|
|
24
|
+
if (minStep && hour === "*" && dom === "*" && mon === "*" && dow === "*") {
|
|
25
|
+
return { startInterval: Number(minStep[1]) * 60 };
|
|
26
|
+
}
|
|
27
|
+
// every N hours: 0 */N * * *
|
|
28
|
+
const hourStep = STEP_EVERY_MIN.exec(hour);
|
|
29
|
+
if (min === "0" && hourStep && dom === "*" && mon === "*" && dow === "*") {
|
|
30
|
+
return { startInterval: Number(hourStep[1]) * 3600 };
|
|
31
|
+
}
|
|
32
|
+
const isNum = (s) => /^\d+$/.test(s);
|
|
33
|
+
// daily at H:M — minute & hour numeric, date/dow wild
|
|
34
|
+
if (isNum(min) && isNum(hour) && dom === "*" && mon === "*" && dow === "*") {
|
|
35
|
+
return { startCalendarInterval: { Minute: Number(min), Hour: Number(hour) } };
|
|
36
|
+
}
|
|
37
|
+
// weekly at H:M on a single weekday
|
|
38
|
+
if (isNum(min) && isNum(hour) && dom === "*" && mon === "*" && isNum(dow)) {
|
|
39
|
+
return { startCalendarInterval: { Minute: Number(min), Hour: Number(hour), Weekday: Number(dow) } };
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function xmlEscape(s) {
|
|
44
|
+
return s
|
|
45
|
+
.replace(/&/g, "&")
|
|
46
|
+
.replace(/</g, "<")
|
|
47
|
+
.replace(/>/g, ">")
|
|
48
|
+
.replace(/"/g, """)
|
|
49
|
+
.replace(/'/g, "'");
|
|
50
|
+
}
|
|
51
|
+
function calendarXml(cal) {
|
|
52
|
+
const entries = Object.entries(cal)
|
|
53
|
+
.filter(([, v]) => v !== undefined)
|
|
54
|
+
.map(([k, v]) => ` <key>${k}</key>\n <integer>${v}</integer>`)
|
|
55
|
+
.join("\n");
|
|
56
|
+
return ` <key>StartCalendarInterval</key>\n <dict>\n${entries}\n </dict>`;
|
|
57
|
+
}
|
|
58
|
+
/** Generate the LaunchAgent plist XML. Deliberately omits KeepAlive (timer jobs must not auto-restart). */
|
|
59
|
+
export function generatePlist(job, sched, logsDir, stateRoot) {
|
|
60
|
+
const label = launchdLabel(job.id);
|
|
61
|
+
const outLog = join(logsDir, job.id, `${job.id}.launchd.out.log`);
|
|
62
|
+
const errLog = join(logsDir, job.id, `${job.id}.launchd.err.log`);
|
|
63
|
+
const scheduleXml = sched.startInterval !== undefined
|
|
64
|
+
? ` <key>StartInterval</key>\n <integer>${sched.startInterval}</integer>`
|
|
65
|
+
: calendarXml(sched.startCalendarInterval ?? {});
|
|
66
|
+
// run from stateRoot and pass --root so state resolves correctly; the agent
|
|
67
|
+
// subprocess cwd (job.cwd) is set by the runner, not by WorkingDirectory.
|
|
68
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
69
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
70
|
+
<plist version="1.0">
|
|
71
|
+
<dict>
|
|
72
|
+
<key>Label</key>
|
|
73
|
+
<string>${xmlEscape(label)}</string>
|
|
74
|
+
<key>ProgramArguments</key>
|
|
75
|
+
<array>
|
|
76
|
+
<string>${xmlEscape(job.ompBinPath)}</string>
|
|
77
|
+
<string>schedule</string>
|
|
78
|
+
<string>run</string>
|
|
79
|
+
<string>--id</string>
|
|
80
|
+
<string>${xmlEscape(job.id)}</string>
|
|
81
|
+
<string>--root</string>
|
|
82
|
+
<string>${xmlEscape(stateRoot)}</string>
|
|
83
|
+
</array>
|
|
84
|
+
<key>WorkingDirectory</key>
|
|
85
|
+
<string>${xmlEscape(stateRoot)}</string>
|
|
86
|
+
${scheduleXml}
|
|
87
|
+
<key>StandardOutPath</key>
|
|
88
|
+
<string>${xmlEscape(outLog)}</string>
|
|
89
|
+
<key>StandardErrorPath</key>
|
|
90
|
+
<string>${xmlEscape(errLog)}</string>
|
|
91
|
+
</dict>
|
|
92
|
+
</plist>
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
function gui() {
|
|
96
|
+
return `gui/${process.getuid?.() ?? 0}`;
|
|
97
|
+
}
|
|
98
|
+
export function installLaunchd(job, sched, logsDir, stateRoot) {
|
|
99
|
+
const plistPath = launchdPlistPath(job.id);
|
|
100
|
+
mkdirSync(dirname(plistPath), { recursive: true });
|
|
101
|
+
mkdirSync(join(logsDir, job.id), { recursive: true });
|
|
102
|
+
writeFileSync(plistPath, generatePlist(job, sched, logsDir, stateRoot), "utf8");
|
|
103
|
+
try {
|
|
104
|
+
execFileSync("launchctl", ["bootout", `${gui()}/${launchdLabel(job.id)}`], { stdio: "ignore" });
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// not loaded yet — fine
|
|
108
|
+
}
|
|
109
|
+
execFileSync("launchctl", ["bootstrap", gui(), plistPath], { stdio: "ignore" });
|
|
110
|
+
}
|
|
111
|
+
export function uninstallLaunchd(id) {
|
|
112
|
+
try {
|
|
113
|
+
execFileSync("launchctl", ["bootout", `${gui()}/${launchdLabel(id)}`], { stdio: "ignore" });
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// already gone
|
|
117
|
+
}
|
|
118
|
+
const plistPath = launchdPlistPath(id);
|
|
119
|
+
if (existsSync(plistPath))
|
|
120
|
+
unlinkSync(plistPath);
|
|
121
|
+
}
|
|
122
|
+
export function statusLaunchd(id) {
|
|
123
|
+
return existsSync(launchdPlistPath(id));
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=launchd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchd.js","sourceRoot":"","sources":["../../../../src/schedule/installers/launchd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,UAAU,YAAY,CAAC,EAAU;IACrC,OAAO,oBAAoB,EAAE,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAU;IACzC,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,YAAY,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AACjF,CAAC;AAOD,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;IAEzC,+BAA+B;IAC/B,MAAM,OAAO,GAAG,cAA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