Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/gstack-ship-budget
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* reserve fit under the cap.
*
* start --record <path> [--token-cap <n|none>] [--meter capy|claude|estimate] [--reading <n>] [--prior-reading <n>]
* [--session <id>|--nonce <v>] [--reserve <n>] [--delegate auto|never] [--calibration <file>] [--ledger <path>]
* [--session <id>|--nonce <v>] [--reserve <n>] [--delegate auto|never|measured] [--calibration <file>] [--ledger <path>]
* check --run <id>|--record <path> --step <id> --next <id|dispatch:<role>[,<role>...]> [--reading <n>] [--prior-reading <n>] [--returned <id>[,<id>...]] [--runtime-lines <n>]
* settle --run|--record --reservation <id> [--unknown] [--reading <n>] release --run|--record --reservation <id>
* handoff --run|--record --from <step> --to <step> --base origin/<base> [--reviewed-tree <t>] [--trail <f> --trail-run <id>]
Expand Down
2 changes: 2 additions & 0 deletions capy/skill/gstack/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ If no specific skill was requested, use the router's task-to-skill mapping. Read

For `/autoplan` driven from Capy, read `autoplan/DRIVER.md` in the checkout (`~/.local/share/gstack/autoplan/DRIVER.md`): the compact phase loop, artifact contract and gate protocol, without the interactive preamble. A checkout without that file predates it; follow its `autoplan/SKILL.md` instead. Run every command with the `GSTACK_LAUNCH` assignments and read outputs as files, not prose: the run directory holds `run.json`, `decisions.jsonl`, `findings.jsonl`, `tasks.jsonl`, `timing.json`, `plan.md` and `review-record.md`, and the run ends with `GSTACK_RESULT: skill=autoplan status=gate_pending run=<dir>`. `~/.local/share/gstack/bin/gstack-artifact validate <dir>/run.json` is the completion check. The gate is answered through `gstack-autoplan answer` (or `gstack-gate parse`) with the printed `gate_rev`; an unattended run never approves its own gate. `docs/unattended.md` in the checkout is the contract.

For `/ship` driven from Capy, read `ship/DRIVER.md` in the checkout (`~/.local/share/gstack/ship/DRIVER.md`): the phase loop at one or two calls per phase, and the section each STOP needs. A checkout without that file predates it; follow its `ship/SKILL.md` instead. It starts the budget with `--delegate measured`.

Run directories and scratch on Capy live under `~/.capy/work/<name>` (`--out ~/.capy/work/<project>/autoplan`), never `/tmp`: Capy wipes `/tmp` when a machine sleeps, and a vanished run cannot be resumed, answered or exported. The same holds for any file a later turn reads.

Capy checklist for `/autoplan`: drive `gstack-autoplan`, never a hand adaptation presented as a run. Relay `gstack-gate render <dir>/gate.json --all` with `rec` (every recommendation, plan changes included) as the one-word default; answer with `--by agent:<id> --owner-reply "<their words>"`. Set `GSTACK_AUTOPLAN_CHECKPOINT_DIR` to a private project-user Drive folder; after machine replacement, `gstack-autoplan resume --out <new dir> --from <that dir>` restores the newest valid checkpoint.
Expand Down
5 changes: 4 additions & 1 deletion docs/ship-budget.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ line prints `call`, `call_floor` and `above_floor`, so each verdict can be check
grandchild's.

`--delegate never` turns delegate into stop for a parent on a host without children; a child
continues with a `CONTEXT_HIGH:` note instead.
continues with a `CONTEXT_HIGH:` note instead. `--delegate measured` (what `ship/DRIVER.md` starts
with) delegates only when a measured call is 150k or more above the floor at a segment boundary; an
unknown charge continues there. A parent driving /ship from the driver carries no skill text a fresh
child would shed, so a child pays its fixed cost only when the parent's own context grew.

**Small runs keep their segment.** `check --runtime-lines <n>` (runtime_lines from
`gstack-review-plan --json`, which `gstack-ship-preflight` prints) continues at the Step 7 and
Expand Down
6 changes: 3 additions & 3 deletions lib/ship-budget-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function writeReturnFile(file: string, lines: string[]): void {
/**
* Admission and the delegate rule for one boundary; reserves the admitted work
* under a cap (a dispatch batch goes to admitBatch). The rule compares the call's context above the host floor (an
* unknown charge delegates at a segment boundary, never at start). A light diff
* unknown charge delegates at a segment boundary, never at start; under --delegate measured it continues). A light diff
* whose segment costs less than a child keeps it (keepsSmallRun). A child
* never stops on it: after a completed step it hands its remaining steps to a
* grandchild, and before one, at the maximum depth or past its segment it
Expand All @@ -148,7 +148,7 @@ export function decide(l: Ledger, step: string, next: Next, call: number | null,
const boundary = (startThreshold ? next.step === '1' : next.step === '7' || next.step === '12');
const to = l.parent ? l.parent.to : SEGMENTS[next.step]!;
const small = boundary && !startThreshold ? keepsSmallRun(loadCalibration(l.calibration), { runtimeLines, from: next.step, to, call }) : null;
const wants = boundary && !small && (above === null ? !startThreshold : above >= threshold);
const wants = boundary && !small && (above === null ? !startThreshold && l.delegate !== 'measured' : above >= threshold);
const depth = l.depth ?? (l.parent ? 1 : 0);
const hold = !wants || !l.parent ? undefined
: !l.steps_done?.length ? 'no step completed since verify-handoff'
Expand Down Expand Up @@ -234,7 +234,7 @@ export function cmdStart(argv: string[], ctx: Ctx): Outcome {
const cap = rawCap === undefined || rawCap === 'none' ? null : parseTokens(rawCap, '--token-cap');
const callFloor = tokensOpt(o, 'call-floor');
const delegate = str(o, 'delegate') ?? 'auto';
if (delegate !== 'auto' && delegate !== 'never') throw usageError(`--delegate '${delegate}' is not auto or never`);
if (delegate !== 'auto' && delegate !== 'never' && delegate !== 'measured') throw usageError(`--delegate '${delegate}' is not auto, never or measured`);
const existing = parseRecordBlock(record);
if (existing?.ledger && fs.existsSync(existing.ledger) && !readLedger(existing.ledger).closed_at) {
const l = readLedger(existing.ledger);
Expand Down
2 changes: 1 addition & 1 deletion lib/ship-budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface Handoff {
}
export interface Ledger {
schema_version: 1; kind: 'gstack-ship-budget'; run: string; dir: string; file: string; record?: string; created_at: string;
cap: number | null; tail: number; stop_overhead: number; delegate: 'auto' | 'never'; role: 'parent' | 'child';
cap: number | null; tail: number; stop_overhead: number; delegate: 'auto' | 'never' | 'measured'; role: 'parent' | 'child';
parent?: { run: string; ledger: string; handoff_sha: string; from: string; to: string; return_file: string };
meter: { contract: MeterContract; epoch: number; baseline: number; last: number | null; last_at?: string; sessions?: string[]; config_dir?: string };
epochs: Array<{ epoch: number; contract: MeterContract; baseline: number; last: number | null; used: number }>;
Expand Down
12 changes: 12 additions & 0 deletions scripts/gen-skill-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,15 @@ export function renderAutoplanDriver(options: RenderOptions): string {
return GENERATED_HEADER.replace('{{SOURCE}}', `${AUTOPLAN_DRIVER_RELPATH}.tmpl`) + resolvePlaceholders(tmpl, ctx, getHostConfig('claude'), `${AUTOPLAN_DRIVER_RELPATH}.tmpl`, options);
}

/** ship/DRIVER.md (GSTA-167 PR 5): the compact /ship entry for a parent agent, rendered the same way. */
export const SHIP_DRIVER_RELPATH = 'ship/DRIVER.md';
export function renderShipDriver(options: RenderOptions): string {
const tmplPath = path.join(ROOT, `${SHIP_DRIVER_RELPATH}.tmpl`);
const tmpl = fs.readFileSync(tmplPath, 'utf-8');
const ctx = buildContext(tmpl, tmplPath, 'claude', options, 'ship');
return GENERATED_HEADER.replace('{{SOURCE}}', `${SHIP_DRIVER_RELPATH}.tmpl`) + resolvePlaceholders(tmpl, ctx, getHostConfig('claude'), `${SHIP_DRIVER_RELPATH}.tmpl`, options);
}

/**
* Generate one on-demand section file (`<skill>/sections/<name>.md.tmpl` →
* `<name>.md`). Sections are BODY FRAGMENTS — no frontmatter, no catalog trim,
Expand Down Expand Up @@ -1092,6 +1101,9 @@ export async function runGeneration(settings: GenerationOptions = {}): Promise<G
if (host === 'claude' && includesSkill(hostConfig, 'autoplan') && templates.some(t => t.tmpl === 'autoplan/SKILL.md.tmpl')) {
emit(path.join(options.outputRoot, AUTOPLAN_DRIVER_RELPATH), renderAutoplanDriver(options), 'asset', host);
}
if (host === 'claude' && includesSkill(hostConfig, 'ship') && templates.some(t => t.tmpl === 'ship/SKILL.md.tmpl')) {
emit(path.join(options.outputRoot, SHIP_DRIVER_RELPATH), renderShipDriver(options), 'asset', host);
}

if (host === 'openclaw') {
for (const variant of ['lite', 'full', 'plan'] as const) {
Expand Down
3 changes: 3 additions & 0 deletions scripts/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { generatePlanRealityRows } from './plan-reality';
import { generateSidewaysSweep, generateFlakeFixNumber } from './sideways';
import { generateCoordinatorContract } from './coordinator-contract';
import { generateAutoplanDriverCodes, generateAutoplanDriverCommands, generateAutoplanDriverFiles, generateAutoplanDriverGate, generateAutoplanDriverPhases, generateAutoplanDriverResultFormat } from './autoplan-driver';
import { generateShipDriverSegmentCall, generateShipDriverStops } from './ship-driver';
import { generateQAScope, generateQAExploratory, generateQAFunctional, generateQAResource, generateQAReview, generateQAReviewPreflight, generateQAMethodReads } from './qa';
import { generateVoiceTriggerRouting } from './voice-triggers';
import { generateTranscriptDiscovery, generateTranscriptSources } from './transcripts';
Expand Down Expand Up @@ -191,6 +192,8 @@ export const RESOLVERS: Record<string, ResolverFn> = {
AUTOPLAN_DRIVER_GATE: generateAutoplanDriverGate,
AUTOPLAN_DRIVER_FILES: generateAutoplanDriverFiles,
AUTOPLAN_DRIVER_CODES: generateAutoplanDriverCodes,
SHIP_DRIVER_STOPS: generateShipDriverStops,
SHIP_DRIVER_SEGMENT_CALL: generateShipDriverSegmentCall,
SECTION,
SECTION_INDEX,
TRANSCRIPT_SOURCES: generateTranscriptSources,
Expand Down
43 changes: 43 additions & 0 deletions scripts/resolvers/ship-driver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* ship/DRIVER.md resolvers (GSTA-167 PR 5): the compact entry a parent agent
* reads to run an unattended /ship, instead of ship/SKILL.md plus its sections.
* The phases live in ship/DRIVER.md.tmpl; this file owns the one list a reader
* must trust most: which heading each STOP sends the parent to. test/ship-driver.test.ts
* resolves every anchor against the generated files.
*/
import { DELEGATE_SEGMENT_CALL } from '../../lib/ship-budget';
import type { ResolverFn } from './types';

/** Each STOP (or read-when line) a driver run can meet, and the one heading it reads, relative to <root>/ship/. */
export const SHIP_DRIVER_STOPS: Array<{ when: string; read: string }> = [
{ when: '`merge conflicts`', read: 'SKILL.md#step-3-merge-the-base-branch-before-tests' },
{ when: '`NEXT: carry route`', read: 'SKILL.md#step-1-pre-flight' },
{ when: '`DISTRIBUTION: candidates=`', read: 'SKILL.md#step-2-distribution-pipeline-check' },
{ when: '`APPLE:` with a store ask', read: 'sections/apple-release.md#apple-app-store-release' },
{ when: '`pregate fail` or `incomplete`', read: 'sections/tests.md#step-5-run-tests-on-merged-code' },
{ when: 'a failed or zero-run lane', read: 'sections/tests.md#test-failure-ownership-triage' },
{ when: 'a red eval or a failed free-suite shard', read: 'sections/measure.md#measure-then-fix-loop-a-red-paid-eval-or-a-failed-free-suite-shard' },
{ when: 'Greptile found', read: 'sections/greptile-early.md#step-65-early-greptile-pr-after-the-free-tests-pass' },
{ when: 'coverage below target, a failed audit', read: 'sections/test-coverage.md#step-7-test-coverage-audit' },
{ when: 'plan items NOT DONE or UNVERIFIABLE', read: 'sections/plan-completion.md#gate-logic' },
{ when: '`REVIEW_COVERAGE_INCOMPLETE` or `NEXT: stop`', read: 'sections/review-army.md#decide-whether-to-repeat-step-9' },
{ when: 'a `REVIEW_SCOPE_*` refusal, the review-log row', read: 'sections/review-army.md#step-94-fix-first-and-persistence' },
{ when: 'a required probe not passed', read: 'sections/review-army.md#step-921-exploratory-qa-before-fix-first' },
{ when: 'native adversarial incomplete, queued fixes', read: 'sections/adversarial.md#finish-the-adversarial-phase' },
{ when: 'Step 11.5 mismatch', read: 'SKILL.md#step-115-bind-the-reviews' },
{ when: 'a `version` STOP', read: 'SKILL.md#step-12-version-bump-auto-decide' },
{ when: '`Documentation: blocked` or a `DOCS_CAP:` over', read: 'sections/documentation.md#blocked-recovery' },
{ when: 'finish: changed since review', read: 'SKILL.md#2-choose-the-change-route' },
{ when: 'finish: documentation inputs changed', read: 'SKILL.md#3-resolve-documentation-freshness' },
{ when: 'finish: build, lane or pregate STOP', read: 'SKILL.md#4-verify-the-frozen-candidate' },
{ when: 'a push STOP', read: 'SKILL.md#step-17-push' },
{ when: 'unattended, no open PR at HEAD', read: 'sections/handoff.md#step-18-h-handoff-without-a-pr-automation-lanes' },
{ when: 'a receipt write or `gstack-post` refusal', read: 'sections/pr-body.md#compose-the-body-then-publish-through-gstack-post' },
{ when: '`verdict=stop` or `DELEGATE:`', read: 'sections/budget-handoff.md#budget-and-context-handoff-read-when-a-cap-is-set-or-verdictdelegate-prints' },
{ when: '`QUEUE_RECEIPT_STALE`', read: '../docs/ship-policy.md#ship-before-ready' },
];

export const generateShipDriverSegmentCall: ResolverFn = () => `${DELEGATE_SEGMENT_CALL / 1000}k`;

export const generateShipDriverStops: ResolverFn = () =>
SHIP_DRIVER_STOPS.map(s => `- ${s.when}: \`${s.read}\``).join('\n');
Loading