Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(questions): import every migrated dream.auto_think pin inactive (migrated_enabled when auto_think was on), keeping questions, budget and settings so one pin --id activates it; notice row, CHANGELOG and guide say so; scenario proves standing_questions refreshes nothing until activation

garrytan0bb58e7d28c5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6408bb09dd..c2369c622d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,7 @@ A fact you save with `remember` used to lose to the stale page text it corrected
- `remember` takes `valid_from`, so a correction can carry the date it became true instead of the day it was saved.
- Fact supersession uses a threshold measured for the brain's embedding model. The default voyage-4 at 1024 dimensions keeps 0.95 and decides as before. Any other model no longer replaces a similar fact by cosine: both stay active and conflict review judges the pair, and exact-text duplicates still merge. Doctor `supersession_calibration` names a command that measures a threshold on synthetic text (about a cent), and `facts.supersession_thresholds` registers one.
- Pinned questions: `gbrain questions pin|list|status|refresh|unpin` and MCP `questions_*`. Answers live in their own private tables with per-sentence evidence, never in search results, exports or git. A sentence whose evidence changed is flagged stale when you read it, and `context_pack` gains optional `pinned_questions` and `withheld` fields. A pin made over MCP stays inactive until the owner activates it. The dream cycle's `standing_questions` phase refreshes active pins under `cycle.standing_questions.budget_usd` (default $1.00 per run). Guide: `docs/guides/pinned-questions.md`.
-- Pinned questions replace `dream.auto_think`. On upgrade, its questions become pins with their budget, cooldown, model and commit setting, inactive when auto_think was off or its budget was 0. `gbrain config get|set dream.auto_think.*` names where each key went.
+- Pinned questions replace `dream.auto_think`. On upgrade, its questions become inactive pins with their budget, cooldown, model and commit setting, so nothing starts spending; `gbrain questions pin --id <id>` turns one on. `gbrain config get|set dream.auto_think.*` names where each key went.
- Opt-in retrieval settings, each off by default: `search.evidence_date_header` (each delivered evidence block starts with its observation date), `search.entity_anchoring` (a current-state question that names one entity puts that entity's page and the pages about it first), `search.temporal_fact_reserve` (a question about when things happened reserves part of the token budget for dated facts) and `facts.candidate_fusion interleave` (a keyword arm for supersession candidates).
- `GOOGLE_GENERATIVE_AI_BASE_URL` (or `provider_base_urls.google`) routes Gemini chat, expansion and embeddings through a proxy.
- Fixes:
diff --git a/docs/architecture/key-files/core-questions.md b/docs/architecture/key-files/core-questions.md
index e1d39c083f..0929e4a4d5 100644
--- a/docs/architecture/key-files/core-questions.md
+++ b/docs/architecture/key-files/core-questions.md
@@ -22,7 +22,7 @@ User guide: [docs/guides/pinned-questions.md](../../guides/pinned-questions.md).
- `src/core/questions/phase.ts` — Cycle phase `standing_questions` (global, writes): syncs question pages, refreshes due active pins (never answered, then stale, then new evidence since the watermark; cooldown per pin or `cycle.standing_questions.cooldown_days`) under one `BudgetMeter` (`cycle.standing_questions.budget_usd`) and `max_per_cycle`, stops on `budget_exhausted` or `no_model_key`, and stamps `cycle.standing_questions.last_run_at`. Kill switch `cycle.standing_questions.enabled=false`.
-- `src/core/questions/auto-think-migration.ts` — Maps the seven `dream.auto_think` keys onto pins without creating consent (disabled or zero budget → inactive; `auto_commit=false` → draft; cooldown and model per pin; budget, max and allow_unpriced seed `cycle.standing_questions.*` only when unset). Config reads and inserts only; idempotent. `autoThinkReplacement` is what `gbrain config get|set` prints for an old key.
+- `src/core/questions/auto-think-migration.ts` — Maps the seven `dream.auto_think` keys onto pins without creating consent (every pin imports inactive: `migrated_disabled`, `migrated_zero_budget` or `migrated_enabled`; `auto_commit=false` → draft; cooldown and model per pin; budget, max and allow_unpriced seed `cycle.standing_questions.*` only when unset). Config reads and inserts only; idempotent. `autoThinkReplacement` is what `gbrain config get|set` prints for an old key.
- `src/core/ops/questions.ts` — `questions_pin`, `questions_refresh`, `questions_unpin` (write, `writeInference` `explicit_llm` / `none`) and `questions_list`, `questions_status` (read). On the full surface registrations pin (not `STARTER_OPS`). CLI equivalents in `src/core/ops/cli-equivalent.ts`.
diff --git a/docs/guides/pinned-questions.md b/docs/guides/pinned-questions.md
index 4b4b5be775..1dca16206c 100644
--- a/docs/guides/pinned-questions.md
+++ b/docs/guides/pinned-questions.md
@@ -74,7 +74,7 @@ Every pin, list, status and refresh returns the same fields:
| `blocked_reason` | Meaning | Next action |
|---|---|---|
-| `awaiting_consent` | The pin was made over MCP (or imported from a disabled `dream.auto_think`) and is not active | The owner runs `gbrain questions pin --id <id>` |
+| `awaiting_consent` | The pin was made over MCP (or imported from `dream.auto_think`) and is not active | The owner runs `gbrain questions pin --id <id>` |
| `no_model_key` | No chat-model key is configured | The user adds an Anthropic or OpenAI key (`gbrain providers list` shows how) |
| `budget_exhausted` | This run's refresh budget is spent | Raise `cycle.standing_questions.budget_usd`, or wait for the next run |
| `refresh_failed` | The last refresh failed; the previous answer is kept with its stale flags | `questions_refresh {id, full: true}` |
@@ -169,13 +169,17 @@ A draft-only pin (`publish_mode: draft`) is refreshed but not served by
## Coming from dream.auto_think
The `dream.auto_think` settings became pins when this brain upgraded. Each
-saved question is a pin in the `default` source:
+saved question is a pin in the `default` source. Every migrated pin starts
+inactive, whatever `dream.auto_think.enabled` said, because auto_think never
+ran in the dream cycle and the upgrade starts no paid refresh. Turn one on
+with `gbrain questions pin --id <id>` (`gbrain questions list` shows the ids);
+from then on the dream cycle refreshes it under the migrated budget.
| Old key | Now |
|---|---|
-| `dream.auto_think.questions` | One pin per question (`origin: auto_think`) |
-| `dream.auto_think.enabled=false` | The pins are inactive until you run `gbrain questions pin --id <id>` |
-| `dream.auto_think.budget` | `cycle.standing_questions.budget_usd`; a zero budget leaves the pins inactive |
+| `dream.auto_think.questions` | One inactive pin per question (`origin: auto_think`) |
+| `dream.auto_think.enabled` | Recorded as the pin's `inactive_reason`: `migrated_disabled` when it was off, `migrated_enabled` when it was on |
+| `dream.auto_think.budget` | `cycle.standing_questions.budget_usd`; a zero budget is recorded as `migrated_zero_budget` |
| `dream.auto_think.auto_commit=false` | The pins are draft-only |
| `dream.auto_think.cooldown_days` | Each pin's cooldown |
| `dream.auto_think.max_per_cycle` | `cycle.standing_questions.max_per_cycle` |
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index e40a5a5bd2..c41c28c797 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -383,7 +383,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
// Memory proof wave (#6066). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.
{ since: '0.60.159.0', text: '`query` now adds saved facts that match the question as rows of their own, at most 3, only in row and token capacity the pages left free, so no page row is pushed out. A fact row has `result_type: "fact"`, `fact_id` and a `follow_up` recall call, and never a page slug or id; a page row whose claim a newer saved fact replaced carries `superseded_claim`. It adds up to three database lookups per query and no model call. Remote callers see only facts whose source pages they could read. `gbrain config set search.query_facts_arm false` restores the previous results.' },
{ since: '0.60.159.0', text: 'A saved fact now replaces a similar older fact by embedding similarity only when the brain\'s embedding model has a measured threshold. The default voyage-4 at 1024 dimensions keeps 0.95 and decides as before. With any other model, both facts stay active and the conflict review sweep judges the pair where it is on; exact-text duplicates are still merged. Doctor `supersession_calibration` names the command that measures a threshold (about a cent of synthetic text, no brain content), and `gbrain config set facts.supersession_thresholds \'{"<provider:model@dims>": <threshold>}\'` registers one.' },
- { since: '0.60.159.0', text: 'Pinned questions replace `dream.auto_think`. On upgrade, each question in `dream.auto_think.questions` becomes a pinned question, with its budget, cooldown, model and commit setting; it is inactive when auto_think was off or its budget was 0. An active pin is refreshed by the dream cycle\'s new `standing_questions` phase, which spends from `cycle.standing_questions.budget_usd`; auto_think never ran in the cycle. `gbrain questions list` shows the pins, `gbrain questions unpin <id>` stops one, and `gbrain config set cycle.standing_questions.enabled false` stops the phase. `gbrain dream --phase auto_think` now exits with a usage error naming the replacement.' },
+ { since: '0.60.159.0', text: 'Pinned questions replace `dream.auto_think`, which never ran in the dream cycle. On upgrade, each question in `dream.auto_think.questions` becomes an inactive pinned question that keeps its cooldown, model and commit setting, and a positive `dream.auto_think.budget` becomes `cycle.standing_questions.budget_usd`; nothing refreshes or spends until you activate a pin. `gbrain questions list` shows the ids, and `gbrain questions pin --id <id>` activates one, after which the dream cycle\'s `standing_questions` phase refreshes it under that budget. `gbrain dream --phase auto_think` now exits with a usage error naming the replacement.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/cli-flag-registry.generated.ts b/src/core/cli-flag-registry.generated.ts
index 2bd596101f..62be77d6b2 100644
--- a/src/core/cli-flag-registry.generated.ts
+++ b/src/core/cli-flag-registry.generated.ts
@@ -72,7 +72,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
'graph-query': ['--brain', '--depth', '--direction', '--help', '--hop', '--include-foreign', '--json', '--mcp-only', '--source', '--type'],
'hook': ['--allow-unverified-remote', '--auto', '--brain', '--branch', '--cached', '--count', '--diff-filter', '--end-of-options', '--env', '--get', '--harness', '--help', '--jq', '--json', '--limit', '--name-only', '--others', '--path', '--porcelain', '--pure', '--quiet', '--remove', '--seat', '--session', '--show-current', '--show-toplevel', '--since', '--source', '--yes'],
'import': ['--accept-pending', '--allow-empty', '--allow-noncanonical-root', '--apply', '--background', '--brain', '--cached', '--diff-filter', '--dim', '--embedding-dimensions', '--embedding-model', '--empty', '--exclude', '--exclude-standard', '--explain', '--follow', '--force', '--force-rechunk', '--format', '--fresh', '--help', '--include-gitignored', '--is-shallow-repository', '--json', '--log-noop', '--name-only', '--no-accept-pending', '--no-embed', '--no-embedding', '--no-gpg-sign', '--no-pull', '--no-renames', '--no-verify', '--only', '--others', '--path', '--probe', '--progress-interval', '--progress-json', '--quiet', '--show-toplevel', '--skip-failed', '--slugs', '--source', '--source-id', '--stale', '--status', '--supabase', '--timeout', '--to', '--url', '--verify', '--wait', '--workers'],
- 'init': ['--access', '--allow-create-db', '--allow-docker', '--apply', '--assign-corpus', '--auto', '--brain', '--break-lock', '--budget-ms', '--budget-usd', '--chat-model', '--check', '--content-root', '--db-only', '--dest', '--dim', '--embedding-dimensions', '--embedding-model', '--expansion-model', '--facts', '--fix', '--force', '--full', '--git', '--grant-types', '--harness', '--help', '--http', '--images', '--issuer-url', '--json', '--key', '--lanes', '--limit', '--local-postgres', '--markdown', '--max-usd', '--mcp-only', '--mcp-url', '--migrate-only', '--model', '--no-autopilot-install', '--no-delegate', '--no-embed', '--no-embedding', '--no-expand', '--no-git', '--no-llm', '--no-repair', '--non-interactive', '--oauth-client-id', '--oauth-client-secret', '--once', '--only', '--page', '--params', '--path', '--pglite', '--phase', '--plan', '--prefer-postgres', '--preview', '--probe', '--profile', '--provenance', '--query', '--quiet', '--reference-date', '--remediate', '--remove', '--reset', '--retry-failed', '--save', '--schema-pack', '--scope', '--scopes', '--section', '--show-toplevel', '--skip-embed-check', '--source', '--source-id', '--stale', '--status', '--supabase', '--surface', '--to', '--touchpoint', '--url', '--url-env', '--version', '--wait', '--warn-only', '--workspace', '--yes'],
+ 'init': ['--access', '--allow-create-db', '--allow-docker', '--apply', '--assign-corpus', '--auto', '--brain', '--break-lock', '--budget-ms', '--budget-usd', '--chat-model', '--check', '--content-root', '--db-only', '--dest', '--dim', '--embedding-dimensions', '--embedding-model', '--expansion-model', '--facts', '--fix', '--force', '--full', '--git', '--grant-types', '--harness', '--help', '--http', '--id', '--images', '--issuer-url', '--json', '--key', '--lanes', '--limit', '--local-postgres', '--markdown', '--max-usd', '--mcp-only', '--mcp-url', '--migrate-only', '--model', '--no-autopilot-install', '--no-delegate', '--no-embed', '--no-embedding', '--no-expand', '--no-git', '--no-llm', '--no-repair', '--non-interactive', '--oauth-client-id', '--oauth-client-secret', '--once', '--only', '--page', '--params', '--path', '--pglite', '--phase', '--plan', '--prefer-postgres', '--preview', '--probe', '--profile', '--provenance', '--query', '--quiet', '--reference-date', '--remediate', '--remove', '--reset', '--retry-failed', '--save', '--schema-pack', '--scope', '--scopes', '--section', '--show-toplevel', '--skip-embed-check', '--source', '--source-id', '--stale', '--status', '--supabase', '--surface', '--to', '--touchpoint', '--url', '--url-env', '--version', '--wait', '--warn-only', '--workspace', '--yes'],
'integrations': ['--auto', '--brain', '--dry-run', '--help', '--json', '--overwrite', '--refresh', '--source', '--target'],
'integrity': ['--accept-pending', '--auto', '--backend', '--background', '--brain', '--confidence', '--cost', '--dry-run', '--explain', '--follow', '--fresh', '--help', '--json', '--limit', '--no-accept-pending', '--probe', '--progress-interval', '--progress-json', '--quiet', '--review-lower', '--skip-bare-tweet', '--skip-urls', '--source', '--supabase', '--timeout', '--type', '--url', '--wait'],
'jobs': ['--abbrev-ref', '--access', '--add', '--admin-intent', '--aliases', '--all', '--allow-empty', '--allow-shell-jobs', '--allowed-operations', '--apply', '--asof', '--auto', '--background', '--backoff-delay', '--backoff-jitter', '--backoff-type', '--batch-size', '--bound-slug-prefixes', '--brain', '--break-lock', '--by-mention', '--cached', '--catch-up', '--check', '--cli-path', '--client', '--cluster-errors', '--concurrency', '--confidence', '--confirm-destructive', '--confirm-quiesced', '--cost-estimate', '--date', '--dated-since', '--days', '--delay', '--detach', '--diff-filter', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--empty', '--entities', '--exclude', '--exclude-standard', '--expect', '--expected-state', '--explain', '--facts', '--federated-read', '--filters', '--fix', '--follow', '--force', '--force-break-lock', '--format', '--fresh', '--from-meetings', '--full', '--full-history', '--fuzzy', '--grammar-diagnostics', '--group', '--hard-deadline', '--health-interval', '--help', '--http', '--id', '--idempotency-key', '--ids', '--images', '--include-deleted', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--infer-dates', '--inject-bootstrap', '--inline', '--input', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--job-id', '--job-isolation', '--json', '--kind', '--lanes', '--limit', '--lock-duration-ms', '--log-noop', '--markdown', '--max-age', '--max-attempts', '--max-cost', '--max-cost-usd', '--max-crashes', '--max-rss', '--max-sources', '--max-stalled', '--max-usd', '--max-waiting', '--mcp-only', '--min-context', '--missing-path', '--model', '--multimodal', '--name-only', '--ner', '--nice', '--no-auto-embed', '--no-autopilot-install', '--no-bulk', '--no-confirm', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-inject', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-worker', '--non-interactive', '--now', '--older-than', '--once', '--only', '--order', '--others', '--output', '--override-disabled', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--path', '--pause', '--phase', '--pid-file', '--priority', '--probe', '--prune-orphans', '--purge', '--queue', '--queue-only', '--quiet', '--reason', '--rebuild', '--recent', '--redact-secrets', '--reenrich-after', '--refresh-ms', '--refresh-operations', '--replace', '--repo', '--reset-checkpoint', '--resume', '--retry-failed', '--retry-held', '--review-lower', '--row', '--scopes', '--segment-limit', '--select', '--serial', '--session', '--show-toplevel', '--sigkill-rescue', '--since', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--sleep', '--slug', '--slugs', '--source', '--source-id', '--sources', '--src-subpath', '--stale', '--status', '--strategy', '--surface', '--swap-only', '--target', '--thin', '--thin-threshold', '--timeout', '--timeout-ms', '--to', '--trust', '--type', '--types', '--uninstall', '--updated-after', '--url', '--user', '--vectors', '--verbose', '--verify', '--version', '--watch', '--wedge-rescue', '--workers', '--working-tree', '--yes'],
diff --git a/src/core/questions/auto-think-migration.ts b/src/core/questions/auto-think-migration.ts
index c52b97e167..35e710aaaa 100644
--- a/src/core/questions/auto-think-migration.ts
+++ b/src/core/questions/auto-think-migration.ts
@@ -1,10 +1,14 @@
/**
* dream.auto_think -> pinned questions (C4 migration). Maps all seven legacy
- * keys without creating consent the owner never gave:
+ * keys without creating consent the owner never gave. Every migrated pin
+ * imports inactive: the auto_think phase had no caller, so a setting that
+ * never spent must not start paid refreshes on upgrade. The owner activates
+ * one by pinning it again with its id (`gbrain questions list` shows it).
*
* dream.auto_think.questions one pin per question (source `default`, no scope)
- * dream.auto_think.enabled=false pins import inactive (`migrated_disabled`)
- * dream.auto_think.budget = 0 pins import inactive (`migrated_zero_budget`);
+ * dream.auto_think.enabled=false inactive_reason `migrated_disabled`
+ * dream.auto_think.budget = 0 inactive_reason `migrated_zero_budget`
+ * enabled, positive budget inactive_reason `migrated_enabled`;
* a positive budget seeds cycle.standing_questions.budget_usd
* dream.auto_think.auto_commit false (the default) keeps draft-only publishing
* dream.auto_think.cooldown_days per-pin cooldown (default 30, as before)
@@ -51,7 +55,7 @@ export function noteAutoThinkReplacement(key: string): void {
export interface AutoThinkMigrationReport {
questions: number;
inserted: number;
- state: 'active' | 'inactive' | null;
+ state: 'inactive' | null;
publish_mode: 'publish' | 'draft' | null;
config_set: string[];
}
@@ -97,8 +101,8 @@ export async function migrateAutoThinkToPins(engine: BrainEngine): Promise<AutoT
const model = (await read('models.auto_think')) || (await read('dream.auto_think.model')) || null;
const lastCompletion = await read('dream.auto_think.last_completion_ts');
const anchor = lastCompletion && Number.isFinite(Date.parse(lastCompletion)) ? new Date(Date.parse(lastCompletion)).toISOString() : null;
- const inactiveReason = !enabled ? 'migrated_disabled' : budget <= 0 ? 'migrated_zero_budget' : null;
- report.state = inactiveReason ? 'inactive' : 'active';
+ const inactiveReason = !enabled ? 'migrated_disabled' : budget <= 0 ? 'migrated_zero_budget' : 'migrated_enabled';
+ report.state = 'inactive';
report.publish_mode = autoCommit ? 'publish' : 'draft';
for (const question of questions) {
diff --git a/src/core/questions/receipt.ts b/src/core/questions/receipt.ts
index 512c5a878c..f24e1f20e2 100644
--- a/src/core/questions/receipt.ts
+++ b/src/core/questions/receipt.ts
@@ -81,8 +81,8 @@ export function fixFor(pin: PinRow, blocked: BlockedReason | null, freshness: Fr
case 'awaiting_consent':
return {
argv: ['gbrain', 'questions', 'pin', '--id', id], consent: ['paid'], actor: remote ? 'user' : 'agent',
- why: pin.inactive_reason === 'migrated_disabled' || pin.inactive_reason === 'migrated_zero_budget'
- ? 'This pin was imported from dream.auto_think, which was off (or had a zero budget), so it stays inactive until the owner turns it on. Activating it allows paid model refreshes under cycle.standing_questions.budget_usd.'
+ why: pin.inactive_reason?.startsWith('migrated_')
+ ? 'This pin was imported from dream.auto_think, which never ran in the dream cycle, so it stays inactive until the owner turns it on. Activating it allows paid model refreshes under cycle.standing_questions.budget_usd.'
: 'A pin created over MCP stays inactive until the owner activates paid refresh on the brain host (or has set consent.preapprove.paid.max_usd_per_run). Activating it allows paid model refreshes under cycle.standing_questions.budget_usd.',
user_message: `The pinned question "${pin.question.slice(0, 120)}" needs a paid model call to answer and to keep its answer current. Activate it with: gbrain questions pin --id ${id}`,
verify: verifyStep(id), requires_exclusive: false,
diff --git a/src/core/questions/store.ts b/src/core/questions/store.ts
index d99ea9f186..603e461256 100644
--- a/src/core/questions/store.ts
+++ b/src/core/questions/store.ts
@@ -8,7 +8,7 @@ import type { BrainEngine } from '../engine.ts';
import { formatQuestionId, type QuestionScope } from './identity.ts';
export type PinState = 'active' | 'inactive' | 'archived';
-export type InactiveReason = 'awaiting_consent' | 'migrated_disabled' | 'migrated_zero_budget';
+export type InactiveReason = 'awaiting_consent' | 'migrated_disabled' | 'migrated_zero_budget' | 'migrated_enabled';
export type PublishMode = 'publish' | 'draft';
export type SentenceOrigin = 'model' | 'owner';
diff --git a/test/helpers/pinned-questions-scenarios.ts b/test/helpers/pinned-questions-scenarios.ts
index 29481c75b4..f4754499cc 100644
--- a/test/helpers/pinned-questions-scenarios.ts
+++ b/test/helpers/pinned-questions-scenarios.ts
@@ -584,7 +584,7 @@ export function registerPinnedQuestionSuite(label: string, getEngine: () => Brai
} finally { __setChatTransportForTests(null); await reset(engine); }
});
- run('enabled with a zero budget imports inactive; enabled with auto_commit imports active and published', async (engine) => {
+ run('enabled with a zero budget imports inactive; enabled with auto_commit imports inactive and published', async (engine) => {
try {
await reset(engine);
await engine.setConfig('dream.auto_think.questions', JSON.stringify(['Who leads acme-example?']));
@@ -597,10 +597,38 @@ export function registerPinnedQuestionSuite(label: string, getEngine: () => Brai
await engine.setConfig('dream.auto_think.questions', JSON.stringify(['Who leads acme-example?']));
await engine.setConfig('dream.auto_think.enabled', 'true');
await engine.setConfig('dream.auto_think.auto_commit', 'true');
- expect(await migrateAutoThinkToPins(engine)).toMatchObject({ state: 'active', publish_mode: 'publish' });
- expect((await migrated(engine))[0]).toMatchObject({ state: 'active', publish_mode: 'publish', inactive_reason: null, cooldown_days: 30 });
+ expect(await migrateAutoThinkToPins(engine)).toMatchObject({ state: 'inactive', publish_mode: 'publish' });
+ expect((await migrated(engine))[0]).toMatchObject({ state: 'inactive', publish_mode: 'publish', inactive_reason: 'migrated_enabled', cooldown_days: 30 });
expect(questionSlug('Who leads acme-example?', { source: 'default' })).toMatch(/^questions\/who-leads-acme-example-[0-9a-f]{8}$/);
} finally { await reset(engine); }
});
+
+ run('an enabled auto_think imports inactive pins that standing_questions skips until the owner activates one', async (engine) => {
+ const question = 'Which widgets did acme-example ship this quarter?';
+ try {
+ await reset(engine);
+ await engine.setConfig('dream.auto_think.questions', JSON.stringify([question]));
+ await engine.setConfig('dream.auto_think.enabled', 'true');
+ await engine.setConfig('dream.auto_think.budget', '2.5');
+ expect(await migrateAutoThinkToPins(engine)).toMatchObject({ inserted: 1, state: 'inactive' });
+ expect((await migrated(engine))[0]).toMatchObject({ state: 'inactive', inactive_reason: 'migrated_enabled' });
+ expect(await engine.getConfig('cycle.standing_questions.budget_usd')).toBe('2.5');
+ const id = `default:${questionSlug(question, { source: 'default' })}`;
+ const status = await questionStatus(localCtx(engine, 'default'), { id });
+ expect(status).toMatchObject({ state: 'inactive', blocked_reason: 'awaiting_consent', fix: { argv: ['gbrain', 'questions', 'pin', '--id', id] } });
+
+ const before = stubChat();
+ const idle = await runPhaseStandingQuestions(engine, { dryRun: false, chat: before.fn });
+ expect(before.calls.filter(c => c.includes(question))).toHaveLength(0);
+ expect((idle.details as { outcomes: Array<{ id: string }> }).outcomes.map(o => o.id)).not.toContain(id);
+
+ const activated = await pinQuestion(localCtx(engine, 'default'), { id, defer: true });
+ expect(activated).toMatchObject({ created: false, activated: true, receipt: { state: 'active' } });
+ const after = stubChat();
+ const ran = await runPhaseStandingQuestions(engine, { dryRun: false, chat: after.fn });
+ expect((ran.details as { outcomes: Array<{ id: string }> }).outcomes.map(o => o.id)).toContain(id);
+ expect(after.calls.filter(c => c.includes(question)).length).toBeGreaterThan(0);
+ } finally { await reset(engine); }
+ });
});
}