@namzu/sdk 62.1.0 → 62.2.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/CHANGELOG.md +10 -0
- package/dist/compaction/consolidation.d.ts +16 -1
- package/dist/compaction/consolidation.d.ts.map +1 -1
- package/dist/compaction/consolidation.js +8 -6
- package/dist/compaction/consolidation.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -0
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/public-runtime.d.ts +3 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +1 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/finalize-turn.d.ts.map +1 -1
- package/dist/runtime/query/finalize-turn.js +1 -1
- package/dist/runtime/query/finalize-turn.js.map +1 -1
- package/dist/runtime/query/index.d.ts +7 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/memory/secrets.d.ts +20 -0
- package/dist/store/memory/secrets.d.ts.map +1 -0
- package/dist/store/memory/secrets.js +84 -0
- package/dist/store/memory/secrets.js.map +1 -0
- package/dist/tools/memory/save.d.ts.map +1 -1
- package/dist/tools/memory/save.js +5 -0
- package/dist/tools/memory/save.js.map +1 -1
- package/dist/tools/memory/secret-guard.d.ts +8 -0
- package/dist/tools/memory/secret-guard.d.ts.map +1 -0
- package/dist/tools/memory/secret-guard.js +23 -0
- package/dist/tools/memory/secret-guard.js.map +1 -0
- package/dist/tools/memory/update.d.ts.map +1 -1
- package/dist/tools/memory/update.js +10 -0
- package/dist/tools/memory/update.js.map +1 -1
- package/dist/turn/index.d.ts +1 -1
- package/dist/turn/index.d.ts.map +1 -1
- package/dist/turn/memory-promoter.d.ts +20 -0
- package/dist/turn/memory-promoter.d.ts.map +1 -1
- package/dist/turn/memory-promoter.js +6 -3
- package/dist/turn/memory-promoter.js.map +1 -1
- package/package.json +1 -1
- package/src/compaction/consolidation.ts +29 -4
- package/src/compaction/index.ts +1 -0
- package/src/public-runtime.ts +3 -1
- package/src/public-types.ts +2 -0
- package/src/runtime/query/finalize-turn.ts +9 -5
- package/src/runtime/query/index.ts +8 -0
- package/src/store/index.ts +2 -0
- package/src/store/memory/secrets.ts +105 -0
- package/src/tools/memory/save.ts +4 -0
- package/src/tools/memory/secret-guard.ts +23 -0
- package/src/tools/memory/update.ts +9 -0
- package/src/turn/index.ts +1 -1
- package/src/turn/memory-promoter.ts +19 -2
package/dist/turn/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/turn/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACtE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7F,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,UAAU,EACV,iBAAiB,GACjB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,EACN,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,GACpB,MAAM,4BAA4B,CAAA;AACnC,YAAY,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAE9F,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzE,YAAY,EAAE,i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AAE,MAAM,0BAA0B,CAAA;AAClE,YAAY,EACX,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,0BAA0B,CAAA"}
|
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { MemoryStore } from '../types/memory/index.js';
|
|
7
7
|
import type { PromoteMemory } from '../types/session/memory-promotion.js';
|
|
8
|
+
/**
|
|
9
|
+
* The categories that make a turn worth remembering.
|
|
10
|
+
*
|
|
11
|
+
* Ordered as they are rendered. `userRequirements` first because it is the
|
|
12
|
+
* most durable of the five — a constraint the user stated outlives the turn
|
|
13
|
+
* that heard it, whereas a discovery about a codebase expires when the
|
|
14
|
+
* codebase moves.
|
|
15
|
+
*/
|
|
16
|
+
declare const KNOWLEDGE: readonly [readonly ["userRequirements", "What the user requires"], readonly ["decisions", "Decisions"], readonly ["discoveries", "Discoveries"], readonly ["failures", "What did not work"], readonly ["environment", "Environment"]];
|
|
8
17
|
/**
|
|
9
18
|
* Tag every record this promoter writes, so a host can find or prune them.
|
|
10
19
|
* Also its `metadata.source`, which keeps the record out of a Markdown
|
|
@@ -30,7 +39,17 @@ export interface MemoryPromoterOptions {
|
|
|
30
39
|
* that costs context every time it is retrieved.
|
|
31
40
|
*/
|
|
32
41
|
readonly maxPerCategory?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Decide whether one extracted claim may become part of a record. Called
|
|
44
|
+
* with the candidate's category (`userRequirements`, `decisions`,
|
|
45
|
+
* `discoveries`, `failures` or `environment`) and the claim text. A claim
|
|
46
|
+
* it rejects is left out; a record with no claim left is not written.
|
|
47
|
+
* Defaults to keeping every claim.
|
|
48
|
+
*/
|
|
49
|
+
readonly acceptClaim?: (category: SessionMemoryCategory, text: string) => boolean;
|
|
33
50
|
}
|
|
51
|
+
/** The claim categories of a {@link SessionMemoryCandidate}. */
|
|
52
|
+
export type SessionMemoryCategory = (typeof KNOWLEDGE)[number][0];
|
|
34
53
|
/**
|
|
35
54
|
* Build a promoter that writes one record per turn that learned something.
|
|
36
55
|
*
|
|
@@ -40,4 +59,5 @@ export interface MemoryPromoterOptions {
|
|
|
40
59
|
* reports it.
|
|
41
60
|
*/
|
|
42
61
|
export declare function createMemoryPromoter(options: MemoryPromoterOptions): PromoteMemory;
|
|
62
|
+
export {};
|
|
43
63
|
//# sourceMappingURL=memory-promoter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-promoter.d.ts","sourceRoot":"","sources":["../../src/turn/memory-promoter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAA0B,MAAM,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"memory-promoter.d.ts","sourceRoot":"","sources":["../../src/turn/memory-promoter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAA0B,MAAM,sCAAsC,CAAA;AAEjG;;;;;;;GAOG;AACH,QAAA,MAAM,SAAS,uOAMkE,CAAA;AAEjF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,mBAAwB,CAAA;AAEvD,MAAM,WAAW,qBAAqB;IACrC,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CACjF;AAED,gEAAgE;AAChE,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAqDjE;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,aAAa,CA+ClF"}
|
|
@@ -28,11 +28,13 @@ const KNOWLEDGE = [
|
|
|
28
28
|
*/
|
|
29
29
|
export const SESSION_MEMORY_TAG = SESSION_MEMORY_SOURCE;
|
|
30
30
|
/** Everything the candidate knows, as `[heading, items]`, empties dropped. */
|
|
31
|
-
function knowledge(candidate, cap) {
|
|
31
|
+
function knowledge(candidate, cap, accept) {
|
|
32
32
|
const out = [];
|
|
33
33
|
for (const [key, heading] of KNOWLEDGE) {
|
|
34
34
|
const items = [
|
|
35
|
-
...new Set(candidate[key]
|
|
35
|
+
...new Set(candidate[key]
|
|
36
|
+
.map((item) => item.trim())
|
|
37
|
+
.filter((item) => item !== '' && accept(key, item))),
|
|
36
38
|
];
|
|
37
39
|
if (items.length > 0)
|
|
38
40
|
out.push([heading, items.slice(0, cap)]);
|
|
@@ -73,9 +75,10 @@ export function createMemoryPromoter(options) {
|
|
|
73
75
|
const cap = options.maxPerCategory ?? 20;
|
|
74
76
|
if (!Number.isSafeInteger(cap) || cap < 1)
|
|
75
77
|
throw new Error('maxPerCategory must be a positive integer');
|
|
78
|
+
const accept = options.acceptClaim ?? (() => true);
|
|
76
79
|
const tags = [SESSION_MEMORY_TAG, ...(options.tags ?? [])];
|
|
77
80
|
return async (candidate) => {
|
|
78
|
-
const sections = knowledge(candidate, cap);
|
|
81
|
+
const sections = knowledge(candidate, cap, accept);
|
|
79
82
|
// Nothing learned, nothing written. Not an empty record: a store full
|
|
80
83
|
// of rows describing runs that discovered nothing is a store whose
|
|
81
84
|
// search results are mostly noise, and the model reads that store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-promoter.js","sourceRoot":"","sources":["../../src/turn/memory-promoter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,GACf,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAIjE;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG;IACjB,CAAC,kBAAkB,EAAE,wBAAwB,CAAC;IAC9C,CAAC,WAAW,EAAE,WAAW,CAAC;IAC1B,CAAC,aAAa,EAAE,aAAa,CAAC;IAC9B,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACjC,CAAC,aAAa,EAAE,aAAa,CAAC;CACkD,CAAA;AAEjF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"memory-promoter.js","sourceRoot":"","sources":["../../src/turn/memory-promoter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,GACf,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAIjE;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG;IACjB,CAAC,kBAAkB,EAAE,wBAAwB,CAAC;IAC9C,CAAC,WAAW,EAAE,WAAW,CAAC;IAC1B,CAAC,aAAa,EAAE,aAAa,CAAC;IAC9B,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACjC,CAAC,aAAa,EAAE,aAAa,CAAC;CACkD,CAAA;AAEjF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAiCvD,8EAA8E;AAC9E,SAAS,SAAS,CACjB,SAAiC,EACjC,GAAW,EACX,MAAkE;IAElE,MAAM,GAAG,GAA6C,EAAE,CAAA;IACxD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,SAAS,EAAE,CAAC;QACx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;aAC1B;SACD,CAAC,CAAA;IACH,CAAC,CAAA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/sdk",
|
|
3
|
-
"version": "62.
|
|
3
|
+
"version": "62.2.0",
|
|
4
4
|
"description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"engines": {
|
|
@@ -37,6 +37,25 @@ export interface ConsolidationMeta {
|
|
|
37
37
|
|
|
38
38
|
const MAX_TASK_IN_TITLE = 72
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* A host's screen over what a consolidation may quote. Without one a
|
|
42
|
+
* consolidation carries the task, decisions, discoveries and failures
|
|
43
|
+
* verbatim, which is right for a store the operator reads and wrong for one
|
|
44
|
+
* that is recalled into later prompts unreviewed.
|
|
45
|
+
*/
|
|
46
|
+
export interface ConsolidationScreen {
|
|
47
|
+
/**
|
|
48
|
+
* The task as it may appear in the title and body, or `undefined` to say
|
|
49
|
+
* it is not stated. Absent keeps the task as written.
|
|
50
|
+
*/
|
|
51
|
+
readonly task?: (task: string) => string | undefined
|
|
52
|
+
/** Whether one item may be written down. Absent keeps every item. */
|
|
53
|
+
readonly keep?: (
|
|
54
|
+
category: 'decisions' | 'discoveries' | 'failures' | 'files',
|
|
55
|
+
text: string,
|
|
56
|
+
) => boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
40
59
|
function head(text: string, max: number): string {
|
|
41
60
|
const line = text.split('\n')[0]?.trim() ?? ''
|
|
42
61
|
return line.length <= max ? line : `${line.slice(0, max - 1)}…`
|
|
@@ -72,16 +91,22 @@ export async function isConsolidated(
|
|
|
72
91
|
export function consolidationEntry(
|
|
73
92
|
state: WorkingState,
|
|
74
93
|
meta: ConsolidationMeta,
|
|
94
|
+
screen?: ConsolidationScreen,
|
|
75
95
|
): CreateMemoryParams | null {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
const kept =
|
|
97
|
+
(category: 'decisions' | 'discoveries' | 'failures' | 'files') =>
|
|
98
|
+
(item: string): boolean =>
|
|
99
|
+
item.trim().length > 0 && (screen?.keep?.(category, item) ?? true)
|
|
100
|
+
const decisions = state.decisions.filter(kept('decisions'))
|
|
101
|
+
const discoveries = state.discoveries.filter(kept('discoveries'))
|
|
102
|
+
const failures = state.failures.filter(kept('failures'))
|
|
79
103
|
if (decisions.length + discoveries.length + failures.length === 0) return null
|
|
80
104
|
|
|
81
|
-
const task = state.task.trim()
|
|
105
|
+
const task = (screen?.task ? (screen.task(state.task.trim()) ?? '') : state.task).trim()
|
|
82
106
|
const files = [...state.files.values()]
|
|
83
107
|
.filter((slot) => slot.actions.some((a) => a.type !== 'read'))
|
|
84
108
|
.map((slot) => slot.path)
|
|
109
|
+
.filter(kept('files'))
|
|
85
110
|
const section = (name: string, items: readonly string[]): string[] =>
|
|
86
111
|
items.length === 0 ? [] : [`## ${name}`, '', ...items.map((item) => `- ${item}`), '']
|
|
87
112
|
const content = [
|
package/src/compaction/index.ts
CHANGED
|
@@ -109,4 +109,5 @@ export { DEFAULT_SOFT_TARGET, planSalienceWorkingSet } from './plan.js'
|
|
|
109
109
|
|
|
110
110
|
// Episodic → semantic: what a turn learned, as the entry a later turn searches.
|
|
111
111
|
export { CONSOLIDATION_TAG, consolidationEntry, isConsolidated } from './consolidation.js'
|
|
112
|
+
export type { ConsolidationScreen } from './consolidation.js'
|
|
112
113
|
export type { ConsolidationMeta } from './consolidation.js'
|
package/src/public-runtime.ts
CHANGED
|
@@ -477,7 +477,7 @@ export type {
|
|
|
477
477
|
// the model reads this store, so noise here is context spent on a turn that
|
|
478
478
|
// did nothing.
|
|
479
479
|
export { SESSION_MEMORY_TAG, createMemoryPromoter } from './turn/index.js'
|
|
480
|
-
export type { MemoryPromoterOptions } from './turn/index.js'
|
|
480
|
+
export type { MemoryPromoterOptions, SessionMemoryCategory } from './turn/index.js'
|
|
481
481
|
export { createMemoryRecallStep } from './turn/memory-recall.js'
|
|
482
482
|
export type { MemoryRecallOptions } from './turn/memory-recall.js'
|
|
483
483
|
export {
|
|
@@ -592,6 +592,7 @@ export {
|
|
|
592
592
|
memoryIndexLine,
|
|
593
593
|
memoryLinkNames,
|
|
594
594
|
memoryOrigin,
|
|
595
|
+
findSecretShape,
|
|
595
596
|
renderMemoryIndex,
|
|
596
597
|
slugifyMemoryName,
|
|
597
598
|
} from './store/index.js'
|
|
@@ -1336,6 +1337,7 @@ export {
|
|
|
1336
1337
|
consolidationEntry,
|
|
1337
1338
|
isConsolidated,
|
|
1338
1339
|
} from './compaction/consolidation.js'
|
|
1340
|
+
export type { ConsolidationScreen } from './compaction/consolidation.js'
|
|
1339
1341
|
// The sibling state-bearing system message. A host that carries a turn's
|
|
1340
1342
|
// conversation into a fresh query must distinguish this ledger from the fresh
|
|
1341
1343
|
// identity/environment prompt floor without copying its private header string.
|
package/src/public-types.ts
CHANGED
|
@@ -177,11 +177,15 @@ export async function* finalizeTurn(
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
if (params.consolidateInto && workingStateManager) {
|
|
180
|
-
const entry = consolidationEntry(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
const entry = consolidationEntry(
|
|
181
|
+
workingStateManager.getState(),
|
|
182
|
+
{
|
|
183
|
+
sessionId: ctx.sessionId,
|
|
184
|
+
turnId: ctx.turnId,
|
|
185
|
+
at: Date.now(),
|
|
186
|
+
},
|
|
187
|
+
params.consolidationScreen,
|
|
188
|
+
)
|
|
185
189
|
if (entry) {
|
|
186
190
|
try {
|
|
187
191
|
// Same knowledge, same record: a later turn that learned what an
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '../../advisory/index.js'
|
|
8
8
|
import { AuthorizationGate } from '../../authorization/gate.js'
|
|
9
9
|
import { SkillGrantSet } from '../../authorization/skill-grant.js'
|
|
10
|
+
import type { ConsolidationScreen } from '../../compaction/consolidation.js'
|
|
10
11
|
import { repairToolMessageHistory, toolHistoryRepairChanged } from '../../compaction/dangling.js'
|
|
11
12
|
import { extractFromUserMessage } from '../../compaction/extractor.js'
|
|
12
13
|
import { WorkingStateManager } from '../../compaction/manager.js'
|
|
@@ -963,6 +964,13 @@ export interface QueryParams {
|
|
|
963
964
|
*/
|
|
964
965
|
consolidateInto?: MemoryStore
|
|
965
966
|
|
|
967
|
+
/**
|
|
968
|
+
* What a consolidation may quote. Absent keeps the task, decisions,
|
|
969
|
+
* discoveries and failures verbatim; a host whose store is recalled into
|
|
970
|
+
* later prompts sets it to drop or neutralise what should not persist.
|
|
971
|
+
*/
|
|
972
|
+
consolidationScreen?: ConsolidationScreen
|
|
973
|
+
|
|
966
974
|
/**
|
|
967
975
|
* Optional neutral working-memory seam. When set, the iteration loop
|
|
968
976
|
* re-renders the provider's string into a single pinned leading system
|
package/src/store/index.ts
CHANGED
|
@@ -37,6 +37,8 @@ export {
|
|
|
37
37
|
isMemoryName,
|
|
38
38
|
slugifyMemoryName,
|
|
39
39
|
} from './memory/naming.js'
|
|
40
|
+
export { findSecretShape } from './memory/secrets.js'
|
|
41
|
+
export type { SecretScanOptions, SecretShape } from './memory/secrets.js'
|
|
40
42
|
export type { MemoryContentRejection } from './memory/naming.js'
|
|
41
43
|
export { MemoryRevisionConflictError } from './memory/revision.js'
|
|
42
44
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret shapes: text that looks like a credential and must not be written to
|
|
3
|
+
* a memory. A memory is recalled into later prompts, sent to providers and
|
|
4
|
+
* kept on disk in the clear, so a key saved once is a key leaked many times.
|
|
5
|
+
*
|
|
6
|
+
* The match is on shape only. It names a reason code and never returns the
|
|
7
|
+
* matched text, so a caller can log the code without logging the secret.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type SecretShape =
|
|
11
|
+
| 'private_key'
|
|
12
|
+
| 'provider_token'
|
|
13
|
+
| 'jwt'
|
|
14
|
+
| 'credentialed_url'
|
|
15
|
+
| 'high_entropy'
|
|
16
|
+
|
|
17
|
+
const PATTERNS: readonly (readonly [SecretShape, RegExp])[] = [
|
|
18
|
+
['private_key', /-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/],
|
|
19
|
+
[
|
|
20
|
+
'provider_token',
|
|
21
|
+
new RegExp(
|
|
22
|
+
[
|
|
23
|
+
'\\bsk-(?:ant-|proj-|live-|or-v1-)?[A-Za-z0-9_-]{20,}',
|
|
24
|
+
'\\bgh[pousr]_[A-Za-z0-9]{30,}',
|
|
25
|
+
'\\bgithub_pat_[A-Za-z0-9_]{30,}',
|
|
26
|
+
'\\bglpat-[A-Za-z0-9_-]{16,}',
|
|
27
|
+
'\\bxox[abposr]-[A-Za-z0-9-]{10,}',
|
|
28
|
+
'\\b(?:AKIA|ASIA)[A-Z0-9]{16}\\b',
|
|
29
|
+
'\\bAIza[A-Za-z0-9_-]{35}\\b',
|
|
30
|
+
'\\bnvapi-[A-Za-z0-9_-]{20,}',
|
|
31
|
+
'\\bnpm_[A-Za-z0-9]{30,}',
|
|
32
|
+
'\\b[sr]k_(?:live|test)_[A-Za-z0-9]{16,}',
|
|
33
|
+
'\\bSG\\.[A-Za-z0-9_-]{16,}\\.[A-Za-z0-9_-]{16,}',
|
|
34
|
+
'\\bhf_[A-Za-z0-9]{30,}',
|
|
35
|
+
'\\bBearer\\s+[A-Za-z0-9._~+/-]{24,}=*',
|
|
36
|
+
].join('|'),
|
|
37
|
+
),
|
|
38
|
+
],
|
|
39
|
+
['jwt', /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/],
|
|
40
|
+
['credentialed_url', /\b[a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:[^\s/@]+@[^\s/]+/i],
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
/** Shannon entropy of `text`, in bits per character. */
|
|
44
|
+
function entropy(text: string): number {
|
|
45
|
+
const counts = new Map<string, number>()
|
|
46
|
+
for (const ch of text) counts.set(ch, (counts.get(ch) ?? 0) + 1)
|
|
47
|
+
let bits = 0
|
|
48
|
+
for (const n of counts.values()) {
|
|
49
|
+
const p = n / text.length
|
|
50
|
+
bits -= p * Math.log2(p)
|
|
51
|
+
}
|
|
52
|
+
return bits
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** How many times the token switches between a letter and a digit. */
|
|
56
|
+
function letterDigitSwitches(token: string): number {
|
|
57
|
+
let switches = 0
|
|
58
|
+
let previous: 'letter' | 'digit' | undefined
|
|
59
|
+
for (const ch of token) {
|
|
60
|
+
const kind = /\d/.test(ch) ? 'digit' : /[A-Za-z]/.test(ch) ? 'letter' : undefined
|
|
61
|
+
if (kind === undefined) continue
|
|
62
|
+
if (previous !== undefined && previous !== kind) switches += 1
|
|
63
|
+
previous = kind
|
|
64
|
+
}
|
|
65
|
+
return switches
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Random, not merely long: a long identifier with a trailing number
|
|
70
|
+
* (`DecisionsAbcDefGhi1234567890`) has mixed case and a digit but few
|
|
71
|
+
* letter-digit switches and a low spread, a key has both. A path-like token
|
|
72
|
+
* is a path.
|
|
73
|
+
*/
|
|
74
|
+
function looksRandom(token: string): boolean {
|
|
75
|
+
return (
|
|
76
|
+
!token.includes('/') &&
|
|
77
|
+
/[A-Z]/.test(token) &&
|
|
78
|
+
/[a-z]/.test(token) &&
|
|
79
|
+
letterDigitSwitches(token) >= 4 &&
|
|
80
|
+
entropy(token) >= 4.5
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface SecretScanOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Also flag a long unbroken run of mixed-case letters and digits that looks
|
|
87
|
+
* random. Off by default: it can flag an identifier a person meant to keep,
|
|
88
|
+
* which is right for text nobody chose and wrong for text somebody did.
|
|
89
|
+
*/
|
|
90
|
+
readonly entropy?: boolean
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The first secret shape `text` has, or `undefined`. */
|
|
94
|
+
export function findSecretShape(
|
|
95
|
+
text: string,
|
|
96
|
+
options: SecretScanOptions = {},
|
|
97
|
+
): SecretShape | undefined {
|
|
98
|
+
for (const [shape, pattern] of PATTERNS) if (pattern.test(text)) return shape
|
|
99
|
+
if (options.entropy === true) {
|
|
100
|
+
for (const token of text.match(/[A-Za-z0-9+/_=-]{32,}/g) ?? []) {
|
|
101
|
+
if (looksRandom(token)) return 'high_entropy'
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return undefined
|
|
105
|
+
}
|
package/src/tools/memory/save.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { MemoryStore } from '../../types/memory/index.js'
|
|
|
5
5
|
import type { ToolDefinition } from '../../types/tool/index.js'
|
|
6
6
|
import { defineTool } from '../defineTool.js'
|
|
7
7
|
import { memoryFieldsSchema } from './fields.js'
|
|
8
|
+
import { refuseSecret } from './secret-guard.js'
|
|
8
9
|
|
|
9
10
|
export function buildSaveMemoryTool(store: MemoryStore): ToolDefinition {
|
|
10
11
|
return defineTool({
|
|
@@ -13,6 +14,7 @@ export function buildSaveMemoryTool(store: MemoryStore): ToolDefinition {
|
|
|
13
14
|
'Save one memory for later sessions in this project: a single fact that the code, the history and the docs do not already hold.',
|
|
14
15
|
'Choose a type: user (who the person is and how they like to work), feedback (a rule they gave about how to work), project (a fact or decision about the work), reference (where to look for something).',
|
|
15
16
|
'For feedback and project memories, write the rule or fact first, then a line starting "Why:" and a line starting "How to apply:".',
|
|
17
|
+
'Never save a secret: an API key, token, password, private key or a URL with credentials in it is refused.',
|
|
16
18
|
'Link a related memory by writing [[its-name]] in the content.',
|
|
17
19
|
'The name must be new: a name another memory holds is refused, and the reply points to update_memory.',
|
|
18
20
|
"Returns the saved memory's id and name.",
|
|
@@ -30,6 +32,8 @@ export function buildSaveMemoryTool(store: MemoryStore): ToolDefinition {
|
|
|
30
32
|
destructive: false,
|
|
31
33
|
concurrencySafe: true,
|
|
32
34
|
async execute({ title, summary, content, tags, name, description, type }, context) {
|
|
35
|
+
const refused = refuseSecret([title, summary, content, description, ...(tags ?? [])])
|
|
36
|
+
if (refused) return refused
|
|
33
37
|
try {
|
|
34
38
|
const { entry } = await store.create({
|
|
35
39
|
title,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { findSecretShape } from '../../store/memory/secrets.js'
|
|
2
|
+
import type { ToolResult } from '../../types/tool/index.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A refusal when any field a model is saving holds a secret, else `undefined`.
|
|
6
|
+
* The reply names the shape, never the text, so the refusal does not repeat
|
|
7
|
+
* the secret into the transcript.
|
|
8
|
+
*/
|
|
9
|
+
export function refuseSecret(fields: readonly (string | undefined)[]): ToolResult | undefined {
|
|
10
|
+
for (const field of fields) {
|
|
11
|
+
if (field === undefined) continue
|
|
12
|
+
const shape = findSecretShape(field)
|
|
13
|
+
if (shape === undefined) continue
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
output:
|
|
17
|
+
'The memory looks like it contains a secret (an API key, token, password, private key or a URL with credentials). Memories are recalled into later prompts and kept on disk in the clear, so it was not saved. Save where the secret lives (the variable or file name) instead of its value.',
|
|
18
|
+
error: 'Memory content rejected',
|
|
19
|
+
data: { reason: 'secret', shape },
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { ToolDefinition } from '../../types/tool/index.js'
|
|
|
7
7
|
import { defineTool } from '../defineTool.js'
|
|
8
8
|
import { memoryFieldsSchema } from './fields.js'
|
|
9
9
|
import { resolveMemoryReference } from './resolve.js'
|
|
10
|
+
import { refuseSecret } from './secret-guard.js'
|
|
10
11
|
|
|
11
12
|
export function buildUpdateMemoryTool(store: MemoryStore): ToolDefinition {
|
|
12
13
|
return defineTool({
|
|
@@ -52,6 +53,14 @@ export function buildUpdateMemoryTool(store: MemoryStore): ToolDefinition {
|
|
|
52
53
|
error: 'Conditional memory update unavailable',
|
|
53
54
|
}
|
|
54
55
|
}
|
|
56
|
+
const refused = refuseSecret([
|
|
57
|
+
updates.title,
|
|
58
|
+
updates.summary,
|
|
59
|
+
updates.content,
|
|
60
|
+
updates.description,
|
|
61
|
+
...(updates.tags ?? []),
|
|
62
|
+
])
|
|
63
|
+
if (refused) return refused
|
|
55
64
|
const reference = await resolveMemoryReference(store, id)
|
|
56
65
|
if (!reference.found) {
|
|
57
66
|
return {
|
package/src/turn/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ export { checkLimitsDetailed, buildLimitConfig } from './LimitChecker.js'
|
|
|
22
22
|
export type { LimitCheckerState, LimitCheckResult } from './LimitChecker.js'
|
|
23
23
|
|
|
24
24
|
export { SESSION_MEMORY_TAG, createMemoryPromoter } from './memory-promoter.js'
|
|
25
|
-
export type { MemoryPromoterOptions } from './memory-promoter.js'
|
|
25
|
+
export type { MemoryPromoterOptions, SessionMemoryCategory } from './memory-promoter.js'
|
|
26
26
|
export { createMemoryRecallStep } from './memory-recall.js'
|
|
27
27
|
export type { MemoryRecallOptions } from './memory-recall.js'
|
|
28
28
|
export { createJsonClaimVerifier } from './json-claim-verifier.js'
|
|
@@ -55,17 +55,33 @@ export interface MemoryPromoterOptions {
|
|
|
55
55
|
* that costs context every time it is retrieved.
|
|
56
56
|
*/
|
|
57
57
|
readonly maxPerCategory?: number
|
|
58
|
+
/**
|
|
59
|
+
* Decide whether one extracted claim may become part of a record. Called
|
|
60
|
+
* with the candidate's category (`userRequirements`, `decisions`,
|
|
61
|
+
* `discoveries`, `failures` or `environment`) and the claim text. A claim
|
|
62
|
+
* it rejects is left out; a record with no claim left is not written.
|
|
63
|
+
* Defaults to keeping every claim.
|
|
64
|
+
*/
|
|
65
|
+
readonly acceptClaim?: (category: SessionMemoryCategory, text: string) => boolean
|
|
58
66
|
}
|
|
59
67
|
|
|
68
|
+
/** The claim categories of a {@link SessionMemoryCandidate}. */
|
|
69
|
+
export type SessionMemoryCategory = (typeof KNOWLEDGE)[number][0]
|
|
70
|
+
|
|
60
71
|
/** Everything the candidate knows, as `[heading, items]`, empties dropped. */
|
|
61
72
|
function knowledge(
|
|
62
73
|
candidate: SessionMemoryCandidate,
|
|
63
74
|
cap: number,
|
|
75
|
+
accept: (category: SessionMemoryCategory, text: string) => boolean,
|
|
64
76
|
): readonly (readonly [string, readonly string[]])[] {
|
|
65
77
|
const out: (readonly [string, readonly string[]])[] = []
|
|
66
78
|
for (const [key, heading] of KNOWLEDGE) {
|
|
67
79
|
const items = [
|
|
68
|
-
...new Set(
|
|
80
|
+
...new Set(
|
|
81
|
+
(candidate[key] as readonly string[])
|
|
82
|
+
.map((item) => item.trim())
|
|
83
|
+
.filter((item) => item !== '' && accept(key, item)),
|
|
84
|
+
),
|
|
69
85
|
]
|
|
70
86
|
if (items.length > 0) out.push([heading, items.slice(0, cap)])
|
|
71
87
|
}
|
|
@@ -115,10 +131,11 @@ export function createMemoryPromoter(options: MemoryPromoterOptions): PromoteMem
|
|
|
115
131
|
const cap = options.maxPerCategory ?? 20
|
|
116
132
|
if (!Number.isSafeInteger(cap) || cap < 1)
|
|
117
133
|
throw new Error('maxPerCategory must be a positive integer')
|
|
134
|
+
const accept = options.acceptClaim ?? (() => true)
|
|
118
135
|
const tags = [SESSION_MEMORY_TAG, ...(options.tags ?? [])]
|
|
119
136
|
|
|
120
137
|
return async (candidate: SessionMemoryCandidate): Promise<void> => {
|
|
121
|
-
const sections = knowledge(candidate, cap)
|
|
138
|
+
const sections = knowledge(candidate, cap, accept)
|
|
122
139
|
// Nothing learned, nothing written. Not an empty record: a store full
|
|
123
140
|
// of rows describing runs that discovered nothing is a store whose
|
|
124
141
|
// search results are mostly noise, and the model reads that store.
|