@noetic-tools/context 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/layer-lifecycle.d.ts +16 -1
- package/dist/context/layer-lifecycle.js +34 -3
- package/dist/context/layers/history.d.ts +1 -0
- package/dist/context/layers/history.js +1 -0
- package/dist/context/layers/observations.d.ts +2 -2
- package/dist/context/layers/plan-prompts.d.ts +2 -2
- package/dist/context/layers/plan-state.d.ts +5 -5
- package/dist/context/layers/scratchpad.d.ts +2 -2
- package/dist/context/layers/steering.d.ts +1 -1
- package/dist/context/layers/task-state.d.ts +2 -2
- package/package.json +2 -2
|
@@ -90,6 +90,12 @@ interface SpawnLayersParams {
|
|
|
90
90
|
}
|
|
91
91
|
interface ReturnLayersParams<T = unknown> {
|
|
92
92
|
layers: ContextLayer[];
|
|
93
|
+
/**
|
|
94
|
+
* Id of the spawn (or inParallel) step whose child is returning. Names the
|
|
95
|
+
* step in `spawn_summary_failed` diagnostics; defaults to the child's
|
|
96
|
+
* execution id.
|
|
97
|
+
*/
|
|
98
|
+
stepId?: string;
|
|
93
99
|
parentCtx: ExecutionContext;
|
|
94
100
|
childCtx: ExecutionContext;
|
|
95
101
|
childLog: ItemLog;
|
|
@@ -180,6 +186,8 @@ export interface RecallCache {
|
|
|
180
186
|
}
|
|
181
187
|
export declare function createRecallCache(): RecallCache;
|
|
182
188
|
export declare function mostRestrictive(decisions: SteeringDecision[]): SteeringDecision;
|
|
189
|
+
/** Span event added to the child's span when a layer's `onReturn` hook fails. */
|
|
190
|
+
export declare const SPAWN_SUMMARY_FAILED_EVENT = "spawn.summary_failed";
|
|
183
191
|
export declare function initLayers({ layers, ctx, storage, store, keep, }: InitLayersParams): Promise<void>;
|
|
184
192
|
export declare function recallLayers({ layers, query, ctx, log, budgets, store, itemSchemas, peek, }: RecallLayersParams): Promise<RecallEntry[]>;
|
|
185
193
|
type RecallEntry = {
|
|
@@ -229,7 +237,14 @@ export declare function spawnLayers({ layers, parentCtx, childCtx, store, itemSc
|
|
|
229
237
|
childState: unknown;
|
|
230
238
|
items: Item[];
|
|
231
239
|
}[]>;
|
|
232
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Pipes a child's result through each layer's `onReturn` hook in slot order.
|
|
242
|
+
*
|
|
243
|
+
* A failing hook never fails the spawn: the child's work already succeeded,
|
|
244
|
+
* so the result passes on unchanged and the failure is reported as a
|
|
245
|
+
* `spawn_summary_failed` diagnostic plus a span event on the child's span.
|
|
246
|
+
*/
|
|
247
|
+
export declare function returnLayers<T>({ layers, stepId, parentCtx, childCtx, childLog, result, store, }: ReturnLayersParams<T>): Promise<T>;
|
|
233
248
|
export declare function completeLayers({ layers, ctx, log, outcome, store, }: CompleteLayersParams): Promise<void>;
|
|
234
249
|
export declare function beforeToolCallLayers({ layers, toolName, toolArgs, callId, ctx, store, }: BeforeToolCallLayersParams): Promise<SteeringDecision>;
|
|
235
250
|
export declare function afterModelCallLayers({ layers, response, ctx, store, }: AfterModelCallLayersParams): Promise<SteeringDecision>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMessage, defaultItemSchemaRegistry, estimateTokens, frameworkCast, NoeticConfigError, SteeringAction, } from '@noetic-tools/types';
|
|
1
|
+
import { createMessage, defaultItemSchemaRegistry, estimateTokens, frameworkCast, NoeticConfigError, NoeticErrorImpl, SteeringAction, } from '@noetic-tools/types';
|
|
2
2
|
import { createScopedStorage, resolveScopeKey } from './scope.js';
|
|
3
3
|
/** Maximum allowed re-render depth to prevent infinite loops */
|
|
4
4
|
const MAX_RERENDER_DEPTH = 3;
|
|
@@ -177,6 +177,23 @@ export function mostRestrictive(decisions) {
|
|
|
177
177
|
function layerItemSchemas(layer, base = defaultItemSchemaRegistry) {
|
|
178
178
|
return base.extend(layer.itemSchemas);
|
|
179
179
|
}
|
|
180
|
+
/** Span event added to the child's span when a layer's `onReturn` hook fails. */
|
|
181
|
+
export const SPAWN_SUMMARY_FAILED_EVENT = 'spawn.summary_failed';
|
|
182
|
+
function reportSummaryFailure({ layerId, stepId, childOutput, cause, childCtx, store, }) {
|
|
183
|
+
const summaryCause = cause instanceof Error ? cause : new Error(String(cause));
|
|
184
|
+
const error = new NoeticErrorImpl({
|
|
185
|
+
kind: 'spawn_summary_failed',
|
|
186
|
+
stepId,
|
|
187
|
+
childOutput,
|
|
188
|
+
summaryCause,
|
|
189
|
+
});
|
|
190
|
+
childCtx.trace.addEvent(SPAWN_SUMMARY_FAILED_EVENT, {
|
|
191
|
+
stepId,
|
|
192
|
+
layerId,
|
|
193
|
+
message: summaryCause.message,
|
|
194
|
+
});
|
|
195
|
+
store.diagnostic(layerId, 'onReturn', error);
|
|
196
|
+
}
|
|
180
197
|
//#endregion
|
|
181
198
|
//#region Public API
|
|
182
199
|
export async function initLayers({ layers, ctx, storage, store, keep = false, }) {
|
|
@@ -560,7 +577,14 @@ export async function spawnLayers({ layers, parentCtx, childCtx, store, itemSche
|
|
|
560
577
|
}
|
|
561
578
|
return results;
|
|
562
579
|
}
|
|
563
|
-
|
|
580
|
+
/**
|
|
581
|
+
* Pipes a child's result through each layer's `onReturn` hook in slot order.
|
|
582
|
+
*
|
|
583
|
+
* A failing hook never fails the spawn: the child's work already succeeded,
|
|
584
|
+
* so the result passes on unchanged and the failure is reported as a
|
|
585
|
+
* `spawn_summary_failed` diagnostic plus a span event on the child's span.
|
|
586
|
+
*/
|
|
587
|
+
export async function returnLayers({ layers, stepId, parentCtx, childCtx, childLog, result, store, }) {
|
|
564
588
|
const sorted = [
|
|
565
589
|
...layers,
|
|
566
590
|
].sort((a, b) => a.slot - b.slot);
|
|
@@ -594,7 +618,14 @@ export async function returnLayers({ layers, parentCtx, childCtx, childLog, resu
|
|
|
594
618
|
}
|
|
595
619
|
}
|
|
596
620
|
catch (e) {
|
|
597
|
-
|
|
621
|
+
reportSummaryFailure({
|
|
622
|
+
layerId: layer.id,
|
|
623
|
+
stepId: stepId ?? childCtx.executionId,
|
|
624
|
+
childOutput: currentResult,
|
|
625
|
+
cause: e,
|
|
626
|
+
childCtx,
|
|
627
|
+
store,
|
|
628
|
+
});
|
|
598
629
|
}
|
|
599
630
|
}
|
|
600
631
|
// The child execution's store is typically cleaned up right after onReturn —
|
|
@@ -27,5 +27,6 @@ export interface HistoryConfig {
|
|
|
27
27
|
* @public
|
|
28
28
|
* @param config - Optional `{ maxItems }`. Defaults to 40.
|
|
29
29
|
* @returns A `ContextLayer` that contributes only a `projectHistory` hook.
|
|
30
|
+
* @throws `NoeticConfigError` with code `INVALID_HISTORY_MAX_ITEMS` if `maxItems` is not an integer in the allowed range.
|
|
30
31
|
*/
|
|
31
32
|
export declare function history(config?: HistoryConfig): ContextLayer<null>;
|
|
@@ -100,6 +100,7 @@ function findHeadAnchor(items, windowStart) {
|
|
|
100
100
|
* @public
|
|
101
101
|
* @param config - Optional `{ maxItems }`. Defaults to 40.
|
|
102
102
|
* @returns A `ContextLayer` that contributes only a `projectHistory` hook.
|
|
103
|
+
* @throws `NoeticConfigError` with code `INVALID_HISTORY_MAX_ITEMS` if `maxItems` is not an integer in the allowed range.
|
|
103
104
|
*/
|
|
104
105
|
export function history(config) {
|
|
105
106
|
const maxItems = config?.maxItems ?? DEFAULT_MAX_ITEMS;
|
|
@@ -19,10 +19,10 @@ export interface ObservationsConfig {
|
|
|
19
19
|
* @returns A `ContextLayer` that accumulates and summarizes observations over time.
|
|
20
20
|
*/
|
|
21
21
|
export declare function observations(config?: ObservationsConfig): {
|
|
22
|
-
id:
|
|
22
|
+
id: "observations";
|
|
23
23
|
name: string;
|
|
24
24
|
slot: 200;
|
|
25
|
-
scope: "
|
|
25
|
+
scope: "thread" | "resource";
|
|
26
26
|
budget: {
|
|
27
27
|
min: number;
|
|
28
28
|
max: number;
|
|
@@ -17,9 +17,9 @@ import type { PlanState } from './plan-state.js';
|
|
|
17
17
|
/** How the planning briefing shapes the turn. */
|
|
18
18
|
export declare const PlanStyle: {
|
|
19
19
|
/** Explore → design → review → write → exit. Best when the work's shape is known. */
|
|
20
|
-
readonly Phased:
|
|
20
|
+
readonly Phased: "phased";
|
|
21
21
|
/** Explore → write → ask, on repeat. Best when requirements are still vague. */
|
|
22
|
-
readonly Interview:
|
|
22
|
+
readonly Interview: "interview";
|
|
23
23
|
};
|
|
24
24
|
export type PlanStyle = (typeof PlanStyle)[keyof typeof PlanStyle];
|
|
25
25
|
export interface PlanningPromptOptions {
|
|
@@ -5,11 +5,11 @@ import type { WorkflowDocument } from '@noetic-tools/types';
|
|
|
5
5
|
* both depend on it without importing each other.
|
|
6
6
|
*/
|
|
7
7
|
export declare const PlanPhase: {
|
|
8
|
-
readonly Idle:
|
|
9
|
-
readonly Planning:
|
|
10
|
-
readonly Executing:
|
|
11
|
-
readonly Completed:
|
|
12
|
-
readonly Failed:
|
|
8
|
+
readonly Idle: "idle";
|
|
9
|
+
readonly Planning: "planning";
|
|
10
|
+
readonly Executing: "executing";
|
|
11
|
+
readonly Completed: "completed";
|
|
12
|
+
readonly Failed: "failed";
|
|
13
13
|
};
|
|
14
14
|
export type PlanPhase = (typeof PlanPhase)[keyof typeof PlanPhase];
|
|
15
15
|
export interface PlanExecutionEntry {
|
|
@@ -14,10 +14,10 @@ export interface ScratchpadConfig {
|
|
|
14
14
|
* @returns A `ContextLayer` providing scratchpad state the model can read and write.
|
|
15
15
|
*/
|
|
16
16
|
export declare function scratchpad(config?: ScratchpadConfig): {
|
|
17
|
-
id:
|
|
17
|
+
id: "scratchpad";
|
|
18
18
|
name: string;
|
|
19
19
|
slot: 100;
|
|
20
|
-
scope: "
|
|
20
|
+
scope: "thread" | "resource";
|
|
21
21
|
budget: {
|
|
22
22
|
min: number;
|
|
23
23
|
max: number;
|
|
@@ -7,7 +7,7 @@ import type { AfterModelCallParams, BeforeToolCallParams, ContextScope, LedgerEn
|
|
|
7
7
|
* @returns A `ContextLayer` that enforces steering rules via allow/deny/guide decisions.
|
|
8
8
|
*/
|
|
9
9
|
export declare function steering(config: SteeringConfig): {
|
|
10
|
-
id:
|
|
10
|
+
id: "steering";
|
|
11
11
|
name: string;
|
|
12
12
|
slot: 90;
|
|
13
13
|
scope: ContextScope;
|
|
@@ -46,7 +46,7 @@ export interface TaskStateOptions {
|
|
|
46
46
|
* @returns A `ContextLayer` scoped to the thread with durable task state.
|
|
47
47
|
*/
|
|
48
48
|
export declare function taskState(opts?: TaskStateOptions): {
|
|
49
|
-
id:
|
|
49
|
+
id: "task-state";
|
|
50
50
|
name: string;
|
|
51
51
|
slot: number;
|
|
52
52
|
scope: "thread";
|
|
@@ -93,7 +93,6 @@ export declare function taskState(opts?: TaskStateOptions): {
|
|
|
93
93
|
}>;
|
|
94
94
|
onComplete({ state, outcome, ctx }: import("@noetic-tools/types").CompleteParams<TaskState>): Promise<{
|
|
95
95
|
state: {
|
|
96
|
-
files: string[];
|
|
97
96
|
data: {
|
|
98
97
|
__outcome: import("@noetic-tools/types").ExecutionOutcome;
|
|
99
98
|
};
|
|
@@ -101,6 +100,7 @@ export declare function taskState(opts?: TaskStateOptions): {
|
|
|
101
100
|
timestamp: number;
|
|
102
101
|
depth: number;
|
|
103
102
|
}[];
|
|
103
|
+
files: string[];
|
|
104
104
|
};
|
|
105
105
|
} | undefined>;
|
|
106
106
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/context",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Context layer system for Noetic agents: the ContextLayer contract, lifecycle, budget/projection machinery, and built-in layer implementations.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"zod": "^4.0.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@noetic-tools/types": "^3.
|
|
47
|
+
"@noetic-tools/types": "^3.7.0",
|
|
48
48
|
"zod": "^4.0.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|