@phnx-labs/agents-cli 1.23.28 → 1.23.30

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 (171) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +33 -82
  3. package/dist/bootstrap.js +0 -17
  4. package/dist/cli/command-registry.js +0 -2
  5. package/dist/commands/cloud.js +0 -58
  6. package/dist/commands/config.js +0 -4
  7. package/dist/commands/daemon-index.js +1 -1
  8. package/dist/commands/daemon.js +14 -63
  9. package/dist/commands/doctor.js +0 -12
  10. package/dist/commands/events.js +1 -1
  11. package/dist/commands/feed.d.ts +1 -3
  12. package/dist/commands/feed.js +1 -6
  13. package/dist/commands/fleet-capture.js +2 -4
  14. package/dist/commands/focus.d.ts +0 -1
  15. package/dist/commands/focus.js +2 -4
  16. package/dist/commands/inspect.d.ts +1 -19
  17. package/dist/commands/inspect.js +8 -474
  18. package/dist/commands/mine.js +1 -1
  19. package/dist/commands/prune.js +2 -64
  20. package/dist/commands/ps-roster.d.ts +0 -4
  21. package/dist/commands/ps-roster.js +2 -30
  22. package/dist/commands/ps.js +1 -4
  23. package/dist/commands/repo.d.ts +1 -1
  24. package/dist/commands/repo.js +4 -4
  25. package/dist/commands/sessions-browser.d.ts +0 -2
  26. package/dist/commands/sessions-browser.js +2 -32
  27. package/dist/commands/sessions-optimize.js +3 -4
  28. package/dist/commands/setup-mine.js +0 -1
  29. package/dist/commands/ssh.js +8 -9
  30. package/dist/commands/sync.js +1 -1
  31. package/dist/commands/update.js +2 -2
  32. package/dist/commands/watchdog.js +3 -4
  33. package/dist/lib/accounting/rotate.d.ts +0 -2
  34. package/dist/lib/accounting/rotate.js +1 -4
  35. package/dist/lib/agent-spec/agents.d.ts +0 -1
  36. package/dist/lib/agent-spec/agents.js +0 -8
  37. package/dist/lib/answer-router.d.ts +1 -1
  38. package/dist/lib/answer-router.js +9 -10
  39. package/dist/lib/auth-health.d.ts +0 -1
  40. package/dist/lib/auth-health.js +0 -3
  41. package/dist/lib/cli-entry.d.ts +0 -1
  42. package/dist/lib/cli-entry.js +0 -36
  43. package/dist/lib/cloud/types.d.ts +0 -2
  44. package/dist/lib/config-keys.d.ts +1 -1
  45. package/dist/lib/config-keys.js +1 -4
  46. package/dist/lib/daemon/daemon.d.ts +0 -4
  47. package/dist/lib/daemon/daemon.js +6 -202
  48. package/dist/lib/daemon/heartbeat-service.d.ts +1 -1
  49. package/dist/lib/daemon/heartbeat-service.js +1 -8
  50. package/dist/lib/daemon-services.d.ts +1 -1
  51. package/dist/lib/daemon-services.js +1 -11
  52. package/dist/lib/device-config.d.ts +0 -2
  53. package/dist/lib/device-config.js +4 -22
  54. package/dist/lib/devices/config-migration.js +1 -3
  55. package/dist/lib/exec.d.ts +2 -5
  56. package/dist/lib/exec.js +18 -18
  57. package/dist/lib/factory/snapshot.d.ts +0 -5
  58. package/dist/lib/factory/snapshot.js +1 -28
  59. package/dist/lib/feed/events.d.ts +1 -11
  60. package/dist/lib/feed/events.js +0 -20
  61. package/dist/lib/feed/feed.d.ts +1 -3
  62. package/dist/lib/feed/feed.js +18 -1
  63. package/dist/lib/feed-outcome.d.ts +0 -2
  64. package/dist/lib/feed-outcome.js +0 -5
  65. package/dist/lib/fleet/capture.d.ts +0 -1
  66. package/dist/lib/fleet/capture.js +0 -3
  67. package/dist/lib/fleet/manifest.js +0 -6
  68. package/dist/lib/fleet/types.d.ts +0 -1
  69. package/dist/lib/harness/adapter.d.ts +0 -7
  70. package/dist/lib/harness/adapters/claude.js +0 -18
  71. package/dist/lib/harness/adapters/codex.js +0 -10
  72. package/dist/lib/harness/adapters/cursor.js +0 -11
  73. package/dist/lib/harness/adapters/kimi.js +0 -3
  74. package/dist/lib/harness/adapters/muse.js +0 -11
  75. package/dist/lib/harness/index.d.ts +1 -1
  76. package/dist/lib/harness/index.js +0 -2
  77. package/dist/lib/hosts/passthrough.js +2 -10
  78. package/dist/lib/hosts/ready.d.ts +0 -4
  79. package/dist/lib/hosts/ready.js +0 -9
  80. package/dist/lib/hosts/reconcile.d.ts +0 -1
  81. package/dist/lib/hosts/reconcile.js +0 -8
  82. package/dist/lib/installations/migrate.d.ts +0 -2
  83. package/dist/lib/installations/migrate.js +0 -145
  84. package/dist/lib/loop.js +1 -2
  85. package/dist/lib/menubar/snapshot.d.ts +0 -1
  86. package/dist/lib/menubar/snapshot.js +1 -4
  87. package/dist/lib/placement.d.ts +1 -2
  88. package/dist/lib/placement.js +4 -24
  89. package/dist/lib/profiles.d.ts +0 -1
  90. package/dist/lib/profiles.js +0 -6
  91. package/dist/lib/session/active.d.ts +4 -3
  92. package/dist/lib/session/active.js +3 -4
  93. package/dist/lib/session/db.d.ts +7 -5
  94. package/dist/lib/session/db.js +11 -14
  95. package/dist/lib/session/discover.d.ts +3 -2
  96. package/dist/lib/session/discover.js +12 -129
  97. package/dist/lib/session/live-metadata.js +0 -2
  98. package/dist/lib/session/presentation.d.ts +0 -1
  99. package/dist/lib/session/presentation.js +3 -8
  100. package/dist/lib/session/selection.d.ts +0 -2
  101. package/dist/lib/session/selection.js +2 -12
  102. package/dist/lib/session/session-cache.d.ts +2 -1
  103. package/dist/lib/session/session-cache.js +1 -0
  104. package/dist/lib/session/title.d.ts +10 -0
  105. package/dist/lib/session/title.js +9 -0
  106. package/dist/lib/staleness/detectors/commands.d.ts +1 -1
  107. package/dist/lib/staleness/detectors/hooks.d.ts +1 -1
  108. package/dist/lib/staleness/detectors/mcp.d.ts +1 -1
  109. package/dist/lib/staleness/detectors/permissions.d.ts +1 -1
  110. package/dist/lib/staleness/detectors/plugins.d.ts +1 -1
  111. package/dist/lib/staleness/detectors/rules.d.ts +1 -1
  112. package/dist/lib/staleness/detectors/skills.d.ts +1 -1
  113. package/dist/lib/staleness/detectors/subagents.d.ts +1 -1
  114. package/dist/lib/staleness/detectors/workflows.d.ts +1 -1
  115. package/dist/lib/staleness/writers/commands.d.ts +1 -1
  116. package/dist/lib/staleness/writers/hooks.d.ts +1 -1
  117. package/dist/lib/staleness/writers/mcp.d.ts +1 -1
  118. package/dist/lib/staleness/writers/permissions.d.ts +1 -1
  119. package/dist/lib/staleness/writers/plugins.d.ts +1 -1
  120. package/dist/lib/staleness/writers/rules.d.ts +1 -1
  121. package/dist/lib/staleness/writers/skills.d.ts +1 -1
  122. package/dist/lib/staleness/writers/subagents.d.ts +1 -1
  123. package/dist/lib/staleness/writers/workflows.d.ts +1 -1
  124. package/dist/lib/startup/command-registry.js +5 -2
  125. package/dist/lib/state.d.ts +0 -3
  126. package/dist/lib/state.js +2 -25
  127. package/dist/lib/types.d.ts +0 -1
  128. package/dist/lib/watchdog/runner.d.ts +0 -2
  129. package/dist/lib/watchdog/runner.js +0 -2
  130. package/package.json +2 -2
  131. package/scripts/postinstall.js +2 -2
  132. package/dist/commands/routines.d.ts +0 -14
  133. package/dist/commands/routines.js +0 -2149
  134. package/dist/commands/routines.test-fixture.d.ts +0 -52
  135. package/dist/commands/routines.test-fixture.js +0 -254
  136. package/dist/lib/catchup.d.ts +0 -19
  137. package/dist/lib/catchup.js +0 -83
  138. package/dist/lib/daemon/catchup-service.d.ts +0 -18
  139. package/dist/lib/daemon/catchup-service.js +0 -21
  140. package/dist/lib/daemon/runner.d.ts +0 -91
  141. package/dist/lib/daemon/runner.js +0 -1927
  142. package/dist/lib/harness/adapters/droid.d.ts +0 -2
  143. package/dist/lib/harness/adapters/droid.js +0 -14
  144. package/dist/lib/overdue.d.ts +0 -9
  145. package/dist/lib/overdue.js +0 -74
  146. package/dist/lib/routine-activation.d.ts +0 -13
  147. package/dist/lib/routine-activation.js +0 -117
  148. package/dist/lib/routine-context.d.ts +0 -59
  149. package/dist/lib/routine-context.js +0 -181
  150. package/dist/lib/routine-notify-owner.d.ts +0 -4
  151. package/dist/lib/routine-notify-owner.js +0 -49
  152. package/dist/lib/routine-notify.d.ts +0 -17
  153. package/dist/lib/routine-notify.js +0 -138
  154. package/dist/lib/routine-process-cleanup.d.ts +0 -9
  155. package/dist/lib/routine-process-cleanup.js +0 -81
  156. package/dist/lib/routine-readiness.d.ts +0 -31
  157. package/dist/lib/routine-readiness.js +0 -256
  158. package/dist/lib/routines-format.d.ts +0 -7
  159. package/dist/lib/routines-format.js +0 -127
  160. package/dist/lib/routines-placement.d.ts +0 -16
  161. package/dist/lib/routines-placement.js +0 -60
  162. package/dist/lib/routines-project.d.ts +0 -49
  163. package/dist/lib/routines-project.js +0 -306
  164. package/dist/lib/sandbox.d.ts +0 -15
  165. package/dist/lib/sandbox.js +0 -309
  166. package/dist/lib/scheduler.d.ts +0 -23
  167. package/dist/lib/scheduler.js +0 -106
  168. package/dist/lib/scheduling/routines.d.ts +0 -264
  169. package/dist/lib/scheduling/routines.js +0 -1292
  170. package/dist/lib/triggers/webhook.d.ts +0 -26
  171. package/dist/lib/triggers/webhook.js +0 -181
@@ -1,2 +0,0 @@
1
- import type { HarnessAdapter } from '../adapter.js';
2
- export declare const droidAdapter: HarnessAdapter;
@@ -1,14 +0,0 @@
1
- export const droidAdapter = {
2
- id: 'droid',
3
- routineModeArgs(cmd, ctx) {
4
- if (ctx.mode === 'edit') {
5
- cmd.push('--auto', 'low');
6
- }
7
- else if (ctx.mode === 'auto') {
8
- cmd.push('--auto', 'high');
9
- }
10
- else if (ctx.mode === 'skip') {
11
- cmd.push('--skip-permissions-unsafe');
12
- }
13
- },
14
- };
@@ -1,9 +0,0 @@
1
- import { type JobConfig } from './scheduling/routines.js';
2
- export interface OverdueJob {
3
- name: string;
4
- expectedAt: Date;
5
- lastRanAt: Date | null;
6
- }
7
- export declare function routineEffectiveStart(job: JobConfig, now?: Date): Date | null;
8
- export declare function detectOverdueJobs(now?: Date): OverdueJob[];
9
- export declare function notifyOverdue(jobs: OverdueJob[]): void;
@@ -1,74 +0,0 @@
1
- import * as fs from 'fs';
2
- import { Cron } from 'croner';
3
- import { alignedSlotForFire, listJobs, getLatestRun, resolveJobFilePath, isPastEndAt, isOneShotRoutine, jobRunsOnThisDevice } from './scheduling/routines.js';
4
- import { notifyDesktop } from './menubar/notify-desktop.js';
5
- const GRACE_MS = 60_000;
6
- function previousExpectedFire(cron, now) {
7
- return alignedSlotForFire(cron, now);
8
- }
9
- export function routineEffectiveStart(job, now = new Date()) {
10
- if (job.createdAt) {
11
- const stamped = new Date(job.createdAt);
12
- if (!isNaN(stamped.getTime())) {
13
- return stamped.getTime() > now.getTime() ? now : stamped;
14
- }
15
- }
16
- const path = resolveJobFilePath(job.name);
17
- if (!path)
18
- return null;
19
- try {
20
- return new Date(fs.statSync(path).mtimeMs);
21
- }
22
- catch {
23
- return null;
24
- }
25
- }
26
- export function detectOverdueJobs(now = new Date()) {
27
- const overdue = [];
28
- for (const job of listJobs()) {
29
- if (!job.enabled)
30
- continue;
31
- if (isOneShotRoutine(job))
32
- continue;
33
- if (isPastEndAt(job, now))
34
- continue;
35
- if (!job.schedule)
36
- continue;
37
- if (!jobRunsOnThisDevice(job))
38
- continue;
39
- let expected = null;
40
- try {
41
- const cronOptions = { paused: true };
42
- if (job.timezone)
43
- cronOptions.timezone = job.timezone;
44
- const cron = new Cron(job.schedule, cronOptions);
45
- expected = previousExpectedFire(cron, now);
46
- cron.stop();
47
- }
48
- catch {
49
- continue;
50
- }
51
- if (!expected)
52
- continue;
53
- const start = routineEffectiveStart(job, now);
54
- if (start && expected.getTime() < start.getTime())
55
- continue;
56
- const latest = getLatestRun(job.name);
57
- const lastRanAt = latest ? new Date(latest.startedAt) : null;
58
- const isOverdue = !lastRanAt || lastRanAt.getTime() < expected.getTime() - GRACE_MS;
59
- if (isOverdue) {
60
- overdue.push({ name: job.name, expectedAt: expected, lastRanAt });
61
- }
62
- }
63
- return overdue;
64
- }
65
- export function notifyOverdue(jobs) {
66
- if (jobs.length === 0)
67
- return;
68
- const title = jobs.length === 1 ? 'Routine overdue' : `${jobs.length} routines overdue`;
69
- const subtitle = jobs.length === 1 ? jobs[0].name : undefined;
70
- const body = jobs.length === 1
71
- ? `Missed ${jobs[0].expectedAt.toLocaleString()}. Run: agents routines catchup`
72
- : `${jobs.map((j) => j.name).join(', ')} — agents routines catchup`;
73
- notifyDesktop({ title, subtitle, body, action: 'routines:list' });
74
- }
@@ -1,13 +0,0 @@
1
- export declare function normalizeRoutineNames(names: Iterable<string>): string[];
2
- export declare function enabledRoutineNames(): string[] | null;
3
- export declare function routineEnabledOnThisDevice(name: string): boolean | null;
4
- export declare function replaceEnabledRoutines(names: Iterable<string>): string[];
5
- export declare function setRoutineEnabledOnThisDevice(name: string, enabled: boolean, legacyEnabledNames?: Iterable<string>): string[];
6
- export declare function devicesWithRoutineEnabled(name: string): string[];
7
- export interface RoutineDeviceIndex {
8
- byRoutine: Map<string, string[]>;
9
- materialized: boolean;
10
- errors: string[];
11
- }
12
- export declare function routineDeviceIndex(): RoutineDeviceIndex;
13
- export declare function currentRoutineDevice(): string;
@@ -1,117 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as yaml from 'yaml';
4
- import { machineId } from './machine-id.js';
5
- import { getUserAgentsDir, readMeta, updateMeta } from './state.js';
6
- export function normalizeRoutineNames(names) {
7
- return [...new Set([...names].map((name) => name.trim()).filter(Boolean))].sort();
8
- }
9
- export function enabledRoutineNames() {
10
- const names = readMeta().deviceRoutines;
11
- return Array.isArray(names) ? normalizeRoutineNames(names) : null;
12
- }
13
- export function routineEnabledOnThisDevice(name) {
14
- const names = enabledRoutineNames();
15
- return names === null ? null : names.includes(name);
16
- }
17
- export function replaceEnabledRoutines(names) {
18
- const normalized = normalizeRoutineNames(names);
19
- updateMeta((meta) => ({ ...meta, deviceRoutines: normalized }));
20
- return normalized;
21
- }
22
- export function setRoutineEnabledOnThisDevice(name, enabled, legacyEnabledNames = []) {
23
- const current = enabledRoutineNames() ?? normalizeRoutineNames(legacyEnabledNames);
24
- const next = new Set(current);
25
- if (enabled)
26
- next.add(name);
27
- else
28
- next.delete(name);
29
- return replaceEnabledRoutines(next);
30
- }
31
- export function devicesWithRoutineEnabled(name) {
32
- const devicesDir = path.join(getUserAgentsDir(), 'devices');
33
- if (!fs.existsSync(devicesDir))
34
- return [];
35
- const devices = [];
36
- for (const entry of fs.readdirSync(devicesDir, { withFileTypes: true })) {
37
- if (!entry.isDirectory())
38
- continue;
39
- const file = path.join(devicesDir, entry.name, 'agents.yaml');
40
- if (!fs.existsSync(file))
41
- continue;
42
- let parsed;
43
- try {
44
- parsed = yaml.parse(fs.readFileSync(file, 'utf-8'));
45
- }
46
- catch (err) {
47
- throw new Error(`Device config corrupted at ${file}: ${err.message}`);
48
- }
49
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
50
- throw new Error(`Device config corrupted at ${file}: expected a YAML map.`);
51
- }
52
- const routines = parsed.routines;
53
- if (routines === undefined)
54
- continue;
55
- if (!Array.isArray(routines) || routines.some((routine) => typeof routine !== 'string')) {
56
- throw new Error(`Device config corrupted at ${file}: routines must be a string list.`);
57
- }
58
- if (routines.includes(name))
59
- devices.push(entry.name);
60
- }
61
- return devices.sort();
62
- }
63
- export function routineDeviceIndex() {
64
- const byRoutine = new Map();
65
- const errors = [];
66
- let materialized = false;
67
- const devicesDir = path.join(getUserAgentsDir(), 'devices');
68
- if (!fs.existsSync(devicesDir))
69
- return { byRoutine, materialized, errors };
70
- let entries;
71
- try {
72
- entries = fs.readdirSync(devicesDir, { withFileTypes: true });
73
- }
74
- catch (err) {
75
- return { byRoutine, materialized, errors: [`${devicesDir}: ${err.message}`] };
76
- }
77
- for (const entry of entries) {
78
- if (!entry.isDirectory())
79
- continue;
80
- const file = path.join(devicesDir, entry.name, 'agents.yaml');
81
- if (!fs.existsSync(file))
82
- continue;
83
- let parsed;
84
- try {
85
- parsed = yaml.parse(fs.readFileSync(file, 'utf-8'));
86
- }
87
- catch (err) {
88
- errors.push(`${file}: ${err.message.split('\n')[0]}`);
89
- continue;
90
- }
91
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
92
- errors.push(`${file}: expected a YAML map`);
93
- continue;
94
- }
95
- const routines = parsed.routines;
96
- if (routines === undefined)
97
- continue;
98
- if (!Array.isArray(routines) || routines.some((routine) => typeof routine !== 'string')) {
99
- errors.push(`${file}: routines must be a string list`);
100
- continue;
101
- }
102
- materialized = true;
103
- for (const name of normalizeRoutineNames(routines)) {
104
- const devices = byRoutine.get(name);
105
- if (devices)
106
- devices.push(entry.name);
107
- else
108
- byRoutine.set(name, [entry.name]);
109
- }
110
- }
111
- for (const devices of byRoutine.values())
112
- devices.sort();
113
- return { byRoutine, materialized, errors };
114
- }
115
- export function currentRoutineDevice() {
116
- return machineId();
117
- }
@@ -1,59 +0,0 @@
1
- export type RoutineReadinessCode = 'project_not_found' | 'project_path_missing' | 'cwd_missing' | 'cwd_not_directory' | 'cwd_not_portable' | 'execution_context_missing' | 'cloud_context_unsupported' | 'workspace_not_writable' | 'codex_workspace_untrusted' | 'agent_unavailable' | 'agent_auth_failed' | 'target_unreachable' | 'placement_unsupported' | 'migration_conflict';
2
- export interface RoutineReadiness {
3
- code: RoutineReadinessCode;
4
- message: string;
5
- repair?: string;
6
- }
7
- export type PlacementMode = 'local' | 'host' | 'fleet' | 'cloud';
8
- export type ProjectResolution = {
9
- defined: false;
10
- } | {
11
- defined: true;
12
- base?: string;
13
- };
14
- export type RoutineKind = 'agent' | 'workflow' | 'command';
15
- export interface ContextFsProbe {
16
- exists(absPath: string): boolean;
17
- isDirectory(absPath: string): boolean;
18
- isWritable(absPath: string): boolean;
19
- }
20
- export interface ExecutionContextInput {
21
- name?: string;
22
- project?: string;
23
- cwd?: string;
24
- kind: RoutineKind;
25
- mode: PlacementMode;
26
- targetHome: string;
27
- projectResolution?: ProjectResolution;
28
- probe?: ContextFsProbe;
29
- }
30
- export interface ResolvedExecutionContext {
31
- project?: string;
32
- requestedCwd?: string;
33
- resolvedCwd?: string;
34
- absoluteCwd?: string;
35
- targetHome: string;
36
- ready: boolean;
37
- readiness?: RoutineReadiness;
38
- }
39
- export declare function isBareRelative(home: string, p: string): boolean;
40
- export declare function resolveRoutineExecutionContext(input: ExecutionContextInput): ResolvedExecutionContext;
41
- interface HarnessReadinessProbes {
42
- agentInstalled?(): boolean;
43
- codexTrusted?(absoluteCwd: string): boolean;
44
- authOk?(): {
45
- ok: boolean;
46
- reason?: string;
47
- };
48
- targetReachable?(): boolean;
49
- }
50
- export interface RoutineReadinessResult {
51
- context: ResolvedExecutionContext;
52
- ready: boolean;
53
- readiness?: RoutineReadiness;
54
- }
55
- export declare function evaluateRoutineReadiness(context: ResolvedExecutionContext, probes?: HarnessReadinessProbes, opts?: {
56
- agent?: string;
57
- version?: string;
58
- }): RoutineReadinessResult;
59
- export {};
@@ -1,181 +0,0 @@
1
- import * as path from 'path';
2
- function targetPath(home) {
3
- return /^[A-Za-z]:[\\/]/.test(home) || home.includes('\\') ? path.win32 : path.posix;
4
- }
5
- function expandTargetHome(home, p) {
6
- if (p === '~' || p === '$HOME')
7
- return home;
8
- const tp = targetPath(home);
9
- if (p.startsWith('~/'))
10
- return tp.join(home, p.slice(2));
11
- if (p.startsWith('$HOME/'))
12
- return tp.join(home, p.slice('$HOME/'.length));
13
- return p;
14
- }
15
- function toTargetPortable(home, abs) {
16
- const tp = targetPath(home);
17
- const rel = tp.relative(home, abs);
18
- if (rel === '')
19
- return '~';
20
- if (!rel.startsWith('..') && !tp.isAbsolute(rel))
21
- return '~/' + rel.split(tp.sep).join('/');
22
- return abs;
23
- }
24
- export function isBareRelative(home, p) {
25
- return !targetPath(home).isAbsolute(p) && !p.startsWith('~') && !p.startsWith('$HOME');
26
- }
27
- function isInside(baseAbs, childAbs) {
28
- const tp = targetPath(baseAbs);
29
- const rel = tp.relative(baseAbs, childAbs);
30
- return rel === '' || (!rel.startsWith('..') && !tp.isAbsolute(rel));
31
- }
32
- function pause(ctx, readiness) {
33
- return { ...ctx, ready: false, readiness };
34
- }
35
- export function resolveRoutineExecutionContext(input) {
36
- const { project, cwd, kind, mode, targetHome, projectResolution, probe } = input;
37
- const requestedCwd = cwd;
38
- const base = { project, requestedCwd, targetHome };
39
- const hasProjectBinding = projectResolution?.defined === true;
40
- const finalize = (portable, missingCode) => {
41
- const absoluteCwd = expandTargetHome(targetHome, portable);
42
- const ctx = { ...base, resolvedCwd: portable, absoluteCwd };
43
- if (mode === 'cloud' && !hasProjectBinding) {
44
- return pause(ctx, {
45
- code: 'cloud_context_unsupported',
46
- message: `a bare cwd has no cloud repository to run in — bind a project/repo or run '${input.name ?? 'this routine'}' locally`,
47
- repair: `agents routines edit ${input.name ?? '<name>'} --project-anchor <name>`,
48
- });
49
- }
50
- if (probe) {
51
- if (!probe.exists(absoluteCwd)) {
52
- return pause(ctx, {
53
- code: missingCode,
54
- message: missingCode === 'project_path_missing'
55
- ? `project base directory does not exist on the target: ${portable}`
56
- : `execution directory does not exist on the target: ${portable}`,
57
- repair: `mkdir -p ${portable}`,
58
- });
59
- }
60
- if (!probe.isDirectory(absoluteCwd)) {
61
- return pause(ctx, {
62
- code: 'cwd_not_directory',
63
- message: `execution path is not a directory: ${portable}`,
64
- });
65
- }
66
- if (!probe.isWritable(absoluteCwd)) {
67
- return pause(ctx, {
68
- code: 'workspace_not_writable',
69
- message: `execution directory is not writable: ${portable}`,
70
- });
71
- }
72
- }
73
- return { ...ctx, ready: true };
74
- };
75
- if (project !== undefined) {
76
- if (!projectResolution || projectResolution.defined === false) {
77
- return pause(base, {
78
- code: 'project_not_found',
79
- message: `project '${project}' is not defined`,
80
- repair: `agents projects add ${project} --root <path>`,
81
- });
82
- }
83
- const projBase = projectResolution.base;
84
- if (projBase) {
85
- if (cwd === undefined) {
86
- return finalize(projBase, 'project_path_missing');
87
- }
88
- if (isBareRelative(targetHome, cwd)) {
89
- const baseAbs = expandTargetHome(targetHome, projBase);
90
- const joinedAbs = targetPath(targetHome).resolve(baseAbs, cwd);
91
- if (!isInside(baseAbs, joinedAbs)) {
92
- return pause(base, {
93
- code: 'cwd_not_portable',
94
- message: `cwd '${cwd}' escapes the project base '${projBase}' — a project-relative cwd must stay inside it`,
95
- });
96
- }
97
- return finalize(toTargetPortable(targetHome, joinedAbs), 'cwd_missing');
98
- }
99
- }
100
- else if (cwd === undefined) {
101
- return pause(base, {
102
- code: 'project_path_missing',
103
- message: `project '${project}' has no checkout path — give it a cwd (anchored at the target home) or set the project's root`,
104
- repair: `agents routines edit ${input.name ?? '<name>'} --cwd <path>`,
105
- });
106
- }
107
- }
108
- if (cwd !== undefined) {
109
- if (cwd.startsWith('~') || cwd.startsWith('$HOME')) {
110
- const abs = expandTargetHome(targetHome, cwd);
111
- return finalize(toTargetPortable(targetHome, abs), 'cwd_missing');
112
- }
113
- const cwdIsAbsolute = targetPath(targetHome).isAbsolute(cwd) ||
114
- path.posix.isAbsolute(cwd) ||
115
- path.win32.isAbsolute(cwd);
116
- if (cwdIsAbsolute) {
117
- const resolved = cwd;
118
- if (isInside(targetHome, resolved)) {
119
- return finalize(toTargetPortable(targetHome, resolved), 'cwd_missing');
120
- }
121
- if (mode === 'local') {
122
- return finalize(resolved, 'cwd_missing');
123
- }
124
- return pause(base, {
125
- code: 'cwd_not_portable',
126
- message: `absolute cwd '${cwd}' is outside the target home and cannot travel to ${mode} placement — use a home-relative path`,
127
- });
128
- }
129
- return finalize(toTargetPortable(targetHome, targetPath(targetHome).resolve(targetHome, cwd)), 'cwd_missing');
130
- }
131
- if (kind === 'command') {
132
- return finalize(toTargetPortable(targetHome, targetHome), 'cwd_missing');
133
- }
134
- return pause(base, {
135
- code: 'execution_context_missing',
136
- message: `routine '${input.name ?? ''}' has no project or cwd — an agent/workflow routine needs an explicit execution directory`,
137
- repair: `agents routines edit ${input.name ?? '<name>'} --project-anchor <name> # or --cwd <path>`,
138
- });
139
- }
140
- export function evaluateRoutineReadiness(context, probes = {}, opts = {}) {
141
- if (!context.ready) {
142
- return { context, ready: false, readiness: context.readiness };
143
- }
144
- if (probes.targetReachable && !probes.targetReachable()) {
145
- return withBlocker(context, {
146
- code: 'target_unreachable',
147
- message: 'the execution target is not reachable',
148
- });
149
- }
150
- if (probes.agentInstalled && !probes.agentInstalled()) {
151
- const pinned = opts.version && opts.agent ? `${opts.agent}@${opts.version}` : undefined;
152
- return withBlocker(context, {
153
- code: 'agent_unavailable',
154
- message: pinned
155
- ? `pinned ${pinned} is not installed on the target`
156
- : `no usable version of ${opts.agent ?? 'the agent'} is installed on the target`,
157
- repair: pinned ? `agents add ${pinned}` : (opts.agent ? `agents add ${opts.agent}@<version>` : undefined),
158
- });
159
- }
160
- if (probes.codexTrusted && context.absoluteCwd && !probes.codexTrusted(context.absoluteCwd)) {
161
- return withBlocker(context, {
162
- code: 'codex_workspace_untrusted',
163
- message: `Codex will not start in an untrusted workspace: ${context.resolvedCwd}`,
164
- repair: `trust the workspace (add it to Codex's trusted projects) — the routine never uses --skip-git-repo-check`,
165
- });
166
- }
167
- if (probes.authOk) {
168
- const verdict = probes.authOk();
169
- if (!verdict.ok) {
170
- return withBlocker(context, {
171
- code: 'agent_auth_failed',
172
- message: `the selected account failed a live auth check${verdict.reason ? `: ${verdict.reason}` : ''}`,
173
- repair: opts.agent ? `agents run ${opts.agent} -- login` : 'log the account back in',
174
- });
175
- }
176
- }
177
- return { context, ready: true };
178
- }
179
- function withBlocker(context, readiness) {
180
- return { context: { ...context, ready: false, readiness }, ready: false, readiness };
181
- }
@@ -1,4 +0,0 @@
1
- import type { JobConfig, RunMeta } from './scheduling/routines.js';
2
- import { type OwnerNotifyResult } from './owner-notify.js';
3
- export declare function notifyOwnerRoutineFinish(meta: RunMeta): Promise<OwnerNotifyResult | null>;
4
- export declare function notifyOwnerRoutineStartFailed(config: JobConfig, error: string, scheduledFor?: Date): Promise<OwnerNotifyResult>;
@@ -1,49 +0,0 @@
1
- import * as os from 'os';
2
- import { routineKind } from './routine-notify.js';
3
- import { postOwnerNotification } from './owner-notify.js';
4
- function routineLabel(r) {
5
- const kind = routineKind(r);
6
- if (kind === 'command')
7
- return 'command';
8
- if (kind === 'workflow')
9
- return `workflow ${r.workflow}`;
10
- return `agent ${r.agent ?? 'unknown'}`;
11
- }
12
- function failureReason(meta) {
13
- if (meta.status === 'timeout')
14
- return 'Timed out';
15
- if (meta.errorMessage)
16
- return meta.errorMessage;
17
- return `Exited with code ${meta.exitCode ?? '?'}`;
18
- }
19
- function routineFinishOwnerText(meta, host) {
20
- if (meta.status !== 'failed' && meta.status !== 'timeout')
21
- return null;
22
- return `${failureReason(meta)}\n${routineLabel(meta)} · ${host}`;
23
- }
24
- function routineStartFailedOwnerText(config, error, host) {
25
- return `${error}\n${routineLabel(config)} · ${host}`;
26
- }
27
- export async function notifyOwnerRoutineFinish(meta) {
28
- const host = os.hostname();
29
- const body = routineFinishOwnerText(meta, host);
30
- if (!body)
31
- return null;
32
- return postOwnerNotification({
33
- event: 'failed',
34
- title: `Routine failed: ${meta.jobName}`,
35
- body,
36
- dedupKey: `routine:${meta.jobName}:${meta.runId}`,
37
- source: { device: host, agent: 'routines' },
38
- });
39
- }
40
- export async function notifyOwnerRoutineStartFailed(config, error, scheduledFor = new Date()) {
41
- const host = os.hostname();
42
- return postOwnerNotification({
43
- event: 'failed',
44
- title: `Routine failed to start: ${config.name}`,
45
- body: routineStartFailedOwnerText(config, error, host),
46
- dedupKey: `routine-start:${config.name}:${scheduledFor.toISOString()}`,
47
- source: { device: host, agent: 'routines' },
48
- });
49
- }
@@ -1,17 +0,0 @@
1
- import type { JobConfig, RunMeta } from './scheduling/routines.js';
2
- import { type DesktopNotification } from './menubar/notify-desktop.js';
3
- type RoutineKind = 'agent' | 'workflow' | 'command';
4
- export declare function routineKind(r: Pick<JobConfig, 'agent' | 'workflow' | 'command'>): RoutineKind;
5
- export declare function routineAgent(r: Pick<JobConfig, 'agent' | 'workflow' | 'command'>): string | undefined;
6
- export declare function formatDuration(ms: number | undefined): string | null;
7
- export declare function notableSnippet(report: string | null | undefined, maxLen?: number): string | null;
8
- export declare function routineStartNotification(config: Pick<JobConfig, 'name' | 'agent' | 'workflow' | 'command'>): DesktopNotification | null;
9
- export declare function routineStartFailedNotification(config: Pick<JobConfig, 'name' | 'agent' | 'workflow' | 'command'>, error: string): DesktopNotification;
10
- export declare function routineFinishNotification(meta: Pick<RunMeta, 'jobName' | 'status' | 'exitCode' | 'errorMessage' | 'duration' | 'agent' | 'workflow' | 'command'>, opts?: {
11
- report?: string | null;
12
- artifactPath?: string | null;
13
- }): DesktopNotification | null;
14
- export declare function notifyRoutineStart(config: JobConfig): void;
15
- export declare function notifyRoutineStartFailed(config: JobConfig, error: string): void;
16
- export declare function notifyRoutineFinish(meta: RunMeta): void;
17
- export {};