rivet-design 0.27.0 → 0.27.1

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.
Files changed (65) hide show
  1. package/dist/agent-variants/DirectionRefReservations.d.ts +11 -0
  2. package/dist/agent-variants/DirectionRefReservations.js +47 -0
  3. package/dist/agent-variants/SessionStore.d.ts +10 -1
  4. package/dist/agent-variants/SessionStore.js +25 -2
  5. package/dist/agent-variants/WorkItemRequestTimes.d.ts +6 -0
  6. package/dist/agent-variants/WorkItemRequestTimes.js +21 -0
  7. package/dist/agent-variants/WorktreeOrchestrator.d.ts +2 -1
  8. package/dist/agent-variants/WorktreeOrchestrator.js +92 -78
  9. package/dist/agent-variants/contracts.d.ts +4 -0
  10. package/dist/agent-variants/existingStaticEntry.d.ts +34 -0
  11. package/dist/agent-variants/existingStaticEntry.js +136 -0
  12. package/dist/agent-variants/staticPreviewFiles.js +1 -1
  13. package/dist/agent-variants/variant-project-runtime.d.ts +2 -1
  14. package/dist/agent-variants/variantsTelemetry.d.ts +4 -0
  15. package/dist/agent-variants/variantsTelemetry.js +2 -0
  16. package/dist/agent-variants/workItemInput.d.ts +22 -0
  17. package/dist/agent-variants/workItemInput.js +12 -1
  18. package/dist/cli/commands/directionTarget.d.ts +23 -0
  19. package/dist/cli/commands/directionTarget.js +87 -0
  20. package/dist/cli/commands/open.js +28 -4
  21. package/dist/cli/commands/variants.js +36 -43
  22. package/dist/cli/envelope.d.ts +1 -1
  23. package/dist/cli/envelope.js +1 -0
  24. package/dist/cli/projectRuntimeUpgrade.d.ts +11 -0
  25. package/dist/cli/projectRuntimeUpgrade.js +43 -11
  26. package/dist/config/pluginMetrics.js +2 -0
  27. package/dist/mcp/explorationSchema.js +1 -1
  28. package/dist/mcp/getExploration.js +11 -5
  29. package/dist/proxy-middleware/proxy-config.js +7 -0
  30. package/dist/routes/agentVariants.js +4 -0
  31. package/dist/routes/cli.js +10 -1
  32. package/dist/server.js +12 -6
  33. package/dist/services/ProjectLibrary.d.ts +4 -1
  34. package/dist/services/ProjectLibrary.js +14 -9
  35. package/dist/services/ProjectRuntimeService.d.ts +8 -0
  36. package/dist/services/ProjectRuntimeService.js +15 -2
  37. package/dist/services/TelemetryService.d.ts +5 -0
  38. package/dist/services/TelemetryService.js +19 -0
  39. package/dist/services/VariantHistoryService.d.ts +8 -0
  40. package/dist/services/VariantHistoryService.js +40 -0
  41. package/dist/services/WorktreeManager.d.ts +1 -0
  42. package/dist/services/WorktreeManager.js +12 -0
  43. package/dist/services/createAgentVariantsOrchestrator.js +9 -2
  44. package/dist/services/directionRefs.d.ts +21 -0
  45. package/dist/services/directionRefs.js +148 -0
  46. package/dist/services/projectDirections.d.ts +22 -0
  47. package/dist/services/projectDirections.js +38 -0
  48. package/dist/types/direction-ref.d.ts +36 -0
  49. package/dist/types/direction-ref.js +3 -0
  50. package/dist/types/variant-history.d.ts +3 -1
  51. package/dist/utils/skills/cli-guidance.js +4 -3
  52. package/dist/utils/subprocessEnvironment.d.ts +1 -1
  53. package/dist/utils/subprocessEnvironment.js +0 -1
  54. package/package.json +3 -3
  55. package/src/ui/dist/assets/LibraryEntry-BZ5EdFgA.js +37 -0
  56. package/src/ui/dist/assets/main-MepMmTwb.css +1 -0
  57. package/src/ui/dist/assets/main-RriU35pI.js +497 -0
  58. package/src/ui/dist/index.html +2 -2
  59. package/dist/services/StaticPreviewServer.d.ts +0 -8
  60. package/dist/services/StaticPreviewServer.js +0 -207
  61. package/src/ui/dist/assets/LibraryEntry-RI9Lc7P3.js +0 -37
  62. package/src/ui/dist/assets/main-D0UmAaUe.css +0 -1
  63. package/src/ui/dist/assets/main-DgrLzS5j.js +0 -497
  64. package/src/ui/dist/fonts/Goldman-Bold.woff2 +0 -0
  65. package/src/ui/dist/fonts/Goldman-Regular.woff2 +0 -0
@@ -0,0 +1,34 @@
1
+ import type { WorktreeRecord } from './WorkspaceInventory';
2
+ import type { ProjectEnvironment, WorktreeManagerLike } from './variant-project-runtime';
3
+ import { type VariantsTelemetry } from './variantsTelemetry';
4
+ export type ExistingStaticEntrySource = 'configured' | 'root_page' | 'changed_page';
5
+ export type ExistingStaticEntry = {
6
+ kind: 'found';
7
+ entryPath: string;
8
+ source: ExistingStaticEntrySource;
9
+ } | {
10
+ kind: 'missing';
11
+ detail: string;
12
+ source: 'configured' | 'none';
13
+ };
14
+ export type ExistingStaticPreviewEntry = {
15
+ kind: 'unresolved';
16
+ } | (ExistingStaticEntry & {
17
+ hostProjectPath: string;
18
+ projectDirectory: string;
19
+ startedAt: number;
20
+ });
21
+ export declare const resolveExistingStaticEntry: (args: {
22
+ worktreePath: string;
23
+ projectDirectory: string;
24
+ configuredEntryPath: string | undefined;
25
+ changedFiles: string[];
26
+ }) => Promise<ExistingStaticEntry>;
27
+ export declare const resolveExistingStaticPreviewEntry: (args: {
28
+ sessionId: string;
29
+ record: WorktreeRecord;
30
+ resolveEnv: (sessionId: string) => Promise<ProjectEnvironment>;
31
+ worktrees: WorktreeManagerLike;
32
+ telemetry: VariantsTelemetry;
33
+ }) => Promise<ExistingStaticPreviewEntry | undefined>;
34
+ //# sourceMappingURL=existingStaticEntry.d.ts.map
@@ -0,0 +1,136 @@
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.resolveExistingStaticPreviewEntry = exports.resolveExistingStaticEntry = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const staticProjectTarget_1 = require("../services/staticProjectTarget");
10
+ const pathContainment_1 = require("../utils/pathContainment");
11
+ const logger_1 = require("../utils/logger");
12
+ const variantsTelemetry_1 = require("./variantsTelemetry");
13
+ const log = (0, logger_1.createLogger)('ExistingStaticEntry');
14
+ const INDEX_PAGE = 'index.html';
15
+ const MISSING_PAGE_DETAIL = "This project has no index.html or package.json at its root, and this direction didn't add or change an HTML page. " +
16
+ "Run rivet open on the folder that contains your app's package.json or index.html, or pass --entry <page.html>.";
17
+ const missingConfiguredEntryDetail = (entryPath) => `${entryPath} isn't in this direction's copy of the project. Directions start from committed and untracked files; ` +
18
+ `git-ignored files are left out. Commit ${entryPath} or remove it from .gitignore, then generate the direction again.`;
19
+ const isPageInsideWorktree = async (worktreePath, pagePath) => {
20
+ const realPage = await (0, pathContainment_1.resolveRealPathWithinRoot)({
21
+ root: worktreePath,
22
+ candidate: pagePath,
23
+ containment: 'strict',
24
+ });
25
+ if (!realPage)
26
+ return false;
27
+ try {
28
+ await fs_1.default.promises.access(realPage, fs_1.default.constants.R_OK);
29
+ return (await fs_1.default.promises.stat(realPage)).isFile();
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ };
35
+ const pageDepth = (pagePath) => pagePath.split('/').length;
36
+ const isIndexPage = (pagePath) => path_1.default.posix.basename(pagePath).toLowerCase() === INDEX_PAGE;
37
+ const comparePreviewPages = (left, right) => pageDepth(left) - pageDepth(right) ||
38
+ Number(isIndexPage(right)) - Number(isIndexPage(left)) ||
39
+ left.localeCompare(right);
40
+ const findRootPage = (projectDirectory) => {
41
+ try {
42
+ return (0, staticProjectTarget_1.resolveStaticProjectTarget)({ targetPath: projectDirectory })
43
+ .entryPath;
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ };
49
+ const toProjectPagePaths = (args) => args.changedFiles
50
+ .map((changedFile) => path_1.default.join(args.worktreePath, changedFile))
51
+ .filter((changedPath) => (0, pathContainment_1.isPathStrictlyInsideRoot)(args.projectDirectory, changedPath) &&
52
+ (0, staticProjectTarget_1.isStaticHtmlFilePath)(changedPath))
53
+ .map((changedPath) => path_1.default
54
+ .relative(args.projectDirectory, changedPath)
55
+ .split(path_1.default.sep)
56
+ .join('/'))
57
+ .sort(comparePreviewPages);
58
+ const resolveExistingStaticEntry = async (args) => {
59
+ const isProjectPage = (entryPath) => isPageInsideWorktree(args.worktreePath, path_1.default.join(args.projectDirectory, entryPath));
60
+ if (args.configuredEntryPath) {
61
+ return (await isProjectPage(args.configuredEntryPath))
62
+ ? {
63
+ kind: 'found',
64
+ entryPath: args.configuredEntryPath,
65
+ source: 'configured',
66
+ }
67
+ : {
68
+ kind: 'missing',
69
+ detail: missingConfiguredEntryDetail(args.configuredEntryPath),
70
+ source: 'configured',
71
+ };
72
+ }
73
+ const rootPage = findRootPage(args.projectDirectory);
74
+ if (rootPage && (await isProjectPage(rootPage))) {
75
+ return { kind: 'found', entryPath: rootPage, source: 'root_page' };
76
+ }
77
+ for (const changedPage of toProjectPagePaths(args)) {
78
+ if (await isProjectPage(changedPage)) {
79
+ return { kind: 'found', entryPath: changedPage, source: 'changed_page' };
80
+ }
81
+ }
82
+ return { kind: 'missing', detail: MISSING_PAGE_DETAIL, source: 'none' };
83
+ };
84
+ exports.resolveExistingStaticEntry = resolveExistingStaticEntry;
85
+ const resolveExistingStaticPreviewEntry = async (args) => {
86
+ const { sessionId, record } = args;
87
+ let env;
88
+ try {
89
+ env = await args.resolveEnv(sessionId);
90
+ }
91
+ catch (err) {
92
+ log.warn(`resolveEnv failed for ${sessionId}`, err);
93
+ return undefined;
94
+ }
95
+ if (env.framework !== 'static')
96
+ return undefined;
97
+ const startedAt = Date.now();
98
+ (0, variantsTelemetry_1.trackPreviewStarted)(args.telemetry, {
99
+ sessionId,
100
+ variantId: record.workItemId,
101
+ projectContextKind: 'existing',
102
+ previewKind: 'static_artifact',
103
+ });
104
+ let projectDirectory;
105
+ try {
106
+ projectDirectory = await args.worktrees.getProjectCwdInWorktree(record.worktreePath);
107
+ }
108
+ catch (err) {
109
+ log.warn(`project cwd failed for ${sessionId}/${record.workItemId}`, err);
110
+ return { kind: 'unresolved' };
111
+ }
112
+ let changedFiles = [];
113
+ if (!env.entryPath) {
114
+ try {
115
+ changedFiles =
116
+ (await args.worktrees.getChangedFiles?.(record.worktreePath)) ?? [];
117
+ }
118
+ catch (err) {
119
+ log.warn(`changed files unavailable for ${sessionId}/${record.workItemId}`, err);
120
+ }
121
+ }
122
+ const entry = await (0, exports.resolveExistingStaticEntry)({
123
+ worktreePath: record.worktreePath,
124
+ projectDirectory,
125
+ configuredEntryPath: env.entryPath,
126
+ changedFiles,
127
+ });
128
+ return {
129
+ ...entry,
130
+ hostProjectPath: env.projectPath,
131
+ projectDirectory,
132
+ startedAt,
133
+ };
134
+ };
135
+ exports.resolveExistingStaticPreviewEntry = resolveExistingStaticPreviewEntry;
136
+ //# sourceMappingURL=existingStaticEntry.js.map
@@ -33,7 +33,7 @@ const prepareStaticPreviewProjectFiles = ({ sourceDir, entryPath, isWebsite, })
33
33
  exports.prepareStaticPreviewProjectFiles = prepareStaticPreviewProjectFiles;
34
34
  const stageStaticPreviewFiles = ({ preview, workItemId, environment, isWebsite, briefMarkdown, }) => {
35
35
  const rootPath = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), `rivet-variant-${workItemId}-`));
36
- const siteDirectory = isWebsite && environment?.framework === 'static'
36
+ const siteDirectory = isWebsite && environment?.framework === 'static' && environment.entryPath
37
37
  ? path_1.default.dirname(environment.entryPath)
38
38
  : '.';
39
39
  try {
@@ -14,6 +14,7 @@ export interface WorktreeManagerLike {
14
14
  startDevServer(worktreePath: string, port: number, cmd: string, args: string[], env: Record<string, string>): Promise<ChildProcess>;
15
15
  stopDevServer(proc: ChildProcess, timeoutMs?: number): Promise<void>;
16
16
  getProjectCwdInWorktree(worktreePath: string): Promise<string>;
17
+ getChangedFiles?(worktreePath: string): Promise<string[]>;
17
18
  createFreshWorktrees?(sessionId: string, count: number, template: TemplateBundle, designContext: ReadonlyArray<DesignContextEntry | undefined> | undefined, destinationParent: string): Promise<string[]>;
18
19
  }
19
20
  type DevServerProjectEnvironment = {
@@ -31,7 +32,7 @@ type DevServerProjectEnvironment = {
31
32
  type StaticProjectEnvironment = {
32
33
  projectPath: string;
33
34
  framework: 'static';
34
- entryPath: string;
35
+ entryPath?: string;
35
36
  };
36
37
  export type ProjectEnvironment = DevServerProjectEnvironment | StaticProjectEnvironment;
37
38
  export {};
@@ -64,6 +64,7 @@ export interface VariantsTelemetry {
64
64
  hasPort: boolean;
65
65
  port?: number;
66
66
  durationMs?: number | null;
67
+ staticEntrySource?: string;
67
68
  }) => void;
68
69
  trackAgentVariantsPreviewFailed?: (data: {
69
70
  sessionId: string;
@@ -77,6 +78,7 @@ export interface VariantsTelemetry {
77
78
  exitCode?: number | null;
78
79
  signal?: string | null;
79
80
  missingDeps?: boolean;
81
+ staticEntrySource?: string;
80
82
  error?: unknown;
81
83
  }) => void;
82
84
  trackAgentVariantsBriefQuality?: (data: {
@@ -150,6 +152,7 @@ export declare const trackPreviewReady: (telemetry: VariantsTelemetry, data: {
150
152
  hasPort: boolean;
151
153
  port?: number;
152
154
  durationMs?: number | null;
155
+ staticEntrySource?: string;
153
156
  }) => void;
154
157
  export declare const trackPreviewFailed: (telemetry: VariantsTelemetry, data: {
155
158
  sessionId: string;
@@ -163,6 +166,7 @@ export declare const trackPreviewFailed: (telemetry: VariantsTelemetry, data: {
163
166
  exitCode?: number | null;
164
167
  signal?: string | null;
165
168
  missingDeps?: boolean;
169
+ staticEntrySource?: string;
166
170
  error?: unknown;
167
171
  }) => void;
168
172
  export declare const trackStaticPreviewCompleted: (telemetry: VariantsTelemetry, data: {
@@ -122,6 +122,7 @@ const trackPreviewReady = (telemetry, data) => {
122
122
  has_port: data.hasPort,
123
123
  port: data.port,
124
124
  duration_ms: data.durationMs,
125
+ static_entry_source: data.staticEntrySource,
125
126
  });
126
127
  };
127
128
  exports.trackPreviewReady = trackPreviewReady;
@@ -143,6 +144,7 @@ const trackPreviewFailed = (telemetry, data) => {
143
144
  exit_code: data.exitCode,
144
145
  term_signal: data.signal,
145
146
  missing_deps: data.missingDeps,
147
+ static_entry_source: data.staticEntrySource,
146
148
  ...(0, failureReason_1.failureReasonProperties)(data.error),
147
149
  });
148
150
  };
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod/v3';
2
2
  import type { WorkerSelection } from '../types/change-request-types';
3
+ import type { DirectionRef } from '../types/direction-ref';
3
4
  import type { StaticPreviewTargetElement, VariantWorkItem, WorkItem, WorkItemKind } from './contracts';
4
5
  export declare const VARIANT_WORK_ITEM_KINDS: readonly ["static_preview", "refine_variant", "code_gen"];
5
6
  export type VariantWorkItemKind = (typeof VARIANT_WORK_ITEM_KINDS)[number];
@@ -613,6 +614,8 @@ declare const variantWorkItemInputSchemas: {
613
614
  }>;
614
615
  briefBody: z.ZodOptional<z.ZodString>;
615
616
  briefNotes: z.ZodOptional<z.ZodString>;
617
+ directionRef: z.ZodOptional<z.ZodType<DirectionRef, z.ZodTypeDef, DirectionRef>>;
618
+ sourceDirectionRef: z.ZodOptional<z.ZodType<DirectionRef, z.ZodTypeDef, DirectionRef>>;
616
619
  visualReferenceUrl: z.ZodOptional<z.ZodString>;
617
620
  instruction: z.ZodOptional<z.ZodString>;
618
621
  guidance: z.ZodOptional<z.ZodArray<z.ZodType<{
@@ -1427,6 +1430,8 @@ declare const variantWorkItemInputSchemas: {
1427
1430
  workerSelection?: WorkerSelection | undefined;
1428
1431
  briefBody?: string | undefined;
1429
1432
  briefNotes?: string | undefined;
1433
+ directionRef?: DirectionRef | undefined;
1434
+ sourceDirectionRef?: DirectionRef | undefined;
1430
1435
  visualReferenceUrl?: string | undefined;
1431
1436
  guidance?: {
1432
1437
  id: string;
@@ -1927,6 +1932,8 @@ declare const variantWorkItemInputSchemas: {
1927
1932
  workerSelection?: WorkerSelection | undefined;
1928
1933
  briefBody?: string | undefined;
1929
1934
  briefNotes?: string | undefined;
1935
+ directionRef?: DirectionRef | undefined;
1936
+ sourceDirectionRef?: DirectionRef | undefined;
1930
1937
  visualReferenceUrl?: string | undefined;
1931
1938
  guidance?: {
1932
1939
  id: string;
@@ -2595,6 +2602,8 @@ declare const variantWorkItemInputSchemas: {
2595
2602
  briefLabel: z.ZodOptional<z.ZodString>;
2596
2603
  briefBody: z.ZodOptional<z.ZodString>;
2597
2604
  briefNotes: z.ZodOptional<z.ZodString>;
2605
+ directionRef: z.ZodOptional<z.ZodType<DirectionRef, z.ZodTypeDef, DirectionRef>>;
2606
+ sourceDirectionRef: z.ZodOptional<z.ZodType<DirectionRef, z.ZodTypeDef, DirectionRef>>;
2598
2607
  visualReferenceUrl: z.ZodOptional<z.ZodString>;
2599
2608
  guidance: z.ZodOptional<z.ZodArray<z.ZodType<{
2600
2609
  id: string;
@@ -3407,6 +3416,8 @@ declare const variantWorkItemInputSchemas: {
3407
3416
  briefLabel?: string | undefined;
3408
3417
  briefBody?: string | undefined;
3409
3418
  briefNotes?: string | undefined;
3419
+ directionRef?: DirectionRef | undefined;
3420
+ sourceDirectionRef?: DirectionRef | undefined;
3410
3421
  visualReferenceUrl?: string | undefined;
3411
3422
  guidance?: {
3412
3423
  id: string;
@@ -3907,6 +3918,8 @@ declare const variantWorkItemInputSchemas: {
3907
3918
  briefLabel?: string | undefined;
3908
3919
  briefBody?: string | undefined;
3909
3920
  briefNotes?: string | undefined;
3921
+ directionRef?: DirectionRef | undefined;
3922
+ sourceDirectionRef?: DirectionRef | undefined;
3910
3923
  visualReferenceUrl?: string | undefined;
3911
3924
  guidance?: {
3912
3925
  id: string;
@@ -4572,6 +4585,8 @@ declare const variantWorkItemInputSchemas: {
4572
4585
  assetSourceRoot?: string | undefined;
4573
4586
  }>;
4574
4587
  briefNotes: z.ZodOptional<z.ZodString>;
4588
+ directionRef: z.ZodOptional<z.ZodType<DirectionRef, z.ZodTypeDef, DirectionRef>>;
4589
+ sourceDirectionRef: z.ZodOptional<z.ZodType<DirectionRef, z.ZodTypeDef, DirectionRef>>;
4575
4590
  visualReferenceUrl: z.ZodOptional<z.ZodString>;
4576
4591
  instruction: z.ZodOptional<z.ZodString>;
4577
4592
  guidance: z.ZodOptional<z.ZodArray<z.ZodType<{
@@ -5387,6 +5402,8 @@ declare const variantWorkItemInputSchemas: {
5387
5402
  } | undefined;
5388
5403
  workerSelection?: WorkerSelection | undefined;
5389
5404
  briefNotes?: string | undefined;
5405
+ directionRef?: DirectionRef | undefined;
5406
+ sourceDirectionRef?: DirectionRef | undefined;
5390
5407
  visualReferenceUrl?: string | undefined;
5391
5408
  guidance?: {
5392
5409
  id: string;
@@ -5887,6 +5904,8 @@ declare const variantWorkItemInputSchemas: {
5887
5904
  } | undefined;
5888
5905
  workerSelection?: WorkerSelection | undefined;
5889
5906
  briefNotes?: string | undefined;
5907
+ directionRef?: DirectionRef | undefined;
5908
+ sourceDirectionRef?: DirectionRef | undefined;
5890
5909
  visualReferenceUrl?: string | undefined;
5891
5910
  guidance?: {
5892
5911
  id: string;
@@ -5951,6 +5970,9 @@ export type VariantWorkItemInputByKind = {
5951
5970
  [Kind in VariantWorkItemKind]: z.infer<(typeof variantWorkItemInputSchemas)[Kind]>;
5952
5971
  };
5953
5972
  export type VariantWorkItemInput = VariantWorkItemInputByKind[VariantWorkItemKind];
5973
+ export declare const shownDirectionRef: (input: Pick<VariantWorkItemInput, "directionRef" | "sourceDirectionRef">) => {
5974
+ directionRef?: DirectionRef;
5975
+ };
5954
5976
  export declare const parseVariantWorkItemInput: <Kind extends VariantWorkItemKind>(item: {
5955
5977
  id: string;
5956
5978
  kind: Kind;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseVariantWorkItemInput = exports.isVariantWorkItem = exports.isVariantWorkItemKind = exports.VARIANT_WORK_ITEM_KINDS = void 0;
3
+ exports.parseVariantWorkItemInput = exports.shownDirectionRef = exports.isVariantWorkItem = exports.isVariantWorkItemKind = exports.VARIANT_WORK_ITEM_KINDS = void 0;
4
4
  const v3_1 = require("zod/v3");
5
5
  const errors_1 = require("./errors");
6
6
  exports.VARIANT_WORK_ITEM_KINDS = [
@@ -21,6 +21,12 @@ const variantWorkItemInputFields = v3_1.z.object({
21
21
  briefLabel: v3_1.z.string().optional(),
22
22
  briefBody: v3_1.z.string().optional(),
23
23
  briefNotes: v3_1.z.string().optional(),
24
+ directionRef: v3_1.z
25
+ .custom((value) => typeof value === 'string')
26
+ .optional(),
27
+ sourceDirectionRef: v3_1.z
28
+ .custom((value) => typeof value === 'string')
29
+ .optional(),
24
30
  visualReferenceUrl: v3_1.z.string().optional(),
25
31
  instruction: v3_1.z.string().optional(),
26
32
  guidance: v3_1.z.array(recordOf()).optional(),
@@ -59,6 +65,11 @@ const variantWorkItemInputSchemas = {
59
65
  briefBody: v3_1.z.string(),
60
66
  }),
61
67
  };
68
+ const shownDirectionRef = (input) => {
69
+ const directionRef = input.directionRef ?? input.sourceDirectionRef;
70
+ return directionRef ? { directionRef } : {};
71
+ };
72
+ exports.shownDirectionRef = shownDirectionRef;
62
73
  const variantWorkItemInputParsers = {
63
74
  static_preview: (input) => variantWorkItemInputSchemas.static_preview.safeParse(input),
64
75
  refine_variant: (input) => variantWorkItemInputSchemas.refine_variant.safeParse(input),
@@ -0,0 +1,23 @@
1
+ import { type CliCommandResult } from '../envelope';
2
+ import type { DirectionRef } from '../../types/direction-ref';
3
+ export type DirectionTarget = {
4
+ projectId?: string;
5
+ sessionId: string;
6
+ variantId: string;
7
+ directionRef?: DirectionRef;
8
+ };
9
+ type DirectionTargetResult = {
10
+ ok: true;
11
+ target: DirectionTarget;
12
+ } | {
13
+ ok: false;
14
+ result: CliCommandResult;
15
+ };
16
+ export declare const resolveDirectionTarget: (args: {
17
+ command: string;
18
+ projectPath: string;
19
+ input: string;
20
+ usage: string;
21
+ }) => Promise<DirectionTargetResult>;
22
+ export {};
23
+ //# sourceMappingURL=directionTarget.d.ts.map
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveDirectionTarget = void 0;
4
+ const envelope_1 = require("../envelope");
5
+ const libraryErrors_1 = require("../../services/libraryErrors");
6
+ const ProjectLibrary_1 = require("../../services/ProjectLibrary");
7
+ const VariantHistoryService_1 = require("../../services/VariantHistoryService");
8
+ const directionRefs_1 = require("../../services/directionRefs");
9
+ const projectDirections_1 = require("../../services/projectDirections");
10
+ const errorMessage_1 = require("../../utils/errorMessage");
11
+ const resolveInProject = async (args) => {
12
+ const library = ProjectLibrary_1.ProjectLibrary.openReadOnly();
13
+ try {
14
+ const owner = library?.registry.findByPath(args.projectPath);
15
+ if (library && owner)
16
+ return {
17
+ projectId: owner.id,
18
+ resolution: await (0, projectDirections_1.resolveProjectDirection)({
19
+ source: { kind: 'library', library, projectId: owner.id },
20
+ address: args.address,
21
+ }),
22
+ };
23
+ const history = new VariantHistoryService_1.VariantHistoryService();
24
+ try {
25
+ return {
26
+ resolution: await (0, projectDirections_1.resolveProjectDirection)({
27
+ source: { kind: 'history', history, projectPath: args.projectPath },
28
+ address: args.address,
29
+ }),
30
+ };
31
+ }
32
+ finally {
33
+ history.metadata.closeAll();
34
+ }
35
+ }
36
+ finally {
37
+ library?.close();
38
+ }
39
+ };
40
+ const resolveDirectionTarget = async (args) => {
41
+ const address = (0, directionRefs_1.parseDirectionAddress)(args.input);
42
+ if (!address)
43
+ return {
44
+ ok: false,
45
+ result: (0, envelope_1.errorResult)(args.command, 'USAGE_ERROR', args.usage),
46
+ };
47
+ if (address.kind === 'ids') {
48
+ const { projectId, sessionId, variantId } = address;
49
+ return {
50
+ ok: true,
51
+ target: { ...(projectId ? { projectId } : {}), sessionId, variantId },
52
+ };
53
+ }
54
+ try {
55
+ const { projectId, resolution } = await resolveInProject({
56
+ projectPath: args.projectPath,
57
+ address,
58
+ });
59
+ if (!resolution.isResolved)
60
+ return {
61
+ ok: false,
62
+ result: (0, envelope_1.errorResult)(args.command, resolution.code, resolution.message, {
63
+ input: args.input.trim(),
64
+ candidates: resolution.candidates,
65
+ }),
66
+ };
67
+ const { directionRef, sessionId, variantId } = resolution.direction;
68
+ return {
69
+ ok: true,
70
+ target: {
71
+ ...(projectId ? { projectId } : {}),
72
+ sessionId,
73
+ variantId,
74
+ directionRef,
75
+ },
76
+ };
77
+ }
78
+ catch (error) {
79
+ const isMissingProject = error instanceof libraryErrors_1.LibraryError && error.code === 'project_not_found';
80
+ return {
81
+ ok: false,
82
+ result: (0, envelope_1.errorResult)(args.command, isMissingProject ? 'WORK_ITEM_NOT_FOUND' : 'OPERATION_FAILED', (0, errorMessage_1.errorMessage)(error)),
83
+ };
84
+ }
85
+ };
86
+ exports.resolveDirectionTarget = resolveDirectionTarget;
87
+ //# sourceMappingURL=directionTarget.js.map
@@ -47,6 +47,7 @@ const flags_1 = require("../flags");
47
47
  const client_1 = require("../client");
48
48
  const serverHandshake_1 = require("../serverHandshake");
49
49
  const serverVersion_1 = require("../serverVersion");
50
+ const telemetry_1 = require("../telemetry");
50
51
  const handoff_1 = require("../handoff");
51
52
  const callerRunnerPaths_1 = require("../callerRunnerPaths");
52
53
  const runnerSelection_1 = require("../runnerSelection");
@@ -149,6 +150,15 @@ const passthroughServeArgs = (context) => {
149
150
  }
150
151
  return args;
151
152
  };
153
+ const USER_PORT_FLAG = '--user-port';
154
+ const withoutUserPort = (args) => args.filter((arg, index) => arg !== USER_PORT_FLAG && args[index - 1] !== USER_PORT_FLAG);
155
+ const previewRecoveryServeArgs = (context, retiredArgs) => {
156
+ const userPort = (0, flags_1.stringFlag)(context.flags, 'user-port');
157
+ return [
158
+ ...withoutUserPort(retiredArgs ?? passthroughServeArgs(context)),
159
+ ...(userPort === undefined ? [] : [USER_PORT_FLAG, userPort]),
160
+ ];
161
+ };
152
162
  const serveEnvFor = (handoff, baseEnv) => ({
153
163
  ...(0, subprocessEnvironment_1.subprocessEnvironment)('rivetRuntime', baseEnv),
154
164
  ...(0, callerRunnerPaths_1.callerRunnerPathsEnvEntry)(baseEnv),
@@ -283,12 +293,26 @@ const ensureProjectRuntime = async (context, io, dependencies = {}) => {
283
293
  }
284
294
  if (replacement.outcome === 'attach') {
285
295
  const readinessError = await verifyRuntimeReadiness(existing, Math.min(serverStartTimeoutMs, APP_HEALTH_TIMEOUT_MS));
286
- if (readinessError)
296
+ if (!readinessError) {
297
+ return finishProjectOpen(await openedData(existing, true), io);
298
+ }
299
+ if ((0, telemetry_1.serverUnavailableReasonForEnvelope)(readinessError.envelope) !==
300
+ 'app_health_failed')
301
+ return readinessError;
302
+ const retirement = await (0, projectRuntimeUpgrade_1.retireUnavailablePreview)({
303
+ attached: existing,
304
+ clientVersion: (0, serverVersion_1.serverVersionInfo)(existing.handshake).cliVersion,
305
+ shutdownTimeoutMs: timeoutFromEnv(env, UPGRADE_SHUTDOWN_TIMEOUT_ENV, DEFAULT_UPGRADE_SHUTDOWN_TIMEOUT_MS),
306
+ });
307
+ if (retirement.outcome === 'kept')
287
308
  return readinessError;
288
- return finishProjectOpen(await openedData(existing, true), io);
309
+ restartArgs = previewRecoveryServeArgs(context, retirement.restartArgs);
310
+ io.writeProgress('The project server is restarting because the app preview is unavailable…');
311
+ }
312
+ else {
313
+ interruptedWork = replacement.interruptedWork;
314
+ restartArgs = replacement.restartArgs;
289
315
  }
290
- interruptedWork = replacement.interruptedWork;
291
- restartArgs = replacement.restartArgs;
292
316
  }
293
317
  io.writeProgress(`Starting Rivet server for ${projectPath}…`);
294
318
  const handle = spawnServer({