@oss-autopilot/core 3.21.1 → 3.22.1
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/dist/cli-registry.js +73 -4
- package/dist/cli.bundle.cjs +195 -195
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/overnight.d.ts +120 -0
- package/dist/commands/overnight.js +359 -0
- package/dist/commands/parse-list.js +4 -2
- package/dist/commands/scout-bridge.js +6 -9
- package/dist/commands/search.js +12 -1
- package/dist/commands/startup.js +4 -0
- package/dist/core/config-registry.js +3 -3
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +8 -0
- package/dist/core/state-schema.d.ts +47 -0
- package/dist/core/state-schema.js +36 -13
- package/dist/core/state.d.ts +9 -1
- package/dist/core/state.js +18 -0
- package/dist/core/types.d.ts +1 -1
- package/dist/formatters/json.d.ts +13 -4
- package/dist/formatters/json.js +2 -2
- package/package.json +8 -8
package/dist/commands/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export { runDailyForDisplay } from './daily.js';
|
|
|
19
19
|
export { executeDailyCheck } from './daily.js';
|
|
20
20
|
/** Combined startup: auth check, setup check, daily fetch, dashboard launch, version detection. */
|
|
21
21
|
export { runStartup } from './startup.js';
|
|
22
|
+
/** Overnight prepare-and-queue run, branch recording, launchd schedule rendering (#1574). */
|
|
23
|
+
export { runOvernight, runOvernightRecord, runOvernightSchedule } from './overnight.js';
|
|
22
24
|
/** Return contribution statistics (merge rate, PR counts, repo breakdown) from local state. */
|
|
23
25
|
export { runStatus } from './status.js';
|
|
24
26
|
/** On-demand strategy snapshot via the typed `computeStrategy` core function (#1243 step 4). */
|
package/dist/commands/index.js
CHANGED
|
@@ -20,6 +20,8 @@ export { runDailyForDisplay } from './daily.js';
|
|
|
20
20
|
export { executeDailyCheck } from './daily.js';
|
|
21
21
|
/** Combined startup: auth check, setup check, daily fetch, dashboard launch, version detection. */
|
|
22
22
|
export { runStartup } from './startup.js';
|
|
23
|
+
/** Overnight prepare-and-queue run, branch recording, launchd schedule rendering (#1574). */
|
|
24
|
+
export { runOvernight, runOvernightRecord, runOvernightSchedule } from './overnight.js';
|
|
23
25
|
/** Return contribution statistics (merge rate, PR counts, repo breakdown) from local state. */
|
|
24
26
|
export { runStatus } from './status.js';
|
|
25
27
|
/** On-demand strategy snapshot via the typed `computeStrategy` core function (#1243 step 4). */
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overnight autonomous mode (#1574): "prepare and queue", never "act externally".
|
|
3
|
+
*
|
|
4
|
+
* `overnight` runs the same check as `daily`, then splits what it found into
|
|
5
|
+
* work an implementation agent can prepare in an isolated worktree without any
|
|
6
|
+
* external side effect (`prepare`) and items that need a human reply or
|
|
7
|
+
* decision (`judgment`). It writes a dated morning report under
|
|
8
|
+
* `~/.oss-autopilot/reports/` and records the run in state so `startup` can
|
|
9
|
+
* surface its freshness.
|
|
10
|
+
*
|
|
11
|
+
* `overnight record` appends one prepared branch to the report and to state;
|
|
12
|
+
* the plugin calls it after each agent finishes. `overnight schedule` renders
|
|
13
|
+
* the launchd plist that runs the plugin command headlessly.
|
|
14
|
+
*
|
|
15
|
+
* Hard gate: nothing in this module pushes, posts, or merges. That gate is the
|
|
16
|
+
* feature, not a limitation.
|
|
17
|
+
*/
|
|
18
|
+
import type { PRCheckFailure } from '../core/pr-monitor.js';
|
|
19
|
+
import type { ActionableIssueType, OvernightPrepared } from '../core/types.js';
|
|
20
|
+
import type { DailyOutput, DailyWarning } from '../formatters/json.js';
|
|
21
|
+
import type { AttentionSummary } from '../core/pr-attention.js';
|
|
22
|
+
/** One item in either bucket; which bucket is the array it lives in. */
|
|
23
|
+
export interface OvernightItem {
|
|
24
|
+
/** PR or issue URL. */
|
|
25
|
+
url: string;
|
|
26
|
+
type: ActionableIssueType | 'issue_reply';
|
|
27
|
+
label: string;
|
|
28
|
+
/** One line of why it landed in its bucket, for the report. */
|
|
29
|
+
reason: string;
|
|
30
|
+
}
|
|
31
|
+
export interface OvernightOutput {
|
|
32
|
+
runAt: string;
|
|
33
|
+
reportPath: string;
|
|
34
|
+
prepare: OvernightItem[];
|
|
35
|
+
judgment: OvernightItem[];
|
|
36
|
+
attention: AttentionSummary;
|
|
37
|
+
/** PRs the daily check could not fetch; each is absent from the buckets above. */
|
|
38
|
+
failures: PRCheckFailure[];
|
|
39
|
+
warnings: DailyWarning[];
|
|
40
|
+
/** Branches carried over from an earlier run on the same date (a re-run never drops recorded work). */
|
|
41
|
+
carriedPrepared: number;
|
|
42
|
+
/** Set when the run could not be pushed to the Gist; the local cache has it. */
|
|
43
|
+
gistSyncWarning?: string;
|
|
44
|
+
}
|
|
45
|
+
type ReportBody = Pick<OvernightOutput, 'runAt' | 'prepare' | 'judgment' | 'attention' | 'failures' | 'warnings'>;
|
|
46
|
+
/** Freshness block `startup` surfaces (#1574). */
|
|
47
|
+
export interface OvernightFreshness {
|
|
48
|
+
runAt: string;
|
|
49
|
+
reportPath: string;
|
|
50
|
+
/** Whole hours since the run; absent when `runAt` does not parse (see `runAtInvalid`). */
|
|
51
|
+
ageHours?: number;
|
|
52
|
+
runAtInvalid?: true;
|
|
53
|
+
prepareCount: number;
|
|
54
|
+
judgmentCount: number;
|
|
55
|
+
/** Branches recorded via `overnight record` since the run. */
|
|
56
|
+
preparedCount: number;
|
|
57
|
+
}
|
|
58
|
+
/** Pure: split the daily check into prepare vs judgment items. */
|
|
59
|
+
export declare function bucketize(daily: Pick<DailyOutput, 'actionableIssues' | 'commentedIssues'>): {
|
|
60
|
+
prepare: OvernightItem[];
|
|
61
|
+
judgment: OvernightItem[];
|
|
62
|
+
};
|
|
63
|
+
/** Pure: the "Prepared branches" section; `record` rewrites just this part. */
|
|
64
|
+
export declare function renderPreparedSection(prepared: OvernightPrepared[]): string;
|
|
65
|
+
/** Pure: the morning report. Prepared branches are appended by `record`. */
|
|
66
|
+
export declare function renderReport(out: ReportBody, prepared?: OvernightPrepared[]): string;
|
|
67
|
+
/** Local calendar date: the job fires at a local hour, so the report is filed under the local day. */
|
|
68
|
+
export declare function reportDateFor(d: Date): string;
|
|
69
|
+
export declare function runOvernight(): Promise<OvernightOutput>;
|
|
70
|
+
export interface OvernightRecordOptions {
|
|
71
|
+
url: string;
|
|
72
|
+
branch: string;
|
|
73
|
+
worktree?: string;
|
|
74
|
+
note?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface OvernightRecordOutput {
|
|
77
|
+
reportPath: string;
|
|
78
|
+
preparedCount: number;
|
|
79
|
+
/** The report file was missing and has been recreated with only the prepared section. */
|
|
80
|
+
reportRecreated?: true;
|
|
81
|
+
gistSyncWarning?: string;
|
|
82
|
+
}
|
|
83
|
+
/** Append one prepared branch to state and to the report of the latest run. */
|
|
84
|
+
export declare function runOvernightRecord(options: OvernightRecordOptions): Promise<OvernightRecordOutput>;
|
|
85
|
+
/** Pure: swap the "Prepared branches" section (up to the next `## `) for `section`. */
|
|
86
|
+
export declare function replacePreparedSection(report: string, section: string): string;
|
|
87
|
+
/** Freshness for `startup` (#1574); undefined before the first overnight run. */
|
|
88
|
+
export declare function overnightFreshness(now?: Date): OvernightFreshness | undefined;
|
|
89
|
+
export interface ScheduleOptions {
|
|
90
|
+
/** Local hour (0-23) the job fires. */
|
|
91
|
+
hour: number;
|
|
92
|
+
/** Path to the `claude` binary; launchd does not inherit a shell PATH. */
|
|
93
|
+
claudePath: string;
|
|
94
|
+
install: boolean;
|
|
95
|
+
}
|
|
96
|
+
export declare const LAUNCHD_LABEL = "com.oss-autopilot.overnight";
|
|
97
|
+
/**
|
|
98
|
+
* Deny list layered under the allowlist (deny beats allow): even if a future
|
|
99
|
+
* allow rule widens, these never run unattended. `AskUserQuestion` is denied
|
|
100
|
+
* because nobody can answer; the preparer agent reports `blocked` instead.
|
|
101
|
+
*/
|
|
102
|
+
export declare const OVERNIGHT_DISALLOWED_TOOLS: string;
|
|
103
|
+
export declare const OVERNIGHT_ALLOWED_TOOLS: string;
|
|
104
|
+
/** Pure: the launchd plist that runs `/oss-overnight` headlessly. */
|
|
105
|
+
export declare function renderLaunchdPlist(options: Pick<ScheduleOptions, 'hour' | 'claudePath'>, logPath: string): string;
|
|
106
|
+
export interface ScheduleOutput {
|
|
107
|
+
plist: string;
|
|
108
|
+
plistPath: string;
|
|
109
|
+
installed: boolean;
|
|
110
|
+
/** The one command the user runs to (re)load the job. */
|
|
111
|
+
loadCommand: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* launchd runs the plist with its own PATH, so a bare `claude` that resolves in
|
|
115
|
+
* the user's shell would fail silently at 02:00 into the log. Resolve it now,
|
|
116
|
+
* against this process's PATH, and embed the absolute path.
|
|
117
|
+
*/
|
|
118
|
+
export declare function resolveClaudePath(claudePath: string, envPath?: string | undefined): string;
|
|
119
|
+
export declare function runOvernightSchedule(options: ScheduleOptions): ScheduleOutput;
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overnight autonomous mode (#1574): "prepare and queue", never "act externally".
|
|
3
|
+
*
|
|
4
|
+
* `overnight` runs the same check as `daily`, then splits what it found into
|
|
5
|
+
* work an implementation agent can prepare in an isolated worktree without any
|
|
6
|
+
* external side effect (`prepare`) and items that need a human reply or
|
|
7
|
+
* decision (`judgment`). It writes a dated morning report under
|
|
8
|
+
* `~/.oss-autopilot/reports/` and records the run in state so `startup` can
|
|
9
|
+
* surface its freshness.
|
|
10
|
+
*
|
|
11
|
+
* `overnight record` appends one prepared branch to the report and to state;
|
|
12
|
+
* the plugin calls it after each agent finishes. `overnight schedule` renders
|
|
13
|
+
* the launchd plist that runs the plugin command headlessly.
|
|
14
|
+
*
|
|
15
|
+
* Hard gate: nothing in this module pushes, posts, or merges. That gate is the
|
|
16
|
+
* feature, not a limitation.
|
|
17
|
+
*/
|
|
18
|
+
import * as fs from 'node:fs';
|
|
19
|
+
import * as os from 'node:os';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import { getStateManager, maybeCheckpoint, requireGitHubToken } from '../core/index.js';
|
|
22
|
+
import { warn } from '../core/logger.js';
|
|
23
|
+
import { getReportsDir } from '../core/paths.js';
|
|
24
|
+
import { executeDailyCheck } from './daily.js';
|
|
25
|
+
const MODULE = 'overnight';
|
|
26
|
+
// ponytail: static table, not a classifier. Every ActionableIssueType is
|
|
27
|
+
// listed: the Record key type makes a new variant fail typecheck here.
|
|
28
|
+
const BUCKET_BY_TYPE = {
|
|
29
|
+
ci_failing: { bucket: 'prepare', reason: 'CI is red: an agent can diagnose and prepare a fix branch' },
|
|
30
|
+
merge_conflict: { bucket: 'prepare', reason: 'merge conflict: an agent can rebase in a worktree' },
|
|
31
|
+
needs_changes: { bucket: 'prepare', reason: 'changes requested: an agent can prepare the requested edits' },
|
|
32
|
+
incomplete_checklist: { bucket: 'prepare', reason: 'checklist incomplete: an agent can fill in the missing items' },
|
|
33
|
+
needs_response: { bucket: 'judgment', reason: 'a maintainer is waiting on your reply' },
|
|
34
|
+
};
|
|
35
|
+
/** Pure: split the daily check into prepare vs judgment items. */
|
|
36
|
+
export function bucketize(daily) {
|
|
37
|
+
const prepare = [];
|
|
38
|
+
const judgment = [];
|
|
39
|
+
for (const issue of daily.actionableIssues) {
|
|
40
|
+
const rule = BUCKET_BY_TYPE[issue.type];
|
|
41
|
+
(rule.bucket === 'prepare' ? prepare : judgment).push({
|
|
42
|
+
url: issue.prUrl,
|
|
43
|
+
type: issue.type,
|
|
44
|
+
label: issue.label,
|
|
45
|
+
reason: rule.reason,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
for (const c of daily.commentedIssues) {
|
|
49
|
+
if (c.status !== 'new_response')
|
|
50
|
+
continue;
|
|
51
|
+
judgment.push({
|
|
52
|
+
url: c.url,
|
|
53
|
+
type: 'issue_reply',
|
|
54
|
+
label: `[Issue reply] ${c.repo}#${c.number}`,
|
|
55
|
+
reason: `${c.isFromMaintainer ? 'a maintainer' : c.lastResponseAuthor} replied on an issue you commented on`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return { prepare, judgment };
|
|
59
|
+
}
|
|
60
|
+
const PREPARED_HEADING = '## Prepared branches (';
|
|
61
|
+
/** Pure: the "Prepared branches" section; `record` rewrites just this part. */
|
|
62
|
+
export function renderPreparedSection(prepared) {
|
|
63
|
+
const lines = [`${PREPARED_HEADING}${prepared.length})`, ''];
|
|
64
|
+
if (prepared.length === 0)
|
|
65
|
+
lines.push('_None recorded yet._');
|
|
66
|
+
for (const p of prepared) {
|
|
67
|
+
lines.push(`- ${p.url} — branch \`${p.branch}\`${p.worktree ? ` at ${p.worktree}` : ''}${p.note ? `: ${p.note}` : ''}`);
|
|
68
|
+
}
|
|
69
|
+
lines.push('');
|
|
70
|
+
return lines.join('\n');
|
|
71
|
+
}
|
|
72
|
+
/** Pure: the morning report. Prepared branches are appended by `record`. */
|
|
73
|
+
export function renderReport(out, prepared = []) {
|
|
74
|
+
const lines = [];
|
|
75
|
+
lines.push(`# Overnight report — ${reportDateFor(new Date(out.runAt))}`, '');
|
|
76
|
+
lines.push(`Run at ${out.runAt}. Nothing was pushed, posted, or merged.`, '');
|
|
77
|
+
lines.push(`Attention: ${out.attention.needsAttention} need attention, ${out.attention.stuckCI} stuck CI, ${out.attention.dormantFollowup} dormant, ${out.attention.waiting} waiting.`, '');
|
|
78
|
+
lines.push(renderPreparedSection(prepared));
|
|
79
|
+
lines.push(`## Queued for preparation (${out.prepare.length})`, '');
|
|
80
|
+
if (out.prepare.length === 0)
|
|
81
|
+
lines.push('_Nothing to prepare._');
|
|
82
|
+
for (const i of out.prepare)
|
|
83
|
+
lines.push(`- ${i.label} ${i.url} — ${i.reason}`);
|
|
84
|
+
lines.push('');
|
|
85
|
+
lines.push(`## Needs your judgment (${out.judgment.length})`, '');
|
|
86
|
+
if (out.judgment.length === 0)
|
|
87
|
+
lines.push('_Nothing waiting on you._');
|
|
88
|
+
for (const i of out.judgment)
|
|
89
|
+
lines.push(`- ${i.label} ${i.url} — ${i.reason}`);
|
|
90
|
+
lines.push('');
|
|
91
|
+
if (out.failures.length > 0 || out.warnings.length > 0) {
|
|
92
|
+
lines.push('## Check problems', '');
|
|
93
|
+
for (const f of out.failures)
|
|
94
|
+
lines.push(`- ${f.prUrl} could not be fetched (not bucketed): ${f.error}`);
|
|
95
|
+
for (const w of out.warnings)
|
|
96
|
+
lines.push(`- [${w.phase}] ${w.operation}: ${w.message}`);
|
|
97
|
+
lines.push('');
|
|
98
|
+
}
|
|
99
|
+
return lines.join('\n');
|
|
100
|
+
}
|
|
101
|
+
/** Local calendar date: the job fires at a local hour, so the report is filed under the local day. */
|
|
102
|
+
export function reportDateFor(d) {
|
|
103
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
104
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
|
|
105
|
+
}
|
|
106
|
+
function reportPathFor(d) {
|
|
107
|
+
return path.join(getReportsDir(), `overnight-${reportDateFor(d)}.md`);
|
|
108
|
+
}
|
|
109
|
+
export async function runOvernight() {
|
|
110
|
+
const sm = getStateManager();
|
|
111
|
+
const daily = await executeDailyCheck(requireGitHubToken());
|
|
112
|
+
const now = new Date();
|
|
113
|
+
const runAt = now.toISOString();
|
|
114
|
+
const { prepare, judgment } = bucketize(daily);
|
|
115
|
+
const body = {
|
|
116
|
+
runAt,
|
|
117
|
+
prepare,
|
|
118
|
+
judgment,
|
|
119
|
+
attention: daily.attention,
|
|
120
|
+
failures: daily.failures,
|
|
121
|
+
warnings: daily.warnings,
|
|
122
|
+
};
|
|
123
|
+
const reportPath = reportPathFor(now);
|
|
124
|
+
// A re-run on the same date (launchd retry, manual) must not drop branches
|
|
125
|
+
// already recorded: they are still on disk, so keep them in state and report.
|
|
126
|
+
const previous = sm.getLastOvernight();
|
|
127
|
+
const carried = previous?.reportPath === reportPath ? previous.prepared : [];
|
|
128
|
+
fs.writeFileSync(reportPath, renderReport(body, carried), { mode: 0o600 });
|
|
129
|
+
sm.setLastOvernight({
|
|
130
|
+
runAt,
|
|
131
|
+
reportPath,
|
|
132
|
+
prepareCount: prepare.length,
|
|
133
|
+
judgmentCount: judgment.length,
|
|
134
|
+
prepared: carried,
|
|
135
|
+
});
|
|
136
|
+
// executeDailyCheck already checkpointed the Gist; this write came after it,
|
|
137
|
+
// and in Gist mode setLastOvernight only reaches the local cache (#1629 class).
|
|
138
|
+
const gistSyncWarning = await maybeCheckpoint(sm, MODULE);
|
|
139
|
+
return { ...body, reportPath, carriedPrepared: carried.length, ...(gistSyncWarning ? { gistSyncWarning } : {}) };
|
|
140
|
+
}
|
|
141
|
+
/** Append one prepared branch to state and to the report of the latest run. */
|
|
142
|
+
export async function runOvernightRecord(options) {
|
|
143
|
+
const sm = getStateManager();
|
|
144
|
+
const last = sm.getLastOvernight();
|
|
145
|
+
if (!last)
|
|
146
|
+
throw new Error('No overnight run recorded yet; run `overnight` first.');
|
|
147
|
+
const entry = {
|
|
148
|
+
url: options.url,
|
|
149
|
+
branch: options.branch,
|
|
150
|
+
worktree: options.worktree,
|
|
151
|
+
note: options.note,
|
|
152
|
+
recordedAt: new Date().toISOString(),
|
|
153
|
+
};
|
|
154
|
+
const prepared = [...last.prepared, entry];
|
|
155
|
+
sm.setLastOvernight({ ...last, prepared });
|
|
156
|
+
// Rewrite the section in place (state is the source of truth for the
|
|
157
|
+
// list) so its heading count stays right; a report someone deleted is
|
|
158
|
+
// recreated with just this section rather than failing the record.
|
|
159
|
+
const reportExists = fs.existsSync(last.reportPath);
|
|
160
|
+
if (!reportExists)
|
|
161
|
+
warn(MODULE, `Report ${last.reportPath} is missing; recreating it with only the prepared section`);
|
|
162
|
+
const reportBody = reportExists ? fs.readFileSync(last.reportPath, 'utf8') : '';
|
|
163
|
+
fs.writeFileSync(last.reportPath, replacePreparedSection(reportBody, renderPreparedSection(prepared)), {
|
|
164
|
+
mode: 0o600,
|
|
165
|
+
});
|
|
166
|
+
const gistSyncWarning = await maybeCheckpoint(sm, MODULE);
|
|
167
|
+
return {
|
|
168
|
+
reportPath: last.reportPath,
|
|
169
|
+
preparedCount: prepared.length,
|
|
170
|
+
...(reportExists ? {} : { reportRecreated: true }),
|
|
171
|
+
...(gistSyncWarning ? { gistSyncWarning } : {}),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Pure: swap the "Prepared branches" section (up to the next `## `) for `section`. */
|
|
175
|
+
export function replacePreparedSection(report, section) {
|
|
176
|
+
const start = report.indexOf(PREPARED_HEADING);
|
|
177
|
+
if (start === -1)
|
|
178
|
+
return report.length === 0 ? section : `${report.trimEnd()}\n\n${section}`;
|
|
179
|
+
const next = report.indexOf('\n## ', start + PREPARED_HEADING.length);
|
|
180
|
+
return report.slice(0, start) + section + (next === -1 ? '' : report.slice(next));
|
|
181
|
+
}
|
|
182
|
+
/** Freshness for `startup` (#1574); undefined before the first overnight run. */
|
|
183
|
+
export function overnightFreshness(now = new Date()) {
|
|
184
|
+
const last = getStateManager().getLastOvernight();
|
|
185
|
+
if (!last)
|
|
186
|
+
return undefined;
|
|
187
|
+
const ageMs = now.getTime() - Date.parse(last.runAt);
|
|
188
|
+
const base = {
|
|
189
|
+
runAt: last.runAt,
|
|
190
|
+
reportPath: last.reportPath,
|
|
191
|
+
prepareCount: last.prepareCount,
|
|
192
|
+
judgmentCount: last.judgmentCount,
|
|
193
|
+
preparedCount: last.prepared.length,
|
|
194
|
+
};
|
|
195
|
+
// Never emit a non-finite number into the JSON contract (Infinity serialises as null).
|
|
196
|
+
return Number.isNaN(ageMs)
|
|
197
|
+
? { ...base, runAtInvalid: true }
|
|
198
|
+
: { ...base, ageHours: Math.max(0, Math.round(ageMs / 36e5)) };
|
|
199
|
+
}
|
|
200
|
+
export const LAUNCHD_LABEL = 'com.oss-autopilot.overnight';
|
|
201
|
+
/**
|
|
202
|
+
* Tools the headless run may use without a prompt (see commands/oss-overnight.md).
|
|
203
|
+
*
|
|
204
|
+
* The allowlist is the enforcement half of the no-side-effects gate, so it is
|
|
205
|
+
* enumerated, not wildcarded: every git subcommand except `push`, only the
|
|
206
|
+
* read side of `gh` (no `create`/`comment`/`merge`/`close`/`rerun`, no `gh api`
|
|
207
|
+
* because it can POST), and no `bash`/`sh`/`npx` shell escapes. `node`, `pnpm`
|
|
208
|
+
* and `npm` stay because the CLI bundle and a repo's test suite are already
|
|
209
|
+
* arbitrary code; the credential-bearing writes are what the list keeps out.
|
|
210
|
+
* Stronger isolation (a dedicated user with no push credentials, or a
|
|
211
|
+
* container) is the upgrade path if that trust level is not acceptable.
|
|
212
|
+
*/
|
|
213
|
+
const GIT_SUBCOMMANDS = [
|
|
214
|
+
'clone',
|
|
215
|
+
'fetch',
|
|
216
|
+
'worktree',
|
|
217
|
+
'checkout',
|
|
218
|
+
'switch',
|
|
219
|
+
'branch',
|
|
220
|
+
'rebase',
|
|
221
|
+
'merge-base',
|
|
222
|
+
'status',
|
|
223
|
+
'diff',
|
|
224
|
+
'log',
|
|
225
|
+
'show',
|
|
226
|
+
'add',
|
|
227
|
+
'commit',
|
|
228
|
+
'rev-parse',
|
|
229
|
+
'remote',
|
|
230
|
+
];
|
|
231
|
+
const GH_READ_SUBCOMMANDS = [
|
|
232
|
+
'pr view',
|
|
233
|
+
'pr checks',
|
|
234
|
+
'pr diff',
|
|
235
|
+
'pr list',
|
|
236
|
+
'run view',
|
|
237
|
+
'run list',
|
|
238
|
+
'issue view',
|
|
239
|
+
'repo view',
|
|
240
|
+
'auth status',
|
|
241
|
+
];
|
|
242
|
+
/**
|
|
243
|
+
* Deny list layered under the allowlist (deny beats allow): even if a future
|
|
244
|
+
* allow rule widens, these never run unattended. `AskUserQuestion` is denied
|
|
245
|
+
* because nobody can answer; the preparer agent reports `blocked` instead.
|
|
246
|
+
*/
|
|
247
|
+
export const OVERNIGHT_DISALLOWED_TOOLS = [
|
|
248
|
+
'Bash(git push)',
|
|
249
|
+
'Bash(git push *)',
|
|
250
|
+
'Bash(gh pr create *)',
|
|
251
|
+
'Bash(gh pr comment *)',
|
|
252
|
+
'Bash(gh pr merge *)',
|
|
253
|
+
'Bash(gh pr close *)',
|
|
254
|
+
'Bash(gh pr edit *)',
|
|
255
|
+
'Bash(gh pr ready *)',
|
|
256
|
+
'Bash(gh issue create *)',
|
|
257
|
+
'Bash(gh issue comment *)',
|
|
258
|
+
'Bash(gh issue close *)',
|
|
259
|
+
'Bash(gh run rerun *)',
|
|
260
|
+
'Bash(gh api *)',
|
|
261
|
+
'AskUserQuestion',
|
|
262
|
+
].join(',');
|
|
263
|
+
export const OVERNIGHT_ALLOWED_TOOLS = [
|
|
264
|
+
'Read',
|
|
265
|
+
'Edit',
|
|
266
|
+
'Write',
|
|
267
|
+
'Glob',
|
|
268
|
+
'Grep',
|
|
269
|
+
'Task',
|
|
270
|
+
...GIT_SUBCOMMANDS.map((sub) => `Bash(git ${sub} *)`),
|
|
271
|
+
...GH_READ_SUBCOMMANDS.map((sub) => `Bash(gh ${sub} *)`),
|
|
272
|
+
'Bash(node *)',
|
|
273
|
+
'Bash(pnpm *)',
|
|
274
|
+
'Bash(npm *)',
|
|
275
|
+
].join(',');
|
|
276
|
+
function xmlEscape(s) {
|
|
277
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
278
|
+
}
|
|
279
|
+
/** Pure: the launchd plist that runs `/oss-overnight` headlessly. */
|
|
280
|
+
export function renderLaunchdPlist(options, logPath) {
|
|
281
|
+
// Headless `-p` starts in manual permission mode, where any unapproved tool
|
|
282
|
+
// call fails (nobody can answer). `dontAsk` + the enumerated allowlist above
|
|
283
|
+
// is the documented unattended shape and the enforcement half of the gate.
|
|
284
|
+
const args = [
|
|
285
|
+
options.claudePath,
|
|
286
|
+
'-p',
|
|
287
|
+
'/oss-overnight',
|
|
288
|
+
'--permission-mode',
|
|
289
|
+
'dontAsk',
|
|
290
|
+
'--allowedTools',
|
|
291
|
+
OVERNIGHT_ALLOWED_TOOLS,
|
|
292
|
+
'--disallowedTools',
|
|
293
|
+
OVERNIGHT_DISALLOWED_TOOLS,
|
|
294
|
+
'--output-format',
|
|
295
|
+
'text',
|
|
296
|
+
];
|
|
297
|
+
return [
|
|
298
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
299
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
300
|
+
'<plist version="1.0">',
|
|
301
|
+
'<dict>',
|
|
302
|
+
` <key>Label</key><string>${LAUNCHD_LABEL}</string>`,
|
|
303
|
+
' <key>ProgramArguments</key>',
|
|
304
|
+
' <array>',
|
|
305
|
+
...args.map((a) => ` <string>${xmlEscape(a)}</string>`),
|
|
306
|
+
' </array>',
|
|
307
|
+
' <key>StartCalendarInterval</key>',
|
|
308
|
+
` <dict><key>Hour</key><integer>${options.hour}</integer><key>Minute</key><integer>0</integer></dict>`,
|
|
309
|
+
` <key>StandardOutPath</key><string>${xmlEscape(logPath)}</string>`,
|
|
310
|
+
` <key>StandardErrorPath</key><string>${xmlEscape(logPath)}</string>`,
|
|
311
|
+
' <key>EnvironmentVariables</key>',
|
|
312
|
+
// launchd inherits no shell PATH; include the dir of the node that ran
|
|
313
|
+
// `schedule` so a version-manager node resolves for the CLI and tests.
|
|
314
|
+
` <dict><key>PATH</key><string>${xmlEscape(`${path.dirname(process.execPath)}:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin`)}</string></dict>`,
|
|
315
|
+
'</dict>',
|
|
316
|
+
'</plist>',
|
|
317
|
+
'',
|
|
318
|
+
].join('\n');
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* launchd runs the plist with its own PATH, so a bare `claude` that resolves in
|
|
322
|
+
* the user's shell would fail silently at 02:00 into the log. Resolve it now,
|
|
323
|
+
* against this process's PATH, and embed the absolute path.
|
|
324
|
+
*/
|
|
325
|
+
export function resolveClaudePath(claudePath, envPath = process.env.PATH) {
|
|
326
|
+
const hint = 'pass --claude-path "$(command -v claude)"';
|
|
327
|
+
if (path.isAbsolute(claudePath)) {
|
|
328
|
+
if (!fs.existsSync(claudePath))
|
|
329
|
+
throw new Error(`--claude-path ${claudePath} does not exist; ${hint}`);
|
|
330
|
+
return claudePath;
|
|
331
|
+
}
|
|
332
|
+
for (const dir of (envPath ?? '').split(path.delimiter)) {
|
|
333
|
+
if (!dir)
|
|
334
|
+
continue;
|
|
335
|
+
const candidate = path.join(dir, claudePath);
|
|
336
|
+
if (fs.existsSync(candidate))
|
|
337
|
+
return candidate;
|
|
338
|
+
}
|
|
339
|
+
throw new Error(`Could not find "${claudePath}" on PATH; ${hint}`);
|
|
340
|
+
}
|
|
341
|
+
export function runOvernightSchedule(options) {
|
|
342
|
+
if (!Number.isInteger(options.hour) || options.hour < 0 || options.hour > 23) {
|
|
343
|
+
throw new Error(`--hour must be an integer 0-23, got ${options.hour}`);
|
|
344
|
+
}
|
|
345
|
+
const claudePath = resolveClaudePath(options.claudePath);
|
|
346
|
+
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', `${LAUNCHD_LABEL}.plist`);
|
|
347
|
+
const logPath = path.join(getReportsDir(), 'overnight-launchd.log');
|
|
348
|
+
const plist = renderLaunchdPlist({ hour: options.hour, claudePath }, logPath);
|
|
349
|
+
if (options.install) {
|
|
350
|
+
fs.mkdirSync(path.dirname(plistPath), { recursive: true });
|
|
351
|
+
fs.writeFileSync(plistPath, plist, { mode: 0o644 });
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
plist,
|
|
355
|
+
plistPath,
|
|
356
|
+
installed: options.install,
|
|
357
|
+
loadCommand: `launchctl bootout gui/$(id -u) ${plistPath} 2>/dev/null; launchctl bootstrap gui/$(id -u) ${plistPath}`,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
@@ -293,8 +293,10 @@ export function pruneIssueList(content, minScore = 6) {
|
|
|
293
293
|
skipSubBullets = true;
|
|
294
294
|
continue;
|
|
295
295
|
}
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
// Prune looks at issue AND PR entries: a curator's PR line with a MERGED
|
|
297
|
+
// sub-bullet must still be removable even though extractGitHubUrl (Guard 1)
|
|
298
|
+
// refuses PR URLs as issue candidates (#1637).
|
|
299
|
+
if (/https:\/\/github\.com\/[^/]+\/[^/]+\/(?:issues|pull)\/\d+/.test(line)) {
|
|
298
300
|
// Look ahead at sub-bullets for terminal status or low score
|
|
299
301
|
let shouldRemove = false;
|
|
300
302
|
let j = i + 1;
|
|
@@ -198,15 +198,12 @@ export function buildScoutState(diagnostics) {
|
|
|
198
198
|
})),
|
|
199
199
|
skippedIssues: skippedIssuesLoad.issues,
|
|
200
200
|
lastRunAt: state.lastRunAt,
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
// default (offset 0) is correct here, same as the ScoutPreferences
|
|
208
|
-
// defaults above.
|
|
209
|
-
searchRotation: { languageOffset: 0 },
|
|
201
|
+
// Broad-phase language rotation cursor (#1630). Scout advances it in its
|
|
202
|
+
// own state after a search whose broad phase ran; under
|
|
203
|
+
// persistence:'provided' that write is discarded with the process, so
|
|
204
|
+
// search.ts copies it back into AgentState and it is fed in from there.
|
|
205
|
+
// Scout's documented default (offset 0) applies until the first search.
|
|
206
|
+
searchRotation: state.searchRotation ?? { languageOffset: 0 },
|
|
210
207
|
};
|
|
211
208
|
}
|
|
212
209
|
/**
|
package/dist/commands/search.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { adaptScoutLinkedPR, buildCandidateLinkedPR, createAutopilotScout, SEARCH_DIVERSITY_RATIO, } from './scout-bridge.js';
|
|
6
6
|
import { SearchStrategySchema } from '@oss-scout/core';
|
|
7
|
-
import { classifyLinkedPR, getStateManager } from '../core/index.js';
|
|
7
|
+
import { classifyLinkedPR, getStateManager, maybeCheckpoint } from '../core/index.js';
|
|
8
8
|
import { gradeFromCandidate } from '../core/issue-grading.js';
|
|
9
9
|
import { computeStrategy } from '../core/strategy.js';
|
|
10
10
|
import { refreshStarredReposIfStale } from '../core/starred-repos.js';
|
|
@@ -188,6 +188,14 @@ export async function runSearch(options) {
|
|
|
188
188
|
// the next search rotates past it (#1528). Done before the own-PR filter so
|
|
189
189
|
// hidden-but-surfaced issues also rotate out. Persists to AgentState.
|
|
190
190
|
recordSearchSeen(stateManager, result.candidates.map((c) => c.issue.url));
|
|
191
|
+
// Scout advanced its broad-phase language cursor in its own (provided,
|
|
192
|
+
// non-persisted) state; copy it back so the next run starts from the next
|
|
193
|
+
// language slice instead of offset 0 every time (#1630).
|
|
194
|
+
stateManager.setSearchRotation(scout.getState().searchRotation);
|
|
195
|
+
// In Gist mode setSearchSeen only writes the local cache; without a
|
|
196
|
+
// checkpoint the seen-set never reaches the Gist and the next startup's
|
|
197
|
+
// Gist refetch overwrites the cache with the empty remote copy (#1629).
|
|
198
|
+
const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE);
|
|
191
199
|
// #1354: never surface issues the user already has an open PR for. Uses
|
|
192
200
|
// scout's structured linked-PR metadata when present; candidates without it
|
|
193
201
|
// pass through (the issue-scout agent re-checks via verify-issue anyway).
|
|
@@ -273,6 +281,9 @@ export async function runSearch(options) {
|
|
|
273
281
|
aiPolicyBlocklist: result.aiPolicyBlocklist,
|
|
274
282
|
hiddenOwnPRCount,
|
|
275
283
|
};
|
|
284
|
+
if (gistSyncWarning) {
|
|
285
|
+
searchOutput.gistSyncWarning = gistSyncWarning;
|
|
286
|
+
}
|
|
276
287
|
if (result.rateLimitWarning) {
|
|
277
288
|
searchOutput.rateLimitWarning = result.rateLimitWarning;
|
|
278
289
|
}
|
package/dist/commands/startup.js
CHANGED
|
@@ -17,6 +17,7 @@ import { launchDashboardServer } from './dashboard-lifecycle.js';
|
|
|
17
17
|
import { recordBrowserOpened } from './dashboard-process.js';
|
|
18
18
|
import { parseIssueList } from './parse-list.js';
|
|
19
19
|
import { detectIssueListPath, persistConfigPath } from './locate-issue-list.js';
|
|
20
|
+
import { overnightFreshness } from './overnight.js';
|
|
20
21
|
// Path detection moved to locate-issue-list.ts (#1463) so the daily
|
|
21
22
|
// merge-loop can use it without an import cycle through this module.
|
|
22
23
|
// Re-exported here for back-compat with existing consumers/tests.
|
|
@@ -350,5 +351,8 @@ export async function runStartup() {
|
|
|
350
351
|
dashboardBuildStatus,
|
|
351
352
|
dashboardBuildErrorTail,
|
|
352
353
|
issueList,
|
|
354
|
+
// State is already loaded and schema-parsed by this point (getStateManager
|
|
355
|
+
// above), so this is an in-memory read that cannot fail (#1574).
|
|
356
|
+
overnight: overnightFreshness(),
|
|
353
357
|
};
|
|
354
358
|
}
|
|
@@ -229,19 +229,19 @@ export const CONFIG_KEY_REGISTRY = [
|
|
|
229
229
|
},
|
|
230
230
|
{
|
|
231
231
|
key: 'autoFormatBeforePush',
|
|
232
|
-
description: '
|
|
232
|
+
description: 'No effect. The hook that used this setting was removed in #1642; the key is kept in the schema for state-file compatibility.',
|
|
233
233
|
settableVia: 'setup',
|
|
234
234
|
valueHint: 'true|false',
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
237
|
key: 'trustOwnRepoWrites',
|
|
238
|
-
description: '
|
|
238
|
+
description: 'No effect. The hook that used this setting was removed in #1642; the key is kept in the schema for state-file compatibility.',
|
|
239
239
|
settableVia: 'setup',
|
|
240
240
|
valueHint: 'true|false',
|
|
241
241
|
},
|
|
242
242
|
{
|
|
243
243
|
key: 'healthCheckFreshnessMinutes',
|
|
244
|
-
description: '
|
|
244
|
+
description: 'No effect. The hook that used this setting was removed in #1642; the key is kept in the schema for state-file compatibility.',
|
|
245
245
|
settableVia: 'setup',
|
|
246
246
|
valueHint: 'positive integer',
|
|
247
247
|
},
|
package/dist/core/paths.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export declare function getBackupDir(): string;
|
|
|
51
51
|
* ETag-based response caches for GitHub API endpoints.
|
|
52
52
|
*/
|
|
53
53
|
export declare function getCacheDir(): string;
|
|
54
|
+
/** Returns `~/.oss-autopilot/reports`, creating it (overnight morning reports, #1574). */
|
|
55
|
+
export declare function getReportsDir(): string;
|
|
54
56
|
/**
|
|
55
57
|
* Returns the path to the local Gist ID file (`~/.oss-autopilot/gist-id`).
|
|
56
58
|
*
|
package/dist/core/paths.js
CHANGED
|
@@ -78,6 +78,14 @@ export function getCacheDir() {
|
|
|
78
78
|
}
|
|
79
79
|
return dir;
|
|
80
80
|
}
|
|
81
|
+
/** Returns `~/.oss-autopilot/reports`, creating it (overnight morning reports, #1574). */
|
|
82
|
+
export function getReportsDir() {
|
|
83
|
+
const dir = path.join(getDataDir(), 'reports');
|
|
84
|
+
if (!fs.existsSync(dir)) {
|
|
85
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
86
|
+
}
|
|
87
|
+
return dir;
|
|
88
|
+
}
|
|
81
89
|
/**
|
|
82
90
|
* Returns the path to the local Gist ID file (`~/.oss-autopilot/gist-id`).
|
|
83
91
|
*
|