rivet-design 0.9.1 → 0.9.3
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/mcp/agent-variants/SessionStore.d.ts +63 -2
- package/dist/mcp/agent-variants/SessionStore.d.ts.map +1 -1
- package/dist/mcp/agent-variants/SessionStore.js +331 -71
- package/dist/mcp/agent-variants/SessionStore.js.map +1 -1
- package/dist/mcp/agent-variants/WorktreeOrchestrator.d.ts +197 -8
- package/dist/mcp/agent-variants/WorktreeOrchestrator.d.ts.map +1 -1
- package/dist/mcp/agent-variants/WorktreeOrchestrator.js +805 -46
- package/dist/mcp/agent-variants/WorktreeOrchestrator.js.map +1 -1
- package/dist/mcp/agent-variants/contracts.d.ts +1101 -9
- package/dist/mcp/agent-variants/contracts.d.ts.map +1 -1
- package/dist/mcp/agent-variants/contracts.js +131 -5
- package/dist/mcp/agent-variants/contracts.js.map +1 -1
- package/dist/mcp/agent-variants/createZeroToOneTool.d.ts +205 -0
- package/dist/mcp/agent-variants/createZeroToOneTool.d.ts.map +1 -0
- package/dist/mcp/agent-variants/createZeroToOneTool.js +295 -0
- package/dist/mcp/agent-variants/createZeroToOneTool.js.map +1 -0
- package/dist/mcp/agent-variants/designContextStore.d.ts +160 -0
- package/dist/mcp/agent-variants/designContextStore.d.ts.map +1 -0
- package/dist/mcp/agent-variants/designContextStore.js +295 -0
- package/dist/mcp/agent-variants/designContextStore.js.map +1 -0
- package/dist/mcp/agent-variants/elementRefToTarget.d.ts +21 -0
- package/dist/mcp/agent-variants/elementRefToTarget.d.ts.map +1 -0
- package/dist/mcp/agent-variants/elementRefToTarget.js +47 -0
- package/dist/mcp/agent-variants/elementRefToTarget.js.map +1 -0
- package/dist/mcp/agent-variants/errors.d.ts +1 -1
- package/dist/mcp/agent-variants/errors.d.ts.map +1 -1
- package/dist/mcp/agent-variants/errors.js +6 -0
- package/dist/mcp/agent-variants/errors.js.map +1 -1
- package/dist/mcp/agent-variants/index.d.ts +4 -1
- package/dist/mcp/agent-variants/index.d.ts.map +1 -1
- package/dist/mcp/agent-variants/index.js +7 -1
- package/dist/mcp/agent-variants/index.js.map +1 -1
- package/dist/mcp/agent-variants/inspirationDesignContext.d.ts +430 -0
- package/dist/mcp/agent-variants/inspirationDesignContext.d.ts.map +1 -0
- package/dist/mcp/agent-variants/inspirationDesignContext.js +2379 -0
- package/dist/mcp/agent-variants/inspirationDesignContext.js.map +1 -0
- package/dist/mcp/agent-variants/pendingChangesAdapter.d.ts.map +1 -1
- package/dist/mcp/agent-variants/pendingChangesAdapter.js +10 -7
- package/dist/mcp/agent-variants/pendingChangesAdapter.js.map +1 -1
- package/dist/mcp/agent-variants/sourceContext.d.ts +7 -0
- package/dist/mcp/agent-variants/sourceContext.d.ts.map +1 -0
- package/dist/mcp/agent-variants/sourceContext.js +158 -0
- package/dist/mcp/agent-variants/sourceContext.js.map +1 -0
- package/dist/mcp/agent-variants/tools.d.ts +14 -0
- package/dist/mcp/agent-variants/tools.d.ts.map +1 -1
- package/dist/mcp/agent-variants/tools.js +330 -15
- package/dist/mcp/agent-variants/tools.js.map +1 -1
- package/dist/mcp/changeBatchClassification.d.ts +30 -0
- package/dist/mcp/changeBatchClassification.d.ts.map +1 -0
- package/dist/mcp/changeBatchClassification.js +65 -0
- package/dist/mcp/changeBatchClassification.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +237 -39
- package/dist/mcp/server.js.map +1 -1
- package/dist/proxy-middleware/proxy-config.d.ts.map +1 -1
- package/dist/proxy-middleware/proxy-config.js +1 -15
- package/dist/proxy-middleware/proxy-config.js.map +1 -1
- package/dist/routes/agentVariants.d.ts +3 -1
- package/dist/routes/agentVariants.d.ts.map +1 -1
- package/dist/routes/agentVariants.js +131 -13
- package/dist/routes/agentVariants.js.map +1 -1
- package/dist/routes/mcp.d.ts +7 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +139 -16
- package/dist/routes/mcp.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/services/SessionBridgeService.d.ts +22 -0
- package/dist/services/SessionBridgeService.d.ts.map +1 -1
- package/dist/services/SessionBridgeService.js +61 -0
- package/dist/services/SessionBridgeService.js.map +1 -1
- package/dist/services/TelemetryService.d.ts +121 -0
- package/dist/services/TelemetryService.d.ts.map +1 -1
- package/dist/services/TelemetryService.js +155 -0
- package/dist/services/TelemetryService.js.map +1 -1
- package/dist/services/WorktreeManager.d.ts +57 -5
- package/dist/services/WorktreeManager.d.ts.map +1 -1
- package/dist/services/WorktreeManager.js +205 -13
- package/dist/services/WorktreeManager.js.map +1 -1
- package/dist/services/templates/designCatalog.d.ts +27 -0
- package/dist/services/templates/designCatalog.d.ts.map +1 -0
- package/dist/services/templates/designCatalog.js +141 -0
- package/dist/services/templates/designCatalog.js.map +1 -0
- package/dist/services/templates/designmd/airbnb.md +545 -0
- package/dist/services/templates/designmd/airtable.md +554 -0
- package/dist/services/templates/designmd/apple.md +562 -0
- package/dist/services/templates/designmd/binance.md +634 -0
- package/dist/services/templates/designmd/bmw-m.md +503 -0
- package/dist/services/templates/designmd/bmw.md +544 -0
- package/dist/services/templates/designmd/bugatti.md +454 -0
- package/dist/services/templates/designmd/cal.md +542 -0
- package/dist/services/templates/designmd/claude.md +589 -0
- package/dist/services/templates/designmd/clay.md +541 -0
- package/dist/services/templates/designmd/cohere.md +451 -0
- package/dist/services/templates/designmd/cursor.md +537 -0
- package/dist/services/templates/designmd/expo.md +526 -0
- package/dist/services/templates/designmd/figma.md +578 -0
- package/dist/services/templates/designmd/framer.md +544 -0
- package/dist/services/templates/designmd/hp.md +670 -0
- package/dist/services/templates/designmd/linear.app.md +548 -0
- package/dist/services/templates/designmd/mintlify.md +852 -0
- package/dist/services/templates/designmd/miro.md +825 -0
- package/dist/services/templates/designmd/notion.md +821 -0
- package/dist/services/templates/designmd/raycast.md +669 -0
- package/dist/services/templates/designmd/resend.md +585 -0
- package/dist/services/templates/designmd/sentry.md +262 -0
- package/dist/services/templates/designmd/shopify.md +350 -0
- package/dist/services/templates/designmd/spotify.md +246 -0
- package/dist/services/templates/designmd/stripe.md +322 -0
- package/dist/services/templates/designmd/supabase.md +255 -0
- package/dist/services/templates/designmd/superhuman.md +252 -0
- package/dist/services/templates/designmd/uber.md +295 -0
- package/dist/services/templates/designmd/vercel.md +310 -0
- package/dist/services/templates/viteReactTs.d.ts +42 -0
- package/dist/services/templates/viteReactTs.d.ts.map +1 -0
- package/dist/services/templates/viteReactTs.js +267 -0
- package/dist/services/templates/viteReactTs.js.map +1 -0
- package/dist/types/change-request-types.d.ts +15 -3
- package/dist/types/change-request-types.d.ts.map +1 -1
- package/dist/utils/skills/claude-skill.d.ts +2 -2
- package/dist/utils/skills/claude-skill.d.ts.map +1 -1
- package/dist/utils/skills/claude-skill.js +19 -98
- package/dist/utils/skills/claude-skill.js.map +1 -1
- package/dist/utils/skills/cursor-rules.d.ts +2 -2
- package/dist/utils/skills/cursor-rules.d.ts.map +1 -1
- package/dist/utils/skills/cursor-rules.js +15 -80
- package/dist/utils/skills/cursor-rules.js.map +1 -1
- package/dist/utils/skills/shared-variants-protocol.d.ts +23 -0
- package/dist/utils/skills/shared-variants-protocol.d.ts.map +1 -0
- package/dist/utils/skills/shared-variants-protocol.js +131 -0
- package/dist/utils/skills/shared-variants-protocol.js.map +1 -0
- package/package.json +4 -3
- package/src/ui/dist/assets/main-C9jfEp80.css +1 -0
- package/src/ui/dist/assets/main-DejhsBWR.js +382 -0
- package/src/ui/dist/index.html +2 -2
- package/src/ui/dist/assets/main-Bv0LuxKz.js +0 -382
- package/src/ui/dist/assets/main-BzmseUDd.css +0 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerCreateZeroToOneTool = exports.slugifyPrompt = exports.createZeroToOneInput = void 0;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const v3_1 = require("zod/v3");
|
|
12
|
+
const viteReactTs_1 = require("../../services/templates/viteReactTs");
|
|
13
|
+
const contracts_1 = require("./contracts");
|
|
14
|
+
const errors_1 = require("./errors");
|
|
15
|
+
const sourceContext_1 = require("./sourceContext");
|
|
16
|
+
const inspirationDesignContext_1 = require("./inspirationDesignContext");
|
|
17
|
+
const designContextStore_1 = require("./designContextStore");
|
|
18
|
+
const DEFAULT_VARIANT_COUNT = 3;
|
|
19
|
+
const MIN_VARIANT_COUNT = 2;
|
|
20
|
+
const MAX_VARIANT_COUNT = 8;
|
|
21
|
+
const SLUG_SUFFIX_BYTES = 2;
|
|
22
|
+
exports.createZeroToOneInput = {
|
|
23
|
+
prompt: v3_1.z.string().min(1),
|
|
24
|
+
count: v3_1.z.number().int().min(MIN_VARIANT_COUNT).max(MAX_VARIANT_COUNT).optional(),
|
|
25
|
+
destinationParent: v3_1.z.string().optional(),
|
|
26
|
+
framework: v3_1.z.enum(['vite']).optional(),
|
|
27
|
+
sourceContext: contracts_1.sourceContextInputSchema.optional(),
|
|
28
|
+
sessionId: v3_1.z.string().optional(),
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Slugify a prompt into a directory-safe kebab-case name with a short random
|
|
32
|
+
* suffix so concurrent calls with the same prompt don't collide.
|
|
33
|
+
*/
|
|
34
|
+
const slugifyPrompt = (prompt) => {
|
|
35
|
+
const base = prompt
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
38
|
+
.replace(/^-+|-+$/g, '')
|
|
39
|
+
.slice(0, 40);
|
|
40
|
+
const suffix = (0, crypto_1.randomBytes)(SLUG_SUFFIX_BYTES).toString('hex');
|
|
41
|
+
return base ? `${base}-${suffix}` : `rivet-app-${suffix}`;
|
|
42
|
+
};
|
|
43
|
+
exports.slugifyPrompt = slugifyPrompt;
|
|
44
|
+
const failed = (code, message) => ({
|
|
45
|
+
stage: 'failed',
|
|
46
|
+
errorCode: code,
|
|
47
|
+
message,
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Register the `create_zero_to_one_project` convenience MCP tool. Normalizes
|
|
51
|
+
* the variant count, slugifies the prompt to derive a destination directory,
|
|
52
|
+
* validates the framework, and delegates to `proposeVariantsHandler` with
|
|
53
|
+
* `projectContext.kind = 'fresh'`.
|
|
54
|
+
*/
|
|
55
|
+
const registerCreateZeroToOneTool = (mcp, deps) => {
|
|
56
|
+
const homedir = deps.homedir ?? os_1.default.homedir;
|
|
57
|
+
// Filesystem store is the default for CLI/desktop deployments; the dep
|
|
58
|
+
// can swap in a hosted/server-backed store or pass `null` to disable
|
|
59
|
+
// caching entirely. The default store is constructed lazily so we only
|
|
60
|
+
// touch `os.homedir()` if the flow actually uses it. Memoized so the
|
|
61
|
+
// first call's `dirReady`/`mkdir` state survives across tool
|
|
62
|
+
// invocations instead of being thrown away after each request.
|
|
63
|
+
let defaultDesignContextStore;
|
|
64
|
+
const resolveDesignContextStore = () => {
|
|
65
|
+
if (deps.designContextStore === null)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (deps.designContextStore !== undefined)
|
|
68
|
+
return deps.designContextStore;
|
|
69
|
+
if (!defaultDesignContextStore) {
|
|
70
|
+
defaultDesignContextStore = new designContextStore_1.FileDesignContextStore();
|
|
71
|
+
}
|
|
72
|
+
return defaultDesignContextStore;
|
|
73
|
+
};
|
|
74
|
+
mcp.tool('create_zero_to_one_project', 'Convenience entry point for creating a new project from scratch. Slugifies the prompt into a destination directory under the user home and starts an agent-variants session with projectContext.kind=fresh. Returns the same response shape as propose_variants. REQUIRED PROTOCOL: source_research (when requested) -> report_source_context -> briefs -> user confirmation -> approve -> IMMEDIATELY share the visualEditor.url with the user ("Generating variants — watch here: <url>") -> request_work -> generate static_preview HTML/CSS for each work item -> report_variant_complete -> when terminal, share each previewUrl from the response with the user as clickable links -> user picks variant -> commit. static_preview is the final deliverable — no code_gen or Vite scaffold is created. Briefs: label ≤ 4 words, body exactly ONE sentence ≤ 20 words — a single evocative descriptor (no bullets, no lists). MANDATORY USER CONFIRMATION: after report_variant_briefs, show the numbered brief list and wait for feedback before approve_variant_briefs. NEVER auto-approve. For static_preview work items, report_variant_complete output must be {html: string, css?: string, js?: string} — write self-contained HTML with no React/Vite-only imports. After user commit, Rivet writes the HTML to index.html at the destination directory.', exports.createZeroToOneInput, async (args) => {
|
|
75
|
+
try {
|
|
76
|
+
const framework = args.framework ?? 'vite';
|
|
77
|
+
if (framework !== 'vite') {
|
|
78
|
+
return jsonResponse(failed('UNSUPPORTED_FRAMEWORK', `create_zero_to_one_project only supports framework='vite' in v1; got '${framework}'.`));
|
|
79
|
+
}
|
|
80
|
+
const count = clampCount(args.count);
|
|
81
|
+
const sourceUrls = (0, sourceContext_1.resolveSourceUrls)(args.prompt, args.sourceContext);
|
|
82
|
+
const sourceArtifacts = (0, sourceContext_1.normalizeSourceArtifacts)(args.sourceContext?.sourceArtifacts);
|
|
83
|
+
const destinationParent = args.destinationParent ?? homedir();
|
|
84
|
+
if (!path_1.default.isAbsolute(destinationParent)) {
|
|
85
|
+
return jsonResponse(failed('SCHEMA_VALIDATION_FAILED', `destinationParent must be absolute; got '${destinationParent}'.`));
|
|
86
|
+
}
|
|
87
|
+
const slug = (0, exports.slugifyPrompt)(args.prompt);
|
|
88
|
+
const destinationPath = path_1.default.join(destinationParent, slug);
|
|
89
|
+
if (!(0, viteReactTs_1.isDestinationEmpty)(destinationPath)) {
|
|
90
|
+
return jsonResponse(failed('DESTINATION_NOT_EMPTY', `Destination '${destinationPath}' is not empty.`));
|
|
91
|
+
}
|
|
92
|
+
const inspirationOutcome = sourceUrls.length > 0
|
|
93
|
+
? await (0, inspirationDesignContext_1.extractInspirationDesignContext)({
|
|
94
|
+
urls: sourceUrls,
|
|
95
|
+
prompt: args.prompt,
|
|
96
|
+
sourceContext: args.sourceContext,
|
|
97
|
+
slotCount: count,
|
|
98
|
+
fetcher: deps.inspirationFetcher,
|
|
99
|
+
store: resolveDesignContextStore(),
|
|
100
|
+
forceRefresh: (0, designContextStore_1.promptRequestsFreshExtraction)(args.prompt),
|
|
101
|
+
})
|
|
102
|
+
: {
|
|
103
|
+
entries: [],
|
|
104
|
+
warnings: [],
|
|
105
|
+
telemetry: {
|
|
106
|
+
inspirationLinkCount: 0,
|
|
107
|
+
referenceLinkCount: 0,
|
|
108
|
+
successfulExtractions: 0,
|
|
109
|
+
lowSignalCount: 0,
|
|
110
|
+
fetchFailureCount: 0,
|
|
111
|
+
blockedTargetCount: 0,
|
|
112
|
+
mergeStrategy: 'none',
|
|
113
|
+
cache: {
|
|
114
|
+
hitCount: 0,
|
|
115
|
+
missCount: 0,
|
|
116
|
+
staleCount: 0,
|
|
117
|
+
versionMismatchCount: 0,
|
|
118
|
+
lowConfidenceCount: 0,
|
|
119
|
+
regenerationCount: 0,
|
|
120
|
+
forcedRefresh: false,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const designContextEntries = collapseDesignContextEntries(inspirationOutcome.entries);
|
|
125
|
+
const projectContext = {
|
|
126
|
+
kind: 'fresh',
|
|
127
|
+
workspacePath: destinationPath,
|
|
128
|
+
framework: 'vite',
|
|
129
|
+
...(designContextEntries
|
|
130
|
+
? { designContext: designContextEntries }
|
|
131
|
+
: {}),
|
|
132
|
+
...(sourceUrls.length > 0 ||
|
|
133
|
+
sourceArtifacts.length > 0 ||
|
|
134
|
+
args.sourceContext?.preserveBrand !== undefined
|
|
135
|
+
? {
|
|
136
|
+
sourceContext: {
|
|
137
|
+
...(sourceUrls.length > 0 ? { sourceUrls } : {}),
|
|
138
|
+
...(sourceArtifacts.length > 0 ? { sourceArtifacts } : {}),
|
|
139
|
+
...(args.sourceContext?.preserveBrand !== undefined
|
|
140
|
+
? { preserveBrand: args.sourceContext.preserveBrand }
|
|
141
|
+
: {}),
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
: {}),
|
|
145
|
+
};
|
|
146
|
+
// Ensure the destination's parent exists so the materialize step at
|
|
147
|
+
// commit time has a directory to write into. The destination itself
|
|
148
|
+
// is created during materialize.
|
|
149
|
+
fs_1.default.mkdirSync(destinationParent, { recursive: true });
|
|
150
|
+
const proposeInput = {
|
|
151
|
+
sessionId: args.sessionId,
|
|
152
|
+
prompt: args.prompt,
|
|
153
|
+
count,
|
|
154
|
+
projectContext,
|
|
155
|
+
};
|
|
156
|
+
// Validate via the shared schema before delegating, so the proxy and
|
|
157
|
+
// direct callers see the same rejection shape.
|
|
158
|
+
const parsed = v3_1.z.object(contracts_1.proposeVariantsInput).safeParse(proposeInput);
|
|
159
|
+
if (!parsed.success) {
|
|
160
|
+
return jsonResponse(failed('SCHEMA_VALIDATION_FAILED', parsed.error.message));
|
|
161
|
+
}
|
|
162
|
+
const visualEditor = deps.ensureVisualEditorOpen
|
|
163
|
+
? await deps.ensureVisualEditorOpen({
|
|
164
|
+
projectPath: destinationPath,
|
|
165
|
+
framework: 'vite',
|
|
166
|
+
})
|
|
167
|
+
: undefined;
|
|
168
|
+
const result = deps.orchestrator.propose(parsed.data);
|
|
169
|
+
if (sourceUrls.length > 0 || sourceArtifacts.length > 0) {
|
|
170
|
+
deps.telemetry?.trackAgentVariantsSourceContextQuality?.({
|
|
171
|
+
sessionId: result.sessionId,
|
|
172
|
+
sourceUrlCount: sourceUrls.length,
|
|
173
|
+
artifactCount: sourceArtifacts.length,
|
|
174
|
+
hasScreenshotReferences: sourceArtifacts.some((artifact) => artifact.kind === 'screenshotNotes'),
|
|
175
|
+
preserveBrand: Boolean(args.sourceContext?.preserveBrand),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (inspirationOutcome.telemetry.inspirationLinkCount > 0 ||
|
|
179
|
+
inspirationOutcome.telemetry.referenceLinkCount > 0) {
|
|
180
|
+
const { cache, ...telemetryCounts } = inspirationOutcome.telemetry;
|
|
181
|
+
deps.telemetry?.trackAgentVariantsInspirationExtraction?.({
|
|
182
|
+
sessionId: result.sessionId,
|
|
183
|
+
...telemetryCounts,
|
|
184
|
+
cacheHitCount: cache.hitCount,
|
|
185
|
+
cacheMissCount: cache.missCount,
|
|
186
|
+
cacheStaleCount: cache.staleCount,
|
|
187
|
+
cacheVersionMismatchCount: cache.versionMismatchCount,
|
|
188
|
+
cacheLowConfidenceCount: cache.lowConfidenceCount,
|
|
189
|
+
cacheRegenerationCount: cache.regenerationCount,
|
|
190
|
+
cacheForcedRefresh: cache.forcedRefresh,
|
|
191
|
+
...(inspirationOutcome.cacheReuse
|
|
192
|
+
? {
|
|
193
|
+
cacheReuseAgeBucket: inspirationOutcome.cacheReuse.ageBucket,
|
|
194
|
+
cacheReuseConfidenceBucket: inspirationOutcome.cacheReuse.confidenceBucket,
|
|
195
|
+
}
|
|
196
|
+
: {}),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const warningsField = inspirationOutcome.warnings.length > 0
|
|
200
|
+
? { inspirationWarnings: inspirationOutcome.warnings }
|
|
201
|
+
: {};
|
|
202
|
+
if (result.stage === 'awaiting_source_research') {
|
|
203
|
+
return jsonResponse({
|
|
204
|
+
sessionId: result.sessionId,
|
|
205
|
+
stage: 'awaiting_source_research',
|
|
206
|
+
sourceResearchWorkItem: {
|
|
207
|
+
id: result.sourceResearchWorkItem.id,
|
|
208
|
+
kind: 'source_research',
|
|
209
|
+
attempt: result.sourceResearchWorkItem.attempt,
|
|
210
|
+
input: result.sourceResearchWorkItem.input,
|
|
211
|
+
output_schema: {
|
|
212
|
+
sourceContext: 'sourceFindings, sectionInventory, visualObservations, sourceRoles, qualityBar, screenshotReferences?',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
nextAction: 'continue_variants',
|
|
216
|
+
...(visualEditor ? { visualEditor } : {}),
|
|
217
|
+
...warningsField,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return jsonResponse({
|
|
221
|
+
sessionId: result.sessionId,
|
|
222
|
+
stage: 'awaiting_briefs',
|
|
223
|
+
briefWorkItem: {
|
|
224
|
+
id: result.briefWorkItem.id,
|
|
225
|
+
kind: 'brief',
|
|
226
|
+
attempt: result.briefWorkItem.attempt,
|
|
227
|
+
input: result.briefWorkItem.input,
|
|
228
|
+
output_schema: { briefs: 'Array<{briefId, label, body}>' },
|
|
229
|
+
},
|
|
230
|
+
nextAction: 'report_variant_briefs',
|
|
231
|
+
...(visualEditor ? { visualEditor } : {}),
|
|
232
|
+
...warningsField,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
const code = err instanceof errors_1.AgentVariantsError
|
|
237
|
+
? err.code
|
|
238
|
+
: 'SCHEMA_VALIDATION_FAILED';
|
|
239
|
+
const message = err instanceof Error
|
|
240
|
+
? err.message
|
|
241
|
+
: 'Unknown error in create_zero_to_one_project';
|
|
242
|
+
return jsonResponse({
|
|
243
|
+
stage: 'failed',
|
|
244
|
+
errorCode: code,
|
|
245
|
+
message,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
exports.registerCreateZeroToOneTool = registerCreateZeroToOneTool;
|
|
251
|
+
const clampCount = (count) => {
|
|
252
|
+
if (count === undefined)
|
|
253
|
+
return DEFAULT_VARIANT_COUNT;
|
|
254
|
+
if (count < MIN_VARIANT_COUNT)
|
|
255
|
+
return MIN_VARIANT_COUNT;
|
|
256
|
+
if (count > MAX_VARIANT_COUNT)
|
|
257
|
+
return MAX_VARIANT_COUNT;
|
|
258
|
+
return count;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Reduce inspiration-extraction output to the shape the project context
|
|
262
|
+
* accepts: a defined-only `DesignContextEntry[]` of length `entries.length`
|
|
263
|
+
* when every slot has extraction output, or `undefined` when at least one
|
|
264
|
+
* slot is missing so downstream slots fall back to prompt direction.
|
|
265
|
+
*
|
|
266
|
+
* The producer (`extractInspirationDesignContext`) currently populates the
|
|
267
|
+
* array all-or-nothing — either every slot gets an entry or every slot is
|
|
268
|
+
* `undefined`. Downstream consumers index per slot
|
|
269
|
+
* (`WorktreeManager.createFreshWorktrees` uses `designContext?.[i]`, and
|
|
270
|
+
* `summarizeDesignContext` tags telemetry with the slot index), so silently
|
|
271
|
+
* compacting `[A, undefined, B]` to `[A, B]` would shift B from slot 2 to
|
|
272
|
+
* slot 1 and misassign per-slot guidance. If the producer's invariant ever
|
|
273
|
+
* softens, fail closed here: drop the partial context rather than emitting
|
|
274
|
+
* a slot-shifted array.
|
|
275
|
+
*/
|
|
276
|
+
const collapseDesignContextEntries = (entries) => {
|
|
277
|
+
if (entries.length === 0)
|
|
278
|
+
return undefined;
|
|
279
|
+
const populated = [];
|
|
280
|
+
for (const entry of entries) {
|
|
281
|
+
if (entry === undefined)
|
|
282
|
+
return undefined;
|
|
283
|
+
populated.push(entry);
|
|
284
|
+
}
|
|
285
|
+
return populated;
|
|
286
|
+
};
|
|
287
|
+
const jsonResponse = (payload) => ({
|
|
288
|
+
content: [
|
|
289
|
+
{
|
|
290
|
+
type: 'text',
|
|
291
|
+
text: JSON.stringify(payload),
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
});
|
|
295
|
+
//# sourceMappingURL=createZeroToOneTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createZeroToOneTool.js","sourceRoot":"","sources":["../../../src/mcp/agent-variants/createZeroToOneTool.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAqC;AACrC,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AACxB,+BAA2B;AAE3B,sEAA0E;AAC1E,2CAQqB;AACrB,qCAA8D;AAC9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,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAtPW,QAAA,2BAA2B,+BAsPtC;AAEF,MAAM,UAAU,GAAG,CAAC,KAAyB,EAAU,EAAE;IACvD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,qBAAqB,CAAC;IACtD,IAAI,KAAK,GAAG,iBAAiB;QAAE,OAAO,iBAAiB,CAAC;IACxD,IAAI,KAAK,GAAG,iBAAiB;QAAE,OAAO,iBAAiB,CAAC;IACxD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,4BAA4B,GAAG,CACnC,OAA8C,EACZ,EAAE;IACpC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,MAAM,SAAS,GAAyB,EAAE,CAAC;IAC3C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAI,OAAU,EAAE,EAAE,CAAC,CAAC;IACvC,OAAO,EAAE;QACP;YACE,IAAI,EAAE,MAAe;YACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { InspirationDesignSignals } from './inspirationDesignContext';
|
|
2
|
+
/**
|
|
3
|
+
* Runtime user cache for inspiration-link design context. Persists generated
|
|
4
|
+
* designmd markdown plus safe metadata so future MCP
|
|
5
|
+
* `create_zero_to_one_project` requests with the same web link can reuse
|
|
6
|
+
* prior extraction by default. Treated as runtime user data — never mutates
|
|
7
|
+
* the bundled `src/services/templates/designmd` catalog.
|
|
8
|
+
*
|
|
9
|
+
* Path layout (local filesystem implementation):
|
|
10
|
+
* <directory>/<sha256(normalizedUrl)>.json
|
|
11
|
+
*
|
|
12
|
+
* The default <directory> is `~/.rivet/design-context-cache/`. The store
|
|
13
|
+
* abstraction is interface-first so future hosted/server deployments can
|
|
14
|
+
* provide a durable backend (HTTPS, KV, SQL) without changing the
|
|
15
|
+
* extraction or MCP orchestration logic.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Output/extractor schema version. Bump when the cache entry shape or the
|
|
19
|
+
* generated markdown structure changes incompatibly. Cached entries with a
|
|
20
|
+
* different schema version are not silently reused — they regenerate.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DESIGN_CONTEXT_SCHEMA_VERSION = "2";
|
|
23
|
+
/**
|
|
24
|
+
* Default freshness window for a cached entry. Entries older than this are
|
|
25
|
+
* marked `stale` and trigger regeneration by default. Tunable per call so
|
|
26
|
+
* tests can exercise the stale branch without sleeping.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_FRESHNESS_MS: number;
|
|
29
|
+
/**
|
|
30
|
+
* Default confidence threshold below which cached entries are considered
|
|
31
|
+
* low-confidence and trigger regeneration. Mirrors the in-extractor
|
|
32
|
+
* `LOW_SIGNAL_THRESHOLD` so cached and live signals stay aligned.
|
|
33
|
+
*/
|
|
34
|
+
export declare const DEFAULT_CONFIDENCE_THRESHOLD = 18;
|
|
35
|
+
export type FreshnessState = 'fresh' | 'stale';
|
|
36
|
+
export interface DesignContextCacheMetadata {
|
|
37
|
+
/** Stable cache key (sha256 hex of normalized URL). */
|
|
38
|
+
cacheKey: string;
|
|
39
|
+
/** Extractor/output schema version used to produce this entry. */
|
|
40
|
+
schemaVersion: string;
|
|
41
|
+
/** Wall-clock creation time (ms since epoch). */
|
|
42
|
+
createdAtMs: number;
|
|
43
|
+
/** Wall-clock last-used time (ms since epoch). */
|
|
44
|
+
lastUsedAtMs: number;
|
|
45
|
+
/** Signal density / confidence score (0-100). */
|
|
46
|
+
confidence: number;
|
|
47
|
+
/**
|
|
48
|
+
* Safe outcome metadata only — short non-sensitive warning codes such as
|
|
49
|
+
* `low_signal` or `partial_meta`. MUST NOT include fetched page content,
|
|
50
|
+
* full URLs, or extracted text snippets.
|
|
51
|
+
*/
|
|
52
|
+
warningCodes: string[];
|
|
53
|
+
}
|
|
54
|
+
export interface DesignContextCacheEntry {
|
|
55
|
+
metadata: DesignContextCacheMetadata;
|
|
56
|
+
/** Generated single-source designmd markdown (separate-flavor). */
|
|
57
|
+
markdown: string;
|
|
58
|
+
/** Short user-visible label (already truncated to fit downstream cap). */
|
|
59
|
+
label: string;
|
|
60
|
+
/**
|
|
61
|
+
* Structured design signals for the source URL. Storing the same derived
|
|
62
|
+
* design observations the markdown already encodes (palette, families,
|
|
63
|
+
* sections, components) so merge-strategy callers can re-summarise across
|
|
64
|
+
* multiple cached entries without re-fetching. Raw HTML, screenshots,
|
|
65
|
+
* DOM dumps, and full source text MUST NOT be persisted here.
|
|
66
|
+
*/
|
|
67
|
+
signals: InspirationDesignSignals;
|
|
68
|
+
}
|
|
69
|
+
export interface DesignContextStore {
|
|
70
|
+
get(cacheKey: string): Promise<DesignContextCacheEntry | undefined>;
|
|
71
|
+
put(entry: DesignContextCacheEntry): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Normalize an HTTP/HTTPS URL for cache keying. Lowercases scheme and host,
|
|
75
|
+
* strips default ports and fragments, and preserves meaningful path/query
|
|
76
|
+
* so two pages with the same host but different paths or query strings
|
|
77
|
+
* keep separate cache entries. Returns `undefined` for inputs that are not
|
|
78
|
+
* parseable HTTP/HTTPS URLs.
|
|
79
|
+
*/
|
|
80
|
+
export declare const normalizeCacheUrl: (rawUrl: string) => string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Compute a stable cache key from a normalized URL. SHA-256 hashed to hex
|
|
83
|
+
* so the resulting key is filesystem-safe and does not embed proprietary
|
|
84
|
+
* URL content in the filename layer.
|
|
85
|
+
*/
|
|
86
|
+
export declare const cacheKeyForUrl: (rawUrl: string) => string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Coarse age bucket for safe telemetry. Maps a wall-clock age in
|
|
89
|
+
* milliseconds onto a small fixed bucket name so analytics never receive
|
|
90
|
+
* exact timestamps.
|
|
91
|
+
*/
|
|
92
|
+
export declare const ageBucketFor: (ageMs: number) => "lt_1h" | "1h_24h" | "1d_7d" | "7d_30d" | "gt_30d";
|
|
93
|
+
/**
|
|
94
|
+
* Coarse confidence bucket for safe telemetry. Three buckets keyed off the
|
|
95
|
+
* extractor signal density score so reuse outcomes can be aggregated
|
|
96
|
+
* without leaking specific confidence values.
|
|
97
|
+
*/
|
|
98
|
+
export declare const confidenceBucketFor: (confidence: number) => "low" | "medium" | "high";
|
|
99
|
+
/**
|
|
100
|
+
* Return true when the user prompt explicitly asks for fresh/latest/
|
|
101
|
+
* current design context. Used by the MCP flow to bypass cache reuse even
|
|
102
|
+
* when a compatible entry exists.
|
|
103
|
+
*/
|
|
104
|
+
export declare const promptRequestsFreshExtraction: (prompt: string) => boolean;
|
|
105
|
+
export type CacheReuseDecision = {
|
|
106
|
+
reuse: true;
|
|
107
|
+
freshness: FreshnessState;
|
|
108
|
+
ageMs: number;
|
|
109
|
+
} | {
|
|
110
|
+
reuse: false;
|
|
111
|
+
reason: 'version_mismatch' | 'stale' | 'low_confidence' | 'forced_refresh' | 'corrupt';
|
|
112
|
+
freshness: FreshnessState;
|
|
113
|
+
ageMs: number;
|
|
114
|
+
};
|
|
115
|
+
interface CanReuseOptions {
|
|
116
|
+
forceRefresh: boolean;
|
|
117
|
+
schemaVersion?: string;
|
|
118
|
+
confidenceThreshold?: number;
|
|
119
|
+
freshnessMs?: number;
|
|
120
|
+
now?: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Decide whether a cached entry is reusable for a request, factoring in
|
|
124
|
+
* extractor/schema version, freshness window, confidence threshold, and
|
|
125
|
+
* any explicit user request for fresh extraction. Callers MUST honour the
|
|
126
|
+
* decision — the store itself never silently reuses incompatible entries.
|
|
127
|
+
*/
|
|
128
|
+
export declare const canReuseCacheEntry: (entry: DesignContextCacheEntry, options: CanReuseOptions) => CacheReuseDecision;
|
|
129
|
+
interface FileDesignContextStoreOptions {
|
|
130
|
+
/**
|
|
131
|
+
* Override the cache directory. Defaults to `~/.rivet/design-context-cache`
|
|
132
|
+
* via `os.homedir()`. Tests use a tmpdir override so the suite never
|
|
133
|
+
* touches the real user cache.
|
|
134
|
+
*/
|
|
135
|
+
directory?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Filesystem-backed `DesignContextStore`. One JSON file per cache key under
|
|
139
|
+
* a per-user cache directory. Safe to delete the entire directory without
|
|
140
|
+
* affecting bundled catalog data or compiled application code.
|
|
141
|
+
*
|
|
142
|
+
* Read/write failures degrade gracefully — get returns undefined on any
|
|
143
|
+
* parse/IO error so the MCP flow falls through to a fresh extraction
|
|
144
|
+
* instead of crashing the user request.
|
|
145
|
+
*/
|
|
146
|
+
export declare class FileDesignContextStore implements DesignContextStore {
|
|
147
|
+
private readonly directory;
|
|
148
|
+
private dirReady;
|
|
149
|
+
constructor(options?: FileDesignContextStoreOptions);
|
|
150
|
+
/**
|
|
151
|
+
* Resolve a cache key to its on-disk file path. Rejects keys that do not
|
|
152
|
+
* match the expected sha256 hex shape so a malformed key cannot escape
|
|
153
|
+
* the cache directory.
|
|
154
|
+
*/
|
|
155
|
+
resolvePath(cacheKey: string): string | undefined;
|
|
156
|
+
get(cacheKey: string): Promise<DesignContextCacheEntry | undefined>;
|
|
157
|
+
put(entry: DesignContextCacheEntry): Promise<void>;
|
|
158
|
+
}
|
|
159
|
+
export {};
|
|
160
|
+
//# sourceMappingURL=designContextStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"designContextStore.d.ts","sourceRoot":"","sources":["../../../src/mcp/agent-variants/designContextStore.ts"],"names":[],"mapp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