A first version's public copy keeps out the owner's short quotes, and phone first-use checks install a build the phone can run (GST-3646) (#4772)

A first version's public export now keeps out the owner's short quotes
and his reasons to leave something out, and a phone first-use check
installs a build the cloud phone can actually run.

Why: a one- or two-word quote or a leave-out reason could reach the
public copy through the gate's choice titles, and the phone check named
a TestFlight build the cloud phone can't install.

Phone checks now need `--phone-build ` on `gstack-first-use start`;
phone runs started before this change must be started again.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p2/specialist-batched#1 reader=security
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-24 04:19:06 +00:00
1 parent 7c321fff5d
commit 84b4eab0a9
10 files changed
+139 -22

No files matched your search

+10 -4
View File
@@ -9,7 +9,9 @@
* answer at the same gate replaced), the words a carried gate reused, each
* quote in a `### Owner's words` section of any plan text the run kept (plan-active.md, plan-source*.md,
* plan-at-gate.r*.md, plan-file.*.md; lib/autoplan-owner-text.ts), so a quote a revision removed stays redacted,
* and a reason a human gave for `close --deferred <reason> --by human`. A reply that
* and a reason a human gave for `close --deferred <reason> --by human`. A plan quote of any length, and a
* quote's `leave out: <reason>`, are also redacted wherever gstack renders them: the quote between quote marks,
* the reason after `leave out:`, `leave it out for now:` or `reason to leave it out:` in any case (GST-3646). A reply that
* parsed as gate grammar (`owner_reply_parsed`) is the decision code and is
* not scanned for; `reply` and the agent's own `answer_words` stay.
*
@@ -159,7 +161,7 @@ const DEFERRAL_RENDERINGS = (r: string) => [`^deferred: (${r})$`, `\\((${r}); by
* The scan index: each owner reply and deferral reason of MIN_TOKENS+ words (grammar skipped), each run of MIN_TOKENS+
* of its words between echoed windows, and the placements of deferral reasons and carried words.
*/
export function ownerIndex(replies: OwnerSource[], o: { deferred?: OwnerSource[]; carried?: string[] } = {}): OwnerWords {
export function ownerIndex(replies: OwnerSource[], o: { deferred?: OwnerSource[]; carried?: string[]; quoted?: string[]; reasons?: string[] } = {}): OwnerWords {
const keysOf = (texts: string[]) => ` ${texts.flatMap(t => [tokens(t, false), tokens(t)].map(ts => ts.map(k => k.key).join(' '))).join(' \u0001 ')} `;
const seen = new Set<string>();
const indexed: Indexed[] = [];
@@ -188,7 +190,8 @@ export function ownerIndex(replies: OwnerSource[], o: { deferred?: OwnerSource[]
const placements = [
...(o.deferred ?? []).flatMap(d => DEFERRAL_RENDERINGS(escape(d.text))),
...(o.carried ?? []).map(w => `words=(${escape(JSON.stringify(w))})(?= by=|$)`),
].map(p => new RegExp(p, 'gd'));
...(o.quoted ?? []).map(q => `["“](${escape(q)})["”]`),
].map(p => new RegExp(p, 'gd')).concat((o.reasons ?? []).map(r => new RegExp(`(?:leave out|leave it out for now|reason to leave it out)\\s*:\\s*(${escape(r)})`, 'gdi')));
return { replies: indexed, placements };
}
@@ -279,7 +282,8 @@ export function ownerWords(state: Pick<RunState, 'out' | 'phases' | 'gate' | 'ca
note(state.carry?.words, undefined, false);
let names: string[] = [];
try { names = fs.readdirSync(out).filter(f => f === FILES.active || /^plan-source.*\.md$/.test(f) || /^plan-at-gate\.r\d+\.md$/.test(f) || /^plan-file\..+\.md$/.test(f)).sort(); } catch { /* no run directory */ }
for (const text of new Set(names.flatMap(f => parseOwnerWords(read(f) ?? '').quotes.map(q => q.text)))) note(text, undefined, false);
const planQuotes = names.flatMap(f => parseOwnerWords(read(f) ?? '').quotes);
for (const text of new Set(planQuotes.map(q => q.text))) note(text, undefined, false);
const deferred = new Map<string, string | undefined>();
for (const r of journal) if (r.event === 'phase_deferred' && r.by === 'human' && typeof r.reason === 'string') deferred.set(r.reason, deferred.get(r.reason) ?? String(r.ts));
@@ -288,5 +292,7 @@ export function ownerWords(state: Pick<RunState, 'out' | 'phases' | 'gate' | 'ca
return ownerIndex([...byText].map(([text, r]) => ({ text, parsed: r.parsed, prior: prior(r.at) })), {
deferred: [...deferred].map(([text, at]) => ({ text, prior: prior(at) })),
carried: state.carry?.words ? [state.carry.words] : [],
quoted: [...new Set(planQuotes.map(q => q.text))],
reasons: [...new Set(planQuotes.flatMap(q => (q.line?.kind === 'choice' && q.line.leave_out ? [q.line.leave_out] : [])))],
});
}
+1 -1
View File
@@ -138,7 +138,7 @@ const DRIVE: Record<Manifest['build']['platform'], (m: Manifest) => string> = {
};
function phone(m: Manifest): string {
const b = m.build;
return `attach a ${platformName[b.platform]} phone (\`tools.capy.phone\` with action "attach", platform "${b.platform}" and the model closest to the device above), install this exact build on it (action "install"; ${b.testflight ? `TestFlight build ${b.testflight}` : `version ${b.deploy}`}), point it at ${m.play.target.name}, and drive its screen with \`tools.capy.computer.on({ machine_id })\``;
return `attach a ${platformName[b.platform]} phone (\`tools.capy.phone\` with action "attach", platform "${b.platform}" and the model closest to the device above), install this exact build on it (action "install" with build_id "${m.phone_build}", the mobile build service's build of commit ${b.commit.slice(0, 12)}, which ${b.testflight ? `TestFlight build ${b.testflight}` : `version ${b.deploy}`} ships; if it won't install, record step 1 broken), point it at ${m.play.target.name}, and drive its screen with \`tools.capy.computer.on({ machine_id })\``;
}
/** What the cold checker is given: the exact try-it text, the target and its rules, and the commands that record each step. */
+6 -3
View File
@@ -49,7 +49,7 @@ export interface Holding { build: string; defects: string }
export interface Manifest {
schema_version: 2; kind: 'first-use-manifest'; app: string; created_at: string;
source: { path: string; rows_sha256: string }; quotes: FrozenQuote[]; actions: FrozenAction[]; steps: FrozenStep[];
try_text: string; try_sha256: string; build: BuildId & { fingerprint: string }; play: PlaySpec; holding: Holding;
try_text: string; try_sha256: string; build: BuildId & { fingerprint: string }; phone_build?: string; play: PlaySpec; holding: Holding;
builder: { model: string; family: string }; checker: { model: string; family: string };
}
export interface StepResult {
@@ -162,7 +162,7 @@ function checkHolding(h: Partial<Holding> | undefined): Result<{ holding: Holdin
return { holding: { build, defects } };
}
export interface StartInput { root: string; app: string; planPath: string; build: Partial<BuildId>; play: unknown; holding: Partial<Holding>; builder: string; checker: string; now?: Date }
export interface StartInput { root: string; app: string; planPath: string; build: Partial<BuildId>; phoneBuild?: string; play: unknown; holding: Partial<Holding>; builder: string; checker: string; now?: Date }
/** Freezes the owner's quotes, the steps and the try-it text, and writes the run's manifest once; returns the run directory. */
export function startRun(o: StartInput): Result<{ dir: string; manifest: Manifest }> {
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(o.app)) return fail('FIRST_USE_RECORD_INVALID', '--app must be a lowercase slug like ghome');
@@ -174,6 +174,8 @@ export function startRun(o: StartInput): Result<{ dir: string; manifest: Manifes
if ('error' in play) return play;
const build = buildFingerprint(o.build);
if ('error' in build) return build;
const phone = build.platform === 'ios' || build.platform === 'android';
if (phone && !/^[0-9A-Za-z]{26}$/.test(o.phoneBuild ?? '')) return fail('FIRST_USE_RECORD_INVALID', `a ${build.platform} check installs on a cloud phone, which takes only a build from Capy's mobile build service: give --phone-build <its 26-character build id> for commit ${build.commit.slice(0, 12)}, not a TestFlight or store number`);
const holding = checkHolding(o.holding);
if ('error' in holding) return holding;
const builder = modelFamily(o.builder), checker = modelFamily(o.checker);
@@ -186,7 +188,7 @@ export function startRun(o: StartInput): Result<{ dir: string; manifest: Manifes
];
const base = { schema_version: 2 as const, kind: 'first-use-manifest' as const, app: o.app, created_at: now.toISOString(),
source: { path: path.resolve(o.planPath), rows_sha256: frozen.rows_sha256 }, quotes: frozen.quotes, actions: frozen.actions, steps,
build, play: play.spec, holding: holding.holding, builder: { model: o.builder, family: builder }, checker: { model: o.checker, family: checker } };
build, ...(phone ? { phone_build: o.phoneBuild } : {}), play: play.spec, holding: holding.holding, builder: { model: o.builder, family: builder }, checker: { model: o.checker, family: checker } };
const try_text = renderTryText(base);
const manifest: Manifest = { ...base, try_text, try_sha256: sha256(try_text) };
const dir = path.join(o.root, o.app, `${stamp(now)}-${build.fingerprint.slice(0, 8)}`);
@@ -198,6 +200,7 @@ export function readManifest(dir: string): Result<{ manifest: Manifest }> {
const m = readJson<Omit<Manifest, 'schema_version'> & { schema_version: number }>(path.join(dir, 'manifest.json'));
if (m?.kind === 'first-use-manifest' && m.schema_version === 1) return fail('FIRST_USE_RECORD_INVALID', `${dir} is a schema-1 run from before the try-it steps and the owner's quotes were checked; start a new run`);
if (!m || m.schema_version !== 2 || m.kind !== 'first-use-manifest' || !Array.isArray(m.steps) || !m.build?.fingerprint) return fail('FIRST_USE_RECORD_INVALID', `no readable manifest.json in ${dir}`);
if ((m.build.platform === 'ios' || m.build.platform === 'android') && !/^[0-9A-Za-z]{26}$/.test(m.phone_build ?? '')) return fail('FIRST_USE_RECORD_INVALID', `${dir} is a ${m.build.platform} run with no --phone-build, so its checker can't install the build on a cloud phone; start a new run with --phone-build`);
return { manifest: m as Manifest };
}