fluffy-context 0.7.6 → 0.8.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/README.md +115 -36
- package/dist/src/agent/api.d.ts +49 -4
- package/dist/src/agent/api.js +183 -131
- package/dist/src/agent/index.d.ts +7 -1
- package/dist/src/agent/index.js +1 -0
- package/dist/src/cli/main.js +301 -15
- package/dist/src/cognition/evidence-graph.d.ts +4 -0
- package/dist/src/cognition/evidence-graph.js +187 -0
- package/dist/src/cognition/evolution.d.ts +36 -0
- package/dist/src/cognition/evolution.js +221 -0
- package/dist/src/cognition/journal.js +143 -2
- package/dist/src/cognition/projections.js +124 -2
- package/dist/src/cognition/recipes.d.ts +25 -0
- package/dist/src/cognition/recipes.js +149 -0
- package/dist/src/cognition/skills.d.ts +45 -0
- package/dist/src/cognition/skills.js +184 -0
- package/dist/src/cognition/types.d.ts +196 -2
- package/dist/src/cognition/usage-report.d.ts +40 -0
- package/dist/src/cognition/usage-report.js +232 -0
- package/dist/src/cognition/usage.d.ts +5 -0
- package/dist/src/cognition/usage.js +48 -0
- package/dist/src/compiler/compile.js +73 -4
- package/dist/src/compiler/graph.d.ts +7 -0
- package/dist/src/compiler/graph.js +117 -0
- package/dist/src/compiler/identity.d.ts +1 -1
- package/dist/src/compiler/identity.js +3 -1
- package/dist/src/compiler/sources.d.ts +3 -1
- package/dist/src/compiler/sources.js +11 -2
- package/dist/src/compiler/types.d.ts +23 -2
- package/dist/src/mcp/server.js +228 -6
- package/dist/src/storage/layout.d.ts +5 -0
- package/dist/src/storage/layout.js +15 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
- package/skills/fluffy-context/SKILL.md +53 -5
package/dist/src/agent/api.js
CHANGED
|
@@ -4,11 +4,17 @@ import { contextsRoot, contextMetadataPath } from '../storage/layout.js';
|
|
|
4
4
|
import { isRecord, readJson } from '../storage/json-store.js';
|
|
5
5
|
import { checkpoint, rebuildSnapshot, resume, resumeSnapshot } from '../runtime/runtime.js';
|
|
6
6
|
import { recordUse } from '../cognition/feedback.js';
|
|
7
|
+
import { inspectRecipe, listRecipes, materializeRecipe, transitionRecipe } from '../cognition/recipes.js';
|
|
8
|
+
import { inspectSkill, listSkills, materializeSkill, recordSkillInvocation, recordSkillOutcome, transitionSkill } from '../cognition/skills.js';
|
|
9
|
+
import { acceptEvolutionCandidate, inspectEvolutionProposal, listEvolutionProposals, proposeEvolution, transitionEvolutionProposal } from '../cognition/evolution.js';
|
|
7
10
|
import { selectV2Orientation } from '../cognition/orient.js';
|
|
8
11
|
import { discoverV2Deadends, discoverV2Knowledge } from '../cognition/retrieval.js';
|
|
9
12
|
import { discoverDeadends, discoverKnowledge, listDeadends } from '../runtime/knowledge.js';
|
|
10
13
|
import { listNotes } from '../runtime/notes.js';
|
|
11
14
|
import { expandContext } from '../compiler/expand.js';
|
|
15
|
+
import { compileContext } from '../compiler/compile.js';
|
|
16
|
+
import { withUsageTelemetry } from '../cognition/usage.js';
|
|
17
|
+
import { buildUsageReport } from '../cognition/usage-report.js';
|
|
12
18
|
function normalized(value) {
|
|
13
19
|
return value.trim().toLocaleLowerCase();
|
|
14
20
|
}
|
|
@@ -139,155 +145,201 @@ export async function saveContext(startPath, input, options = {}) {
|
|
|
139
145
|
const projectRoot = await resolveProjectRoot(startPath);
|
|
140
146
|
return { projectRoot, result: await checkpoint(projectRoot, input, options) };
|
|
141
147
|
}
|
|
142
|
-
export async function contextExpand(startPath, input) {
|
|
143
|
-
|
|
144
|
-
return expandContext(projectRoot, input);
|
|
148
|
+
export async function contextExpand(startPath, input, interfaceName = 'agent') {
|
|
149
|
+
return withUsageTelemetry(startPath, 'expand', 'agent', input, () => resolveProjectRoot(startPath).then((projectRoot) => expandContext(projectRoot, input)), interfaceName);
|
|
145
150
|
}
|
|
146
|
-
export async function
|
|
147
|
-
|
|
148
|
-
const result = await resume(projectRoot, options.contextId, options.maxChars ?? 4000);
|
|
149
|
-
const knowledge = options.query === undefined ? null : await discoverKnowledge(projectRoot, options.query, { scope: options.scope, maxChars: options.maxChars ?? 4000 });
|
|
150
|
-
const verifiedDeadends = await listDeadends(projectRoot);
|
|
151
|
-
return {
|
|
152
|
-
projectRoot,
|
|
153
|
-
context: result.context,
|
|
154
|
-
snapshot: result.snapshot,
|
|
155
|
-
resumeSummary: result.resumeSummary,
|
|
156
|
-
...(options.includeDetails ? { details: result.details } : {}),
|
|
157
|
-
knowledge,
|
|
158
|
-
verifiedDeadendIds: verifiedDeadends.map((item) => item.deadendId),
|
|
159
|
-
};
|
|
151
|
+
export async function contextCompile(startPath, options = {}, interfaceName = 'agent') {
|
|
152
|
+
return withUsageTelemetry(startPath, 'compile', 'agent', options, () => compileContext(startPath, options), interfaceName);
|
|
160
153
|
}
|
|
161
|
-
export async function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
truncation: { summary: false, knowledge: false, deadends: false, notes: false },
|
|
191
|
-
},
|
|
192
|
-
};
|
|
154
|
+
export async function loadContext(startPath, options = {}, interfaceName = 'agent') {
|
|
155
|
+
return withUsageTelemetry(startPath, 'resume', 'agent', options, async () => {
|
|
156
|
+
const projectRoot = await resolveProjectRoot(startPath);
|
|
157
|
+
const result = await resume(projectRoot, options.contextId, options.maxChars ?? 4000);
|
|
158
|
+
const knowledge = options.query === undefined ? null : await discoverKnowledge(projectRoot, options.query, { scope: options.scope, maxChars: options.maxChars ?? 4000 });
|
|
159
|
+
const verifiedDeadends = await listDeadends(projectRoot);
|
|
160
|
+
return {
|
|
161
|
+
projectRoot,
|
|
162
|
+
context: result.context,
|
|
163
|
+
snapshot: result.snapshot,
|
|
164
|
+
resumeSummary: result.resumeSummary,
|
|
165
|
+
...(options.includeDetails ? { details: result.details } : {}),
|
|
166
|
+
knowledge,
|
|
167
|
+
verifiedDeadendIds: verifiedDeadends.map((item) => item.deadendId),
|
|
168
|
+
};
|
|
169
|
+
}, interfaceName);
|
|
170
|
+
}
|
|
171
|
+
export async function contextOrient(startPath, options = {}, interfaceName = 'agent') {
|
|
172
|
+
const action = async () => {
|
|
173
|
+
const projectRoot = await resolveProjectRoot(startPath);
|
|
174
|
+
const query = options.query === undefined ? null : options.query.trim();
|
|
175
|
+
if (query === '')
|
|
176
|
+
throw new Error('context orient query must not be empty');
|
|
177
|
+
let loaded;
|
|
178
|
+
try {
|
|
179
|
+
const v2 = await selectV2Orientation(projectRoot, options.contextId);
|
|
180
|
+
loaded = v2
|
|
181
|
+
? await resumeSnapshot(projectRoot, v2.contextId, v2.snapshotId, options.maxChars ?? 4000)
|
|
182
|
+
: await resume(projectRoot, options.contextId, options.maxChars ?? 4000, { touchLastUsedAt: false });
|
|
193
183
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof Error && error.message === 'no active context found') {
|
|
186
|
+
return {
|
|
187
|
+
status: 'no_context',
|
|
188
|
+
projectRoot,
|
|
189
|
+
query,
|
|
190
|
+
context: null,
|
|
191
|
+
snapshot: null,
|
|
192
|
+
resumeSummary: null,
|
|
193
|
+
knowledge: emptyKnowledge(query ?? ''),
|
|
194
|
+
deadends: emptyDeadends(query ?? ''),
|
|
195
|
+
notes: [],
|
|
196
|
+
truncated: false,
|
|
197
|
+
explanation: {
|
|
198
|
+
mode: 'v1-fallback',
|
|
199
|
+
selection: 'v1',
|
|
200
|
+
retrieval: { knowledge: {}, deadends: {} },
|
|
201
|
+
truncation: { summary: false, knowledge: false, deadends: false, notes: false },
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
const v2 = await selectV2Orientation(projectRoot, options.contextId);
|
|
208
|
+
const notes = (await listNotes(projectRoot, {
|
|
209
|
+
contextId: loaded.context.id,
|
|
210
|
+
openOnly: true,
|
|
211
|
+
limit: v2 ? Number.MAX_SAFE_INTEGER : options.noteLimit ?? 20,
|
|
212
|
+
maxChars: options.maxChars ?? 4000,
|
|
213
|
+
})).filter((note) => !v2 || v2.noteIds.has(note.noteId)).slice(0, options.noteLimit ?? 20);
|
|
214
|
+
const v2Knowledge = query === null || !v2 ? null : discoverV2Knowledge(v2.retrieval, query, v2.currentGit, {
|
|
216
215
|
scope: options.scope,
|
|
217
216
|
limit: options.knowledgeLimit ?? 10,
|
|
218
217
|
maxChars: options.maxChars ?? 4000,
|
|
219
218
|
});
|
|
220
|
-
|
|
221
|
-
? emptyDeadends('')
|
|
222
|
-
: v2Deadends?.result ?? await discoverDeadends(projectRoot, query, {
|
|
219
|
+
const v2Deadends = query === null || !v2 ? null : discoverV2Deadends(v2.retrieval, query, v2.currentGit, {
|
|
223
220
|
scope: options.scope,
|
|
224
221
|
limit: options.deadendLimit ?? 10,
|
|
225
222
|
maxChars: options.maxChars ?? 4000,
|
|
226
223
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
mode: v2 ? 'v2' : 'v1-fallback',
|
|
274
|
-
selection: v2?.selection ?? 'v1',
|
|
275
|
-
retrieval: {
|
|
276
|
-
knowledge: v2Knowledge?.exclusions ?? {},
|
|
277
|
-
deadends: v2Deadends?.exclusions ?? {},
|
|
224
|
+
const applicableKnowledge = query === null
|
|
225
|
+
? emptyKnowledge('')
|
|
226
|
+
: v2Knowledge?.result ?? await discoverKnowledge(projectRoot, query, {
|
|
227
|
+
scope: options.scope,
|
|
228
|
+
limit: options.knowledgeLimit ?? 10,
|
|
229
|
+
maxChars: options.maxChars ?? 4000,
|
|
230
|
+
});
|
|
231
|
+
const applicableDeadends = query === null
|
|
232
|
+
? emptyDeadends('')
|
|
233
|
+
: v2Deadends?.result ?? await discoverDeadends(projectRoot, query, {
|
|
234
|
+
scope: options.scope,
|
|
235
|
+
limit: options.deadendLimit ?? 10,
|
|
236
|
+
maxChars: options.maxChars ?? 4000,
|
|
237
|
+
});
|
|
238
|
+
const budget = { remaining: Math.max(0, options.maxChars ?? 4000) };
|
|
239
|
+
const resumeSummary = {
|
|
240
|
+
progressSummary: limited(loaded.resumeSummary.progressSummary, budget),
|
|
241
|
+
lastError: loaded.resumeSummary.lastError === null ? null : limited(loaded.resumeSummary.lastError, budget),
|
|
242
|
+
completed: limitedList(loaded.resumeSummary.completed, budget),
|
|
243
|
+
pendingTasks: limitedList(loaded.resumeSummary.pendingTasks, budget),
|
|
244
|
+
decisions: limitedList(loaded.resumeSummary.decisions, budget),
|
|
245
|
+
risks: limitedList(loaded.resumeSummary.risks, budget),
|
|
246
|
+
relatedFiles: limitedList(loaded.resumeSummary.relatedFiles, budget),
|
|
247
|
+
branchOrCommitDrift: loaded.resumeSummary.branchOrCommitDrift,
|
|
248
|
+
};
|
|
249
|
+
const resumeTruncated = textLength(resumeSummary.progressSummary) < textLength(loaded.resumeSummary.progressSummary)
|
|
250
|
+
|| textLength(resumeSummary.lastError) < textLength(loaded.resumeSummary.lastError)
|
|
251
|
+
|| textLength(resumeSummary.completed) < textLength(loaded.resumeSummary.completed)
|
|
252
|
+
|| textLength(resumeSummary.pendingTasks) < textLength(loaded.resumeSummary.pendingTasks)
|
|
253
|
+
|| textLength(resumeSummary.decisions) < textLength(loaded.resumeSummary.decisions)
|
|
254
|
+
|| textLength(resumeSummary.risks) < textLength(loaded.resumeSummary.risks)
|
|
255
|
+
|| textLength(resumeSummary.relatedFiles) < textLength(loaded.resumeSummary.relatedFiles);
|
|
256
|
+
const limitedKnowledgeResult = limitKnowledge(applicableKnowledge, budget);
|
|
257
|
+
const limitedDeadendResult = limitDeadends(applicableDeadends, budget);
|
|
258
|
+
const limitedNotesResult = limitNotes(notes, budget);
|
|
259
|
+
return {
|
|
260
|
+
status: 'ready',
|
|
261
|
+
projectRoot,
|
|
262
|
+
query,
|
|
263
|
+
context: {
|
|
264
|
+
id: loaded.context.id,
|
|
265
|
+
title: loaded.context.title,
|
|
266
|
+
status: loaded.context.status,
|
|
267
|
+
branch: loaded.context.branch,
|
|
268
|
+
commit: loaded.context.commit,
|
|
269
|
+
updatedAt: loaded.context.updatedAt,
|
|
278
270
|
},
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
271
|
+
snapshot: {
|
|
272
|
+
snapshotId: loaded.snapshot.snapshotId,
|
|
273
|
+
mode: loaded.snapshot.mode,
|
|
274
|
+
createdAt: loaded.snapshot.createdAt,
|
|
275
|
+
branch: loaded.snapshot.branch,
|
|
276
|
+
commit: loaded.snapshot.commit,
|
|
284
277
|
},
|
|
285
|
-
|
|
278
|
+
resumeSummary,
|
|
279
|
+
knowledge: limitedKnowledgeResult.result,
|
|
280
|
+
deadends: limitedDeadendResult.result,
|
|
281
|
+
notes: limitedNotesResult.notes,
|
|
282
|
+
truncated: resumeTruncated || limitedKnowledgeResult.truncated || limitedDeadendResult.truncated || limitedNotesResult.truncated,
|
|
283
|
+
explanation: {
|
|
284
|
+
mode: v2 ? 'v2' : 'v1-fallback',
|
|
285
|
+
selection: v2?.selection ?? 'v1',
|
|
286
|
+
retrieval: {
|
|
287
|
+
knowledge: v2Knowledge?.exclusions ?? {},
|
|
288
|
+
deadends: v2Deadends?.exclusions ?? {},
|
|
289
|
+
},
|
|
290
|
+
truncation: {
|
|
291
|
+
summary: resumeTruncated,
|
|
292
|
+
knowledge: limitedKnowledgeResult.truncated,
|
|
293
|
+
deadends: limitedDeadendResult.truncated,
|
|
294
|
+
notes: limitedNotesResult.truncated,
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
};
|
|
286
298
|
};
|
|
299
|
+
return interfaceName === null
|
|
300
|
+
? action()
|
|
301
|
+
: withUsageTelemetry(startPath, 'orient', 'agent', options, action, interfaceName);
|
|
302
|
+
}
|
|
303
|
+
export async function contextUsageReport(startPath, options = {}) {
|
|
304
|
+
return buildUsageReport(startPath, options);
|
|
287
305
|
}
|
|
288
306
|
export async function recordContextUse(startPath, input) {
|
|
289
307
|
return recordUse(startPath, input);
|
|
290
308
|
}
|
|
309
|
+
export { inspectRecipe, inspectSkill, listRecipes, listSkills };
|
|
310
|
+
export async function proposeContextEvolution(startPath, input = {}) {
|
|
311
|
+
return proposeEvolution(startPath, input);
|
|
312
|
+
}
|
|
313
|
+
export async function listContextEvolutionProposals(startPath) {
|
|
314
|
+
return listEvolutionProposals(startPath);
|
|
315
|
+
}
|
|
316
|
+
export async function inspectContextEvolutionProposal(startPath, proposalId) {
|
|
317
|
+
return inspectEvolutionProposal(startPath, proposalId);
|
|
318
|
+
}
|
|
319
|
+
export async function acceptContextEvolutionCandidate(startPath, input) {
|
|
320
|
+
return acceptEvolutionCandidate(startPath, input);
|
|
321
|
+
}
|
|
322
|
+
export async function transitionContextEvolutionProposal(startPath, input) {
|
|
323
|
+
return transitionEvolutionProposal(startPath, input);
|
|
324
|
+
}
|
|
325
|
+
export async function materializeContextRecipe(startPath, input) {
|
|
326
|
+
return materializeRecipe(startPath, input);
|
|
327
|
+
}
|
|
328
|
+
export async function transitionContextRecipe(startPath, input) {
|
|
329
|
+
return transitionRecipe(startPath, input);
|
|
330
|
+
}
|
|
331
|
+
export async function materializeContextSkill(startPath, input) {
|
|
332
|
+
return materializeSkill(startPath, input);
|
|
333
|
+
}
|
|
334
|
+
export async function transitionContextSkill(startPath, input) {
|
|
335
|
+
return transitionSkill(startPath, input);
|
|
336
|
+
}
|
|
337
|
+
export async function recordContextSkillInvocation(startPath, input) {
|
|
338
|
+
return recordSkillInvocation(startPath, input);
|
|
339
|
+
}
|
|
340
|
+
export async function recordContextSkillOutcome(startPath, input) {
|
|
341
|
+
return recordSkillOutcome(startPath, input);
|
|
342
|
+
}
|
|
291
343
|
export async function searchContext(startPath, query, options = {}) {
|
|
292
344
|
const projectRoot = await resolveProjectRoot(startPath);
|
|
293
345
|
const cleanQuery = query.trim();
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export * from './api.js';
|
|
2
|
+
export type { MaterializeRecipeInput, TransitionRecipeInput, } from '../cognition/recipes.js';
|
|
3
|
+
export type { MaterializeSkillInput, RecordSkillInvocationInput, RecordSkillOutcomeInput, TransitionSkillInput, } from '../cognition/skills.js';
|
|
4
|
+
export type { AcceptEvolutionCandidateInput, ProposeEvolutionInput, ProposeEvolutionResult, TransitionEvolutionProposalInput, } from '../cognition/evolution.js';
|
|
5
|
+
export type { EvolutionCandidateArtifact, EvolutionLineageReference, EvolutionProposal, EvolutionProposalState, Experience, } from '../cognition/types.js';
|
|
2
6
|
export type { ContextOrientContext, ContextUseInput, ContextOrientExplanation, ContextOrientNoContextResult, ContextOrientOptions, ContextOrientReadyResult, ContextOrientResult, ContextOrientSnapshot, } from './types.js';
|
|
3
7
|
export type { AgentLoadOptions, AgentLoadResult, AgentSaveResult, ContextSearchHit, ContextSearchOptions, ContextSearchResult, } from '../runtime/types.js';
|
|
8
|
+
export { contextCompile } from './api.js';
|
|
4
9
|
export { compileContext } from '../compiler/compile.js';
|
|
5
10
|
export { canonicalJson, contentHash, estimateTokens, rebuildManifestHash, validateManifestIdentity } from '../compiler/identity.js';
|
|
6
|
-
export type { ContextActivityRecord, ContextAnchor, ContextBudget, ContextBudgetReport, ContextCandidate, ContextCandidateSection, ContextCompileOptions, ContextExpandInput, ContextExpandLevel, ContextExpandResult, ContextExclusion, ContextExclusionReason, ContextIntent, ContextIntentSignal, ContextLevel, ContextManifest, ContextProvenance, ContextScenario, ContextSourceDescriptor, ContextTruncation, } from '../compiler/types.js';
|
|
11
|
+
export type { ContextActivityRecord, ContextAnchor, ContextBudget, ContextBudgetReport, ContextCandidate, ContextCandidateSection, ContextCompileOptions, ContextRecipeParticipation, ContextExpandInput, ContextExpandLevel, ContextExpandResult, ContextExclusion, ContextExclusionReason, ContextIntent, ContextIntentSignal, ContextLevel, ContextManifest, ContextProvenance, ContextScenario, ContextSourceDescriptor, ContextTruncation, } from '../compiler/types.js';
|
|
12
|
+
export type { CompilerRecipe, CompilerRecipeState } from '../cognition/types.js';
|
package/dist/src/agent/index.js
CHANGED