Skip to content

Commit 98e0859

Browse files
V48 (specification-implementation): Generation hierarchy; failsafe context types leave context/
Audit @bitcode/context: prepared-context types belong with failsafes, not a process-global bag. Establish generation-generics primitives and nested generic-generations/{failsafes,thinkings}. Move PreparedContext helpers into failsafes; leave GlobalContext (+ BC re-exports) in context. agent-generics composes bases; AssetPack synthesis documents product extension without reimplementing failsafe/thinkings. LLM-bound factories remain in agent-generics until AgentExecution coupling is inverted.
1 parent bbe783a commit 98e0859

30 files changed

Lines changed: 502 additions & 126 deletions

BITCODE_SPEC_V48_NOTES.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,3 +1531,22 @@ Pipeline inheritance hierarchy is now explicit:
15311531
`factorySDIVFExecutorPipeline` / `factorySDIVFPipeline` / `SDIVFPhase` live in
15321532
`@bitcode/generic-pipelines-sdivf`. AssetPack imports the base package directly.
15331533
`pipelines-generics` re-exports for compatibility.
1534+
1535+
## Generation hierarchy + context/failsafes audit (Garrett, 2026-07-13)
1536+
1537+
Audit: `@bitcode/context` mixed process-global `GlobalContext` with failsafe
1538+
prepared-context types (`PreparedContext`, `prepareConciseContext`, chunking).
1539+
Those failsafe types now live with failsafes.
1540+
1541+
```
1542+
@bitcode/generation-generics
1543+
→ @bitcode/generic-generations-failsafes # packages/generic-generations/failsafes
1544+
→ @bitcode/generic-generations-thinkings # packages/generic-generations/thinkings
1545+
→ @bitcode/agent-generics # PTRR agents; still hosts LLM-bound factories
1546+
→ @bitcode/pipeline-asset-pack # product uses bases; does not reimplement
1547+
```
1548+
1549+
`@bitcode/context` keeps only `GlobalContext` (+ BC re-exports of failsafe helpers).
1550+
Physical move of `createFailsafeGenerationSequence` / Thinkings factories out of
1551+
agent-generics remains gated on inverting AgentExecution LLM coupling.
1552+

FAMILIARIZATION.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,28 @@ uapi → HTTP + React adapters only
111111
```
112112
@bitcode/execution-generics Execution + Executor (lowest runtime primitive)
113113
114-
@bitcode/agent-generics Agent : Executor, PTRR steps, failsafes, Thinkings
114+
@bitcode/agent-generics Agent : Executor, PTRR steps over generations
115115
116116
@bitcode/generic-agents/* Base agents (VCS, danger-wall, code-editor, …)
117117
118118
@bitcode/pipeline-asset-pack Deposit/read SDIVF agents (setup/discovery/…)
119119
```
120120

121+
### 3.1.1 Generations (failsafes + thinkings)
122+
123+
```
124+
@bitcode/generation-generics Generation type + failsafe/thinkings enums
125+
126+
@bitcode/generic-generations-failsafes failsafes/ — prepared-context types + base
127+
@bitcode/generic-generations-thinkings thinkings/ — Reason→Judge→StructuredOutput base
128+
129+
@bitcode/agent-generics composes failsafes/thinkings into PTRR Agents
130+
131+
@bitcode/pipeline-asset-pack product synthesis / phase agents (no reimplementation)
132+
```
133+
134+
Package path: `packages/generic-generations/{failsafes,thinkings}/`.
135+
121136
**PTRR** (Plan / Try / Refine / Retry) is the agent step model. Each step runs a
122137
**Failsafes** sequence:
123138

@@ -127,6 +142,14 @@ uapi → HTTP + React adapters only
127142

128143
Each failsafe’s generation is **Thinkings**: Reason → Judge → StructuredOutput.
129144

145+
Prepared-context types (`PreparedContext`, `prepareConciseContext`, …) live with
146+
**failsafes** (`@bitcode/generic-generations-failsafes`), not a free-floating
147+
context domain. `@bitcode/context` retains only process-global `GlobalContext`
148+
(+ BC re-exports of failsafe prepared-context helpers).
149+
150+
LLM-bound failsafe/thinkings **factories** still execute via `AgentExecution`
151+
inside `agent-generics` until inverted onto pure Execution + LLM registry.
152+
130153
Factories: `factoryAgent`, `factoryAgentWithPTRR` in `agent-generics`.
131154

132155
### 3.2 Tools
@@ -239,14 +262,17 @@ Grouped by role. Names are `@bitcode/<name>` unless noted.
239262
| Package | Responsibility |
240263
| --- | --- |
241264
| `execution-generics` | `Execution` state tree, `Executor`, sequential/parallel/pipe |
242-
| `agent-generics` | Agent = Executor + PTRR + failsafes + generations |
265+
| `agent-generics` | Agent = Executor + PTRR composition over generations |
243266
| `tools-generics` | `Tool` class, factories, MCP bridges |
244267
| `pipelines-generics` | Pipeline / PhaseDelegator primitives / stream hooks (re-exports SDIVF) |
245268
| `generic-pipelines-sdivf` | SDIVF base loop (`packages/generic-pipelines/SDIVF`) |
269+
| `generation-generics` | Generation primitive + failsafe/thinkings enums |
270+
| `generic-generations-failsafes` | Failsafe base + prepared-context types |
271+
| `generic-generations-thinkings` | Thinkings base vocabulary surface |
246272
| `llm-generics` | Pure LLM call contracts |
247273
| `registry` | Hierarchical registry (Prompt is a Registry) |
248274
| `prompts` | Prompt + PromptPart + **all** raw prompt parts |
249-
| `context` | Prepared context types for failsafes |
275+
| `context` | Process-global `GlobalContext` only (failsafe context → failsafes package) |
250276
| `logger` | Shared logging |
251277

252278
### 5.2 Generic implementations
@@ -257,6 +283,7 @@ Grouped by role. Names are `@bitcode/<name>` unless noted.
257283
| `generic-tools/*` | Nested base tools: editing, git, VCS, LSP, web-search, repository-setup, … |
258284
| `generic-pipelines/*` | Nested base pipelines: SDIVF, … |
259285
| `generic-llms/*` | Nested providers (xAI, OpenAI, Anthropic, Google), defaults, registry aggregator |
286+
| `generic-generations/*` | Nested generation bases: failsafes, thinkings |
260287
| `generic-doc-comment-plugins/*` | Nested doc-comment plugins |
261288

262289
### 5.3 Product domain (AssetPack / BTD / market)

internal-docs/BITCODE_SOURCE_LAYOUT.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ packages/generic-<family>/ # README only (no package.json)
193193
| `generic-tools/` | `web-search/`, `vcs/`, … | `@bitcode/generic-tools-*` |
194194
| `generic-pipelines/` | `SDIVF/` | `@bitcode/generic-pipelines-sdivf` |
195195
| `generic-llms/` | `xAI/`, `OpenAI/`, `Anthropic/`, `Google/`, `defaults/`, `registry/` | `@bitcode/generic-llms-*` (+ aggregator `@bitcode/generic-llms`) |
196+
| `generic-generations/` | `failsafes/`, `thinkings/` | `@bitcode/generic-generations-failsafes`, `-thinkings` |
196197
| `generic-doc-comment-plugins/` | `doc-developing/` | `@bitcode/doc-comment-developing` |
197198

198199
**Do not** put a root `package.json` on the family folder. Workspace globs are
@@ -285,6 +286,10 @@ bitcode/
285286
│ │ ├── Google/ # @bitcode/generic-llms-google
286287
│ │ ├── defaults/ # @bitcode/generic-llms-defaults
287288
│ │ └── registry/ # @bitcode/generic-llms (aggregator)
289+
│ ├── generation-generics/ # Generation primitive vocabulary
290+
│ ├── generic-generations/
291+
│ │ ├── failsafes/ # @bitcode/generic-generations-failsafes
292+
│ │ └── thinkings/ # @bitcode/generic-generations-thinkings
288293
│ ├── pipelines/
289294
│ │ └── asset-pack/ # SynthesizeAssetPacks (extends SDIVF)
290295
│ ├── agent-generics/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"packages/generic-agents/*",
1414
"packages/generic-pipelines/*",
1515
"packages/generic-llms/*",
16+
"packages/generic-generations/*",
1617
"packages/generic-doc-comment-plugins/*",
1718
"packages/pipelines/*",
1819
"uapi",

packages/agent-generics/jest.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module.exports = {
88
'^@bitcode/pipelines-generics$': '<rootDir>/../pipelines-generics/src/index.ts',
99
'^@bitcode/pipelines-generics/(.*)$': '<rootDir>/../pipelines-generics/src/$1',
1010
// nested generic-llms family (not packages/generic-llms/src)
11+
'^@bitcode/generation-generics$': '<rootDir>/../generation-generics/src/index.ts',
12+
'^@bitcode/generic-generations-failsafes$': '<rootDir>/../generic-generations/failsafes/src/index.ts',
13+
'^@bitcode/generic-generations-thinkings$': '<rootDir>/../generic-generations/thinkings/src/index.ts',
1114
'^@bitcode/generic-llms$': '<rootDir>/../generic-llms/registry/src/index.ts',
1215
'^@bitcode/generic-llms/defaults$': '<rootDir>/../generic-llms/defaults/src/index.ts',
1316
'^@bitcode/generic-llms-defaults$': '<rootDir>/../generic-llms/defaults/src/index.ts',

packages/agent-generics/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
},
1414
"dependencies": {
1515
"@bitcode/execution-generics": "workspace:*",
16+
"@bitcode/generation-generics": "workspace:*",
17+
"@bitcode/generic-generations-failsafes": "workspace:*",
18+
"@bitcode/generic-generations-thinkings": "workspace:*",
1619
"@bitcode/generic-llms": "workspace:*",
1720
"@bitcode/prompts": "workspace:*",
1821
"@bitcode/tools-generics": "workspace:*",

packages/agent-generics/src/index.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
11
/**
2-
* AGENT-GENERICS - Retained agent orchestration primitives
2+
* AGENT-GENERICS - Agent orchestration over generation bases
33
*
4-
* Agents are Executors that sequence retained PTRR-style steps.
5-
* This package survives as reusable orchestration infrastructure and as a
6-
* reference surface for Bitcode-native pipelines; it is not itself proof that
7-
* the old agent families remain live Bitcode canon.
4+
* Hierarchy:
5+
* generation-generics → generic-generations/{failsafes,thinkings}
6+
* → agent-generics (this package: Agent + PTRR composition)
7+
* → product (pipeline-asset-pack agents / synthesis)
8+
*
9+
* Agents are Executors that sequence PTRR-style steps. Each step runs 3 failsafe
10+
* parents (PrepareConciseContext → ChunkThenSum → StitchUntilComplete), each
11+
* driving Thinkings (Reason → Judge → StructuredOutput). Tools run after failsafes.
12+
*
13+
* Generation vocabulary: @bitcode/generation-generics
14+
* Failsafe prepared-context types: @bitcode/generic-generations-failsafes
15+
* LLM-bound failsafe/thinkings factories still hosted here until AgentExecution
16+
* coupling is inverted into pure Execution + LLM registry.
817
*
9-
* Different agent implementations are selected from registries dynamically.
10-
* Each step runs 3 failsafe parents sequentially, each running 3 generation children.
11-
* Tools execute AFTER all failsafes complete (conditional on reasoning + judgment output).
12-
*
13-
* Key Abstractions:
14-
* - Agent: Executor that sequences PTRR steps
15-
* - Step: StepExecutor that sequences 7 SubSteps
16-
* - SubStep: The atomic operations (3 failsafes + 3 generation + 1 tool)
17-
*
1818
* @doc-package
1919
* version: 1.0.0
2020
* pattern: ptrr-orchestration
21-
* philosophy: "Retained orchestration families remain reusable, but Bitcode decides which ones are admitted as live product behavior"
21+
* philosophy: "Agents compose generic generations; product specializes agents"
2222
*/
2323

2424
// ==================== CORE TYPES ====================
2525

26+
// Generation vocabulary (prefer direct import from generation-generics)
27+
export {
28+
FailsafeMetaSubStep,
29+
GenerationSubMetaSubStep,
30+
type Generation,
31+
} from '@bitcode/generation-generics';
32+
33+
// Failsafe prepared-context types (prefer generic-generations-failsafes)
34+
export type {
35+
PreparedContext,
36+
ContextSelector,
37+
PrepareConciseContextOptions,
38+
PrepareConciseContextResult,
39+
} from '@bitcode/generic-generations-failsafes';
40+
export {
41+
estimateSerializedSize,
42+
createContextSelectors,
43+
chunkContext,
44+
prepareConciseContext,
45+
} from '@bitcode/generic-generations-failsafes';
46+
2647
// Agent enums and types
2748
export {
2849
AgentVariationStep,
29-
FailsafeMetaSubStep,
30-
GenerationSubMetaSubStep
3150
} from './types';
3251

3352
// Agent interfaces
@@ -37,7 +56,6 @@ export type {
3756
AgentGeneration,
3857
QuickAgent,
3958
StepExecutor,
40-
PreparedContext,
4159
Chunk,
4260
Reasoning,
4361
UseTool,

packages/agent-generics/src/steps/failsafe-sequence.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
/**
2-
* FailsafeGenerationSequence - Canonical failsafes sequence builder
2+
* FailsafeGenerationSequence - canonical failsafe base composition.
33
*
4-
* Formalizes the default step generation as THREE failsafes in fixed order,
5-
* each with a DISTINCT trigger and a DISTINCT job:
4+
* Logical home: @bitcode/generic-generations-failsafes.
5+
* Hosted in agent-generics while failsafe factories still require
6+
* AgentExecution registries. Prepared-context pure types live in
7+
* @bitcode/generic-generations-failsafes; vocabulary in
8+
* @bitcode/generation-generics.
69
*
7-
* 1. PrepareConciseContext (context failsafe; ALWAYS runs; selection-only):
8-
* ONE selection Thinkings against the key-selection schema over the
9-
* keys-only root execution state, then the value read-in of exactly the
10-
* selected keys.
11-
* 2. ChunkThenSum (input failsafe; trigger = composed request exceeds the
12-
* request limit): ONE task Thinkings when the request fits; per-chunk task
13-
* generations + one summing pass when it does not.
14-
* 3. StitchUntilComplete (output failsafe; trigger = schema-INCOMPLETE or
15-
* truncated): repair-only, error-carrying stitch generations, bounded.
10+
* THREE failsafes in fixed order, each with a DISTINCT trigger and job:
11+
* 1. PrepareConciseContext — selection-only key Thinkings + value read-in
12+
* 2. ChunkThenSum — task Thinkings once or per-chunk + sum
13+
* 3. StitchUntilComplete — repair-only on incomplete/truncated output
1614
*
17-
* The sequence is selection -> task(xchunks) -> repair-only; the failsafes do
18-
* NOT wrap three identical task generations. Tools execution is a Step-level
19-
* postprocess and is composed by step factories after this core.
15+
* Sequence: selection → task(×chunks) → repair-only. Tools are step postprocess.
2016
*/
2117

2218
import { sequential, type Executor } from '@bitcode/execution-generics';

packages/agent-generics/src/steps/thinkings-generation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* ThinkingsGeneration - A single Generation composed of three child LLM calls
3-
* in strict order: Reason → Judge → StructuredOutput.
2+
* ThinkingsGeneration - Reason → Judge → StructuredOutput.
43
*
5-
* This is the atomic typed "Generation" used by steps. Failsafe wrappers
6-
* (PTRR-specific) can execute this generation under different parents.
4+
* Logical home: @bitcode/generic-generations-thinkings (base Thinkings).
5+
* Hosted here while factoryReason/Judge/StructuredOutput still depend on
6+
* AgentExecution LLM registries. Product code should treat this as the
7+
* generic-generations Thinkings base, not a product-local helper.
78
*/
89

910
import { sequential, type Executor } from '@bitcode/execution-generics';

packages/agent-generics/src/substeps/factories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { PROMPTPART_GENERIC_AGENT_GENERATION_TOP_LEVEL_KEYS_HINT } from '@bitcod
5656
* truncated output): error-carrying repair generations, bounded.
5757
*/
5858

59-
import { estimateSerializedSize } from '@bitcode/context';
59+
import { estimateSerializedSize } from '@bitcode/generic-generations-failsafes';
6060
import {
6161
sequential,
6262
parallel,

0 commit comments

Comments
 (0)