train S4: merge #3868 at 1ff314616d v1.93.6.0

This commit is contained in:
garrytan committed 2000-01-01 00:00:00 +00:00
commit 841447066e
73 files changed
+410 -124

No files matched your search

+2 -2
View File
@@ -50,9 +50,9 @@ If `SKILL_PREFIX` is `true` use `/gstack-*` names; paths stay `$GSTACK_ROOT/[ski
## Question Tuning (skip entirely if `QUESTION_TUNING: false`)
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `$GSTACK_ROOT/scripts/question-registry.ts` or `{skill}-{slug}`, then run `$GSTACK_BIN/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check). `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `$GSTACK_ROOT/scripts/question-registry.ts` or `{skill}-{slug}`, then run `$GSTACK_BIN/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check); its `--signal-keys` prints an optional signal-key hint. `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker, the PreToolUse hook treats AskUserQuestion as observed-only and never auto-decides.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker the hook never auto-decides.
**Embed the option recommendation via the `(recommended)` label suffix** on exactly one option per AUQ. The PreToolUse hook parses it first, falls back to "Recommendation: X" prose, and refuses when ambiguous (two labels = refuse).
+2 -2
View File
@@ -57,9 +57,9 @@ If `SKILL_PREFIX` is `true` use `/gstack-*` names; paths stay `~/.claude/skills/
## Question Tuning (skip entirely if `QUESTION_TUNING: false`)
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `~/.claude/skills/gstack/scripts/question-registry.ts` or `{skill}-{slug}`, then run `~/.claude/skills/gstack/bin/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check). `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `~/.claude/skills/gstack/scripts/question-registry.ts` or `{skill}-{slug}`, then run `~/.claude/skills/gstack/bin/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check); its `--signal-keys` prints an optional signal-key hint. `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker, the PreToolUse hook treats AskUserQuestion as observed-only and never auto-decides.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker the hook never auto-decides.
**Embed the option recommendation via the `(recommended)` label suffix** on exactly one option per AUQ. The PreToolUse hook parses it first, falls back to "Recommendation: X" prose, and refuses when ambiguous (two labels = refuse).
+2 -2
View File
@@ -48,9 +48,9 @@ If `SKILL_PREFIX` is `true` use `/gstack-*` names; paths stay `$GSTACK_ROOT/[ski
## Question Tuning (skip entirely if `QUESTION_TUNING: false`)
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `$GSTACK_ROOT/scripts/question-registry.ts` or `{skill}-{slug}`, then run `$GSTACK_BIN/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check). `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `$GSTACK_ROOT/scripts/question-registry.ts` or `{skill}-{slug}`, then run `$GSTACK_BIN/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check); its `--signal-keys` prints an optional signal-key hint. `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker, the PreToolUse hook treats AskUserQuestion as observed-only and never auto-decides.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker the hook never auto-decides.
**Embed the option recommendation via the `(recommended)` label suffix** on exactly one option per AUQ. The PreToolUse hook parses it first, falls back to "Recommendation: X" prose, and refuses when ambiguous (two labels = refuse).
+2 -2
View File
@@ -50,9 +50,9 @@ If `SKILL_PREFIX` is `true` use `/gstack-*` names; paths stay `$GSTACK_ROOT/[ski
## Question Tuning (skip entirely if `QUESTION_TUNING: false`)
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `$GSTACK_ROOT/scripts/question-registry.ts` or `{skill}-{slug}`, then run `$GSTACK_BIN/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check). `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
Before each decision brief (AskUserQuestion or Conductor/fallback prose), choose `question_id` from `$GSTACK_ROOT/scripts/question-registry.ts` or `{skill}-{slug}`, then run `$GSTACK_BIN/gstack-question-preference --check "<id>"`; for an unregistered id, write the question summary to `.gstack/tmp/qt.txt` (file-write tool) and append `--summary-file .gstack/tmp/qt.txt` (one-way keyword check); its `--signal-keys` prints an optional signal-key hint. `AUTO_DECIDE` means choose the recommended option and say "Auto-decided [summary] → [option] (your preference). Change with /plan-tune." `ASK_NORMALLY` means ask.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker, the PreToolUse hook treats AskUserQuestion as observed-only and never auto-decides.
**Embed the question_id as a marker in every asked brief**, ad hoc IDs included, with one ID for check, marker and log. Include `<gstack-qid:{question_id}>` once in the question text itself, not only a command or log. On prose paths, use the explicit reply line. Without the marker the hook never auto-decides.
**Embed the option recommendation via the `(recommended)` label suffix** on exactly one option per AUQ. The PreToolUse hook parses it first, falls back to "Recommendation: X" prose, and refuses when ambiguous (two labels = refuse).
+12
View File
@@ -109,6 +109,18 @@ describe('marker-first import (source=codex-import-marker)', () => {
expect(events[0].user_choice).toContain('Fix now');
expect(events[0].recommended).toContain('Fix now');
});
test('carries a marker signal hint into the log (#3442)', () => {
const sessionPath = writeSessionFile([
agentMessage('D1 — Caching\n<gstack-qid:plan-ceo-review-add-caching;signal=scope-appetite> Add caching?\nA) Expand with caching (recommended)\nB) Hold scope'),
userMessage('A'),
]);
expect(runImport(sessionPath).status).toBe(0);
const events = readImportedEvents();
expect(events[0].question_id).toBe('plan-ceo-review-add-caching');
expect(events[0].signal_key).toBe('scope-appetite');
expect(events[0].user_choice).toBe('expand');
});
});
// ----------------------------------------------------------------------
+37
View File
@@ -331,6 +331,43 @@ describe('gstack-developer-profile --derive', () => {
expect(p.inferred.signal_events).toBe(2);
});
test('a signal hint on an unregistered id moves its dimension (#3442)', () => {
logQuestion({ skill: 'plan-ceo-review', question_id: 'plan-ceo-review-add-caching', question_summary: 'caching?', user_choice: 'expand', signal_key: 'scope-appetite', session_id: 's1' });
runDev('--derive');
const p = readProfile() as any;
expect(p.inferred.contributing_events.scope_appetite).toBe(1);
expect(p.inferred.hinted_events).toBe(1);
expect(p.inferred.values.scope_appetite).toBeGreaterThan(0.5);
expect(runDev('--trace', 'scope_appetite').stdout).toContain('(hinted)');
});
test('the same unregistered answer without a hint moves nothing (#3442)', () => {
logQuestion({ skill: 'plan-ceo-review', question_id: 'plan-ceo-review-add-caching', question_summary: 'caching?', user_choice: 'expand', session_id: 's1' });
runDev('--derive');
const p = readProfile() as any;
expect(p.inferred.contributing_events.scope_appetite).toBe(0);
expect(p.inferred.hinted_events).toBe(0);
});
test('an unknown hint, a choice outside the signal and a registered id ignore the hint (#3442)', () => {
logQuestion({ skill: 'plan-ceo-review', question_id: 'plan-ceo-review-a', question_summary: 'a?', user_choice: 'expand', signal_key: 'made-up', session_id: 's1' });
logQuestion({ skill: 'plan-ceo-review', question_id: 'plan-ceo-review-b', question_summary: 'b?', user_choice: 'maybe', signal_key: 'scope-appetite', session_id: 's2' });
logQuestion({ skill: 'plan-eng-review', question_id: 'plan-eng-review-arch-finding', question_summary: 'arch?', user_choice: 'fix-now', signal_key: 'scope-appetite', session_id: 's3' });
runDev('--derive');
const p = readProfile() as any;
expect(p.inferred.contributing_events.scope_appetite).toBe(0);
expect(p.inferred.contributing_events.architecture_care).toBe(1);
expect(p.inferred.hinted_events).toBe(0);
});
test('hinted rows share the per-day cap (#3442)', () => {
for (let i = 0; i < 5; i++) {
logQuestion({ skill: 'plan-ceo-review', question_id: `plan-ceo-review-q${i}`, question_summary: 'q?', user_choice: 'expand', signal_key: 'scope-appetite', session_id: `s${i}`, ts: '2026-10-31T12:00:00Z' });
}
runDev('--derive');
expect(runDev('--trace', 'scope_appetite').stdout).toContain('capped to +0.060');
});
test('contributing_events is all zero when no answer matches a signal', () => {
logQuestion({ skill: 'plan-eng-review', question_id: 'plan-eng-review-arch-finding', question_summary: 'arch?', user_choice: 'not-a-mapped-option', session_id: 's1' });
runDev('--derive');
+29
View File
@@ -294,3 +294,32 @@ describe('gstack-question-log — shared injection patterns (#1934 dedup)', () =
expect(source).not.toContain('const INJECTION_PATTERNS');
});
});
describe('gstack-question-log — signal hints (#3442)', () => {
const base = { skill: 'plan-ceo-review', question_summary: 'caching?', session_id: 's1' };
test('a valid hint is kept and a key-word label maps to the option key', () => {
const r = run(JSON.stringify({ ...base, question_id: 'plan-ceo-review-add-caching', signal_key: 'Scope-Appetite', user_choice: 'B) Expand it (recommended)', source: 'hook' }));
expect(r.status).toBe(0);
const row = JSON.parse(readLog().at(-1)!);
expect(row.signal_key).toBe('scope-appetite');
expect(row.user_choice).toBe('expand');
expect(row.choice_label).toBe('B) Expand it (recommended)');
});
test('an unknown hint is dropped with a stable code and the row is still logged', () => {
const r = run(JSON.stringify({ ...base, question_id: 'plan-ceo-review-add-caching', signal_key: 'made-up', user_choice: 'expand' }));
expect(r.status).toBe(0);
expect(r.stderr).toContain('QLOG_SIGNAL_KEY_DROPPED');
const row = JSON.parse(readLog().at(-1)!);
expect(row.signal_key).toBeUndefined();
expect(row.user_choice).toBe('expand');
});
test('a hint on a registered id is dropped', () => {
const r = run(JSON.stringify({ ...base, skill: 'plan-eng-review', question_id: 'plan-eng-review-arch-finding', signal_key: 'scope-appetite', user_choice: 'fix-now' }));
expect(r.status).toBe(0);
expect(r.stderr).toContain('a registered id keeps its own signal');
expect(JSON.parse(readLog().at(-1)!).signal_key).toBeUndefined();
});
});
+2 -2
View File
@@ -68,7 +68,7 @@ export const engSetupAUQ: Step0BoundaryPredicate = (fp) => {
return answered.length > 0 && answered.every(q => {
if (!q.options.some(option => option.label === call.answers?.[q.question])) return false;
const actions = q.options.map(option => option.label.trim().replace(/^[A-Z][.)]\s+/i, ''));
const id = /<gstack-qid:\s*([a-z0-9-]+)\s*>/i.exec(q.question)?.[1]?.toLowerCase();
const id = /<gstack-qid:\s*([a-z0-9-]+)(?:;signal=[a-z0-9-]+)?\s*>/i.exec(q.question)?.[1]?.toLowerCase();
const body = q.question.replace(/<gstack-qid:[^>]*>/gi, '').trim()
.replace(/^D\s*\d+\s*[—–:-]\s*/i, '');
// A finding about one component or a TODO remains substantive even if
@@ -592,7 +592,7 @@ export const engFirstReviewAUQ: Step0BoundaryPredicate = (fp) => {
if (!call.answers?.[q.question]) return false;
// These are review section identities, including the registry's
// arch-finding/test-gap IDs. Scope and onboarding IDs cannot qualify.
const id = /<gstack-qid:\s*([a-z0-9-]+)\s*>/i.exec(q.question)?.[1] ?? '';
const id = /<gstack-qid:\s*([a-z0-9-]+)(?:;signal=[a-z0-9-]+)?\s*>/i.exec(q.question)?.[1] ?? '';
if (/^plan-eng-(?:review-)?(?:arch(?:itecture)?|quality|test|perf(?:ormance)?)-(?:focus|mode|setup|routing|learnings|prerequisite|onboarding|next-steps?)(?:-|$)/i.test(id)) return false;
const title = `${q.header} ${q.question.split('\n')[0]}`.replace(/<gstack-qid:[^>]*>/gi, '');
return /^plan-eng-(?:review-)?(?:arch(?:itecture)?|quality|test|perf(?:ormance)?)-/i.test(id) &&
+1
View File
@@ -62,6 +62,7 @@ function scaffoldFixture(workDir: string): { workDir: string; stateRoot: string;
'archetypes.ts',
'one-way-doors.ts',
'declared-annotation.ts',
'qid-marker.ts',
]) {
const src = path.join(ROOT, 'scripts', f);
if (fs.existsSync(src)) fs.copyFileSync(src, path.join(scriptsDir, f));
+49
View File
@@ -0,0 +1,49 @@
import { describe, expect, test } from 'bun:test';
import { parseQidMarker } from '../scripts/qid-marker';
import { resolveHintedOptionKey, signalKeyLines } from '../scripts/psychographic-signals';
describe('parseQidMarker (#3442)', () => {
test('reads a plain marker and strips it', () => {
expect(parseQidMarker('D1 — Ship? <gstack-qid:ship-test-failure-triage>')).toEqual({ id: 'ship-test-failure-triage', stripped: 'D1 — Ship?' });
});
test('reads a signal hint and strips the whole marker', () => {
expect(parseQidMarker('Add caching? <gstack-qid:plan-ceo-review-add-caching;signal=scope-appetite>')).toEqual({
id: 'plan-ceo-review-add-caching',
signal_key: 'scope-appetite',
stripped: 'Add caching?',
});
});
test('lowercases an uppercase marker', () => {
expect(parseQidMarker('<gstack-qid:Plan-CEO-X;signal=Scope-Appetite> q')).toMatchObject({ id: 'plan-ceo-x', signal_key: 'scope-appetite' });
});
test('no marker returns undefined', () => {
expect(parseQidMarker('plain question')).toBeUndefined();
});
});
describe('resolveHintedOptionKey (#3442)', () => {
test('an exact option key passes through', () => {
expect(resolveHintedOptionKey('scope-appetite', 'expand')).toBe('expand');
});
test('a label that starts with the key words maps to the key', () => {
expect(resolveHintedOptionKey('scope-appetite', 'B) Reduce scope (recommended)')).toBe('reduce');
expect(resolveHintedOptionKey('architecture-care', 'Accept risk and move on')).toBe('accept-risk');
});
test('a cue-table word never maps, so a yes cannot invert a signal', () => {
expect(resolveHintedOptionKey('scope-appetite', 'Yes, cut it')).toBeUndefined();
expect(resolveHintedOptionKey('architecture-care', 'Fix it later')).toBeUndefined();
});
test('an unknown signal key maps nothing', () => {
expect(resolveHintedOptionKey('made-up', 'expand')).toBeUndefined();
});
test('signalKeyLines lists every signal with its option keys', () => {
expect(signalKeyLines()).toContain('architecture-care: fix-now | defer | accept-risk');
});
});
+24
View File
@@ -137,6 +137,30 @@ describe('PostToolUse hook (native AskUserQuestion)', () => {
// Marker stripped from summary
expect((events[0].question_summary as string).includes('<gstack-qid:')).toBe(false);
});
test('a signal hint in the marker reaches the log row (#3442)', () => {
runHook({
session_id: 'sess-hint',
tool_name: 'AskUserQuestion',
tool_use_id: 'tu-hint',
tool_input: {
questions: [
{
question: 'D3 — Add caching? <gstack-qid:plan-ceo-review-add-caching;signal=scope-appetite>',
options: ['A) Expand to add caching (recommended)', 'B) Hold scope'],
},
],
},
tool_response: { answers: [{ option_label: 'A) Expand to add caching (recommended)' }] },
cwd: ROOT,
});
const events = readLog();
expect(events.length).toBe(1);
expect(events[0].question_id).toBe('plan-ceo-review-add-caching');
expect(events[0].signal_key).toBe('scope-appetite');
expect(events[0].user_choice).toBe('expand');
expect((events[0].question_summary as string).includes('gstack-qid')).toBe(false);
});
});
// ----------------------------------------------------------------------