@stigmer/react 3.1.3 → 3.1.4

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 (151) hide show
  1. package/composer/SessionComposer.d.ts +31 -0
  2. package/composer/SessionComposer.d.ts.map +1 -1
  3. package/composer/SessionComposer.js +12 -4
  4. package/composer/SessionComposer.js.map +1 -1
  5. package/execution/ArtifactApplyButton.d.ts +25 -0
  6. package/execution/ArtifactApplyButton.d.ts.map +1 -0
  7. package/execution/ArtifactApplyButton.js +21 -0
  8. package/execution/ArtifactApplyButton.js.map +1 -0
  9. package/execution/ArtifactContentBody.d.ts +36 -0
  10. package/execution/ArtifactContentBody.d.ts.map +1 -0
  11. package/execution/ArtifactContentBody.js +62 -0
  12. package/execution/ArtifactContentBody.js.map +1 -0
  13. package/execution/ArtifactDocument.d.ts +48 -0
  14. package/execution/ArtifactDocument.d.ts.map +1 -0
  15. package/execution/ArtifactDocument.js +89 -0
  16. package/execution/ArtifactDocument.js.map +1 -0
  17. package/execution/ArtifactPreviewModal.d.ts +4 -4
  18. package/execution/ArtifactPreviewModal.d.ts.map +1 -1
  19. package/execution/ArtifactPreviewModal.js +15 -142
  20. package/execution/ArtifactPreviewModal.js.map +1 -1
  21. package/execution/ArtifactRow.d.ts +49 -0
  22. package/execution/ArtifactRow.d.ts.map +1 -0
  23. package/execution/ArtifactRow.js +56 -0
  24. package/execution/ArtifactRow.js.map +1 -0
  25. package/execution/ArtifactsWidget.d.ts +6 -9
  26. package/execution/ArtifactsWidget.d.ts.map +1 -1
  27. package/execution/ArtifactsWidget.js +15 -19
  28. package/execution/ArtifactsWidget.js.map +1 -1
  29. package/execution/index.d.ts +8 -2
  30. package/execution/index.d.ts.map +1 -1
  31. package/execution/index.js +4 -1
  32. package/execution/index.js.map +1 -1
  33. package/execution/useArtifactContent.d.ts +6 -1
  34. package/execution/useArtifactContent.d.ts.map +1 -1
  35. package/execution/useArtifactContent.js +7 -2
  36. package/execution/useArtifactContent.js.map +1 -1
  37. package/execution/useArtifactInspection.d.ts +85 -0
  38. package/execution/useArtifactInspection.d.ts.map +1 -0
  39. package/execution/useArtifactInspection.js +143 -0
  40. package/execution/useArtifactInspection.js.map +1 -0
  41. package/execution/useCreateAgentExecution.d.ts +11 -0
  42. package/execution/useCreateAgentExecution.d.ts.map +1 -1
  43. package/execution/useCreateAgentExecution.js +1 -0
  44. package/execution/useCreateAgentExecution.js.map +1 -1
  45. package/index.d.ts +3 -3
  46. package/index.d.ts.map +1 -1
  47. package/index.js +2 -2
  48. package/index.js.map +1 -1
  49. package/internal/MermaidDiagram.d.ts +47 -0
  50. package/internal/MermaidDiagram.d.ts.map +1 -0
  51. package/internal/MermaidDiagram.js +118 -0
  52. package/internal/MermaidDiagram.js.map +1 -0
  53. package/internal/markdown-components.d.ts.map +1 -1
  54. package/internal/markdown-components.js +34 -0
  55. package/internal/markdown-components.js.map +1 -1
  56. package/internal/mermaid-loader.d.ts +26 -0
  57. package/internal/mermaid-loader.d.ts.map +1 -0
  58. package/internal/mermaid-loader.js +34 -0
  59. package/internal/mermaid-loader.js.map +1 -0
  60. package/internal/mermaid-theme-css.d.ts +41 -0
  61. package/internal/mermaid-theme-css.d.ts.map +1 -0
  62. package/internal/mermaid-theme-css.js +179 -0
  63. package/internal/mermaid-theme-css.js.map +1 -0
  64. package/internal/slug.d.ts +9 -5
  65. package/internal/slug.d.ts.map +1 -1
  66. package/internal/slug.js +10 -6
  67. package/internal/slug.js.map +1 -1
  68. package/package.json +5 -4
  69. package/session/SessionViewer.d.ts.map +1 -1
  70. package/session/SessionViewer.js +91 -18
  71. package/session/SessionViewer.js.map +1 -1
  72. package/session/artifact-document.d.ts +13 -0
  73. package/session/artifact-document.d.ts.map +1 -0
  74. package/session/artifact-document.js +22 -0
  75. package/session/artifact-document.js.map +1 -0
  76. package/session/facets/ArtifactsTab.d.ts +30 -4
  77. package/session/facets/ArtifactsTab.d.ts.map +1 -1
  78. package/session/facets/ArtifactsTab.js +32 -10
  79. package/session/facets/ArtifactsTab.js.map +1 -1
  80. package/session/index.d.ts +2 -1
  81. package/session/index.d.ts.map +1 -1
  82. package/session/index.js +4 -1
  83. package/session/index.js.map +1 -1
  84. package/session/useSessionArtifacts.d.ts +17 -0
  85. package/session/useSessionArtifacts.d.ts.map +1 -1
  86. package/session/useSessionArtifacts.js +16 -5
  87. package/session/useSessionArtifacts.js.map +1 -1
  88. package/session/useSessionConversation.d.ts +17 -1
  89. package/session/useSessionConversation.d.ts.map +1 -1
  90. package/session/useSessionConversation.js +32 -4
  91. package/session/useSessionConversation.js.map +1 -1
  92. package/session/useSessionPageFlow.d.ts.map +1 -1
  93. package/session/useSessionPageFlow.js +1 -0
  94. package/session/useSessionPageFlow.js.map +1 -1
  95. package/session/useSessionPanel.d.ts +20 -0
  96. package/session/useSessionPanel.d.ts.map +1 -1
  97. package/session/useSessionPanel.js +13 -0
  98. package/session/useSessionPanel.js.map +1 -1
  99. package/session/useSessionRailViews.d.ts +13 -1
  100. package/session/useSessionRailViews.d.ts.map +1 -1
  101. package/session/useSessionRailViews.js +5 -3
  102. package/session/useSessionRailViews.js.map +1 -1
  103. package/src/composer/SessionComposer.tsx +69 -1
  104. package/src/composer/__tests__/SessionComposer-editing.test.tsx +128 -0
  105. package/src/execution/ArtifactApplyButton.tsx +79 -0
  106. package/src/execution/ArtifactContentBody.tsx +255 -0
  107. package/src/execution/ArtifactDocument.tsx +344 -0
  108. package/src/execution/ArtifactPreviewModal.tsx +39 -405
  109. package/src/execution/ArtifactRow.tsx +165 -0
  110. package/src/execution/ArtifactsWidget.tsx +24 -33
  111. package/src/execution/__tests__/ArtifactContentBody.test.tsx +131 -0
  112. package/src/execution/__tests__/ArtifactDocument.test.tsx +100 -0
  113. package/src/execution/__tests__/ArtifactRow.test.tsx +139 -0
  114. package/src/execution/__tests__/ArtifactsWidget.test.tsx +78 -0
  115. package/src/execution/__tests__/message-entry.test.tsx +50 -2
  116. package/src/execution/__tests__/useArtifactInspection.test.tsx +151 -0
  117. package/src/execution/__tests__/useCreateAgentExecution.test.tsx +35 -0
  118. package/src/execution/index.ts +14 -2
  119. package/src/execution/useArtifactContent.ts +7 -0
  120. package/src/execution/useArtifactInspection.ts +252 -0
  121. package/src/execution/useCreateAgentExecution.ts +12 -0
  122. package/src/index.ts +11 -2
  123. package/src/internal/MermaidDiagram.tsx +164 -0
  124. package/src/internal/__tests__/a11y/mermaid-theme.a11y.test.tsx +122 -0
  125. package/src/internal/__tests__/markdown-components.test.tsx +93 -1
  126. package/src/internal/__tests__/mermaid-diagram.test.tsx +282 -0
  127. package/src/internal/markdown-components.tsx +36 -1
  128. package/src/internal/mermaid-loader.ts +44 -0
  129. package/src/internal/mermaid-theme-css.ts +178 -0
  130. package/src/internal/slug.ts +10 -6
  131. package/src/session/SessionViewer.tsx +177 -33
  132. package/src/session/__tests__/SessionViewer-artifactTabs.test.tsx +210 -0
  133. package/src/session/__tests__/SessionViewer-editResubmit.test.tsx +233 -0
  134. package/src/session/__tests__/useSessionArtifacts.test.ts +57 -0
  135. package/src/session/__tests__/useSessionConversation.test.tsx +172 -1
  136. package/src/session/__tests__/useSessionPanel.test.ts +70 -1
  137. package/src/session/artifact-document.ts +23 -0
  138. package/src/session/facets/ArtifactsTab.tsx +66 -18
  139. package/src/session/facets/__tests__/ArtifactsTab.test.tsx +111 -47
  140. package/src/session/index.ts +5 -1
  141. package/src/session/useSessionArtifacts.ts +16 -5
  142. package/src/session/useSessionConversation.ts +48 -6
  143. package/src/session/useSessionPageFlow.ts +1 -0
  144. package/src/session/useSessionPanel.ts +41 -0
  145. package/src/session/useSessionRailViews.tsx +21 -1
  146. package/styles.css +1 -1
  147. package/execution/ArtifactCard.d.ts +0 -81
  148. package/execution/ArtifactCard.d.ts.map +0 -1
  149. package/execution/ArtifactCard.js +0 -130
  150. package/execution/ArtifactCard.js.map +0 -1
  151. package/src/execution/ArtifactCard.tsx +0 -320
@@ -0,0 +1,151 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { renderHook, act, waitFor } from "@testing-library/react";
3
+ import type { ReactNode } from "react";
4
+ import { create } from "@bufbuild/protobuf";
5
+ import type { Stigmer } from "@stigmer/sdk";
6
+ import { ExecutionArtifactSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/artifact_pb";
7
+ import { ExecutionArtifactKind } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
8
+ import { StigmerContext } from "../../context";
9
+ import { useArtifactInspection } from "../useArtifactInspection";
10
+
11
+ function fileArtifact(name: string) {
12
+ return create(ExecutionArtifactSchema, {
13
+ name,
14
+ kind: ExecutionArtifactKind.FILE,
15
+ sizeBytes: 64n,
16
+ sandboxPath: `.stigmer/${name}`,
17
+ storageKey: `artifacts/aex_1/${name}`,
18
+ contentHash: "hash-1",
19
+ });
20
+ }
21
+
22
+ function dirArtifact(name: string) {
23
+ return create(ExecutionArtifactSchema, {
24
+ name,
25
+ kind: ExecutionArtifactKind.DIRECTORY,
26
+ sizeBytes: 512n,
27
+ sandboxPath: `.stigmer/${name}`,
28
+ storageKey: `artifacts/aex_1/${name}`,
29
+ entries: ["SKILL.md", "run.sh"],
30
+ });
31
+ }
32
+
33
+ function contentResult(text: string) {
34
+ return {
35
+ content: new TextEncoder().encode(text),
36
+ contentType: "text/plain",
37
+ truncated: false,
38
+ };
39
+ }
40
+
41
+ function wrapperFor(stigmer: Stigmer) {
42
+ return ({ children }: { children: ReactNode }) => (
43
+ <StigmerContext.Provider value={stigmer}>{children}</StigmerContext.Provider>
44
+ );
45
+ }
46
+
47
+ const writeText = vi.fn().mockResolvedValue(undefined);
48
+
49
+ beforeEach(() => {
50
+ writeText.mockClear();
51
+ vi.stubGlobal("navigator", { clipboard: { writeText } });
52
+ });
53
+
54
+ const AGENT_YAML = [
55
+ "apiVersion: agentic.stigmer.ai/v1",
56
+ "kind: Agent",
57
+ "metadata:",
58
+ " name: my-agent",
59
+ "spec: {}",
60
+ "",
61
+ ].join("\n");
62
+
63
+ describe("useArtifactInspection — content + copy", () => {
64
+ it("fetches text content and copies it to the clipboard on demand", async () => {
65
+ const getArtifactContent = vi.fn().mockResolvedValue(contentResult("hello world"));
66
+ const stigmer = { agentExecution: { getArtifactContent } } as unknown as Stigmer;
67
+
68
+ const { result } = renderHook(
69
+ () => useArtifactInspection(fileArtifact("notes.txt"), "aex_1", "acme"),
70
+ { wrapper: wrapperFor(stigmer) },
71
+ );
72
+
73
+ await waitFor(() => expect(result.current.content).toBe("hello world"));
74
+ expect(result.current.isDirectory).toBe(false);
75
+ expect(result.current.isDetected).toBe(false);
76
+ expect(result.current.ctaLabel).toBeNull();
77
+
78
+ act(() => {
79
+ result.current.copy();
80
+ });
81
+ expect(writeText).toHaveBeenCalledWith("hello world");
82
+ await waitFor(() => expect(result.current.copied).toBe(true));
83
+ });
84
+
85
+ it("does not fetch content for a directory artifact", () => {
86
+ const getArtifactContent = vi.fn().mockReturnValue(new Promise(() => {}));
87
+ const stigmer = { agentExecution: { getArtifactContent } } as unknown as Stigmer;
88
+
89
+ const { result } = renderHook(
90
+ () => useArtifactInspection(dirArtifact("skill-pack"), "aex_1", "acme"),
91
+ { wrapper: wrapperFor(stigmer) },
92
+ );
93
+
94
+ expect(result.current.isDirectory).toBe(true);
95
+ // Directory content is not fetched via the text-content RPC (skill
96
+ // detection uses its own entry-scoped fetch).
97
+ expect(
98
+ getArtifactContent.mock.calls.every(
99
+ (call) => call[0]?.entryPath !== undefined,
100
+ ),
101
+ ).toBe(true);
102
+ });
103
+ });
104
+
105
+ describe("useArtifactInspection — detection + apply", () => {
106
+ it("labels a detected Agent YAML and offers an Apply CTA", async () => {
107
+ const getArtifactContent = vi.fn().mockResolvedValue(contentResult(AGENT_YAML));
108
+ const stigmer = { agentExecution: { getArtifactContent } } as unknown as Stigmer;
109
+
110
+ const { result } = renderHook(
111
+ () => useArtifactInspection(fileArtifact("agent.yaml"), "aex_1", "acme"),
112
+ { wrapper: wrapperFor(stigmer) },
113
+ );
114
+
115
+ await waitFor(() => expect(result.current.isDetected).toBe(true));
116
+ expect(result.current.detectionLabel).toBe("Agent detected");
117
+ expect(result.current.ctaLabel).toBe("Apply to acme");
118
+ });
119
+
120
+ it("applies a detected Agent and fires onApplied with the result", async () => {
121
+ const getArtifactContent = vi.fn().mockResolvedValue(contentResult(AGENT_YAML));
122
+ const apply = vi.fn().mockResolvedValue({
123
+ metadata: { name: "my-agent", org: "acme", slug: "my-agent" },
124
+ });
125
+ const stigmer = {
126
+ agentExecution: { getArtifactContent },
127
+ agent: { apply },
128
+ } as unknown as Stigmer;
129
+ const onApplied = vi.fn();
130
+
131
+ const { result } = renderHook(
132
+ () =>
133
+ useArtifactInspection(fileArtifact("agent.yaml"), "aex_1", "acme", {
134
+ onApplied,
135
+ }),
136
+ { wrapper: wrapperFor(stigmer) },
137
+ );
138
+
139
+ await waitFor(() => expect(result.current.isDetected).toBe(true));
140
+
141
+ await act(async () => {
142
+ await result.current.apply();
143
+ });
144
+
145
+ expect(apply).toHaveBeenCalledTimes(1);
146
+ expect(apply.mock.calls[0][0].name).toBe("my-agent");
147
+ await waitFor(() => expect(result.current.applyResult?.kind).toBe("Agent"));
148
+ expect(onApplied).toHaveBeenCalledTimes(1);
149
+ expect(onApplied.mock.calls[0][0].name).toBe("my-agent");
150
+ });
151
+ });
@@ -83,3 +83,38 @@ describe("useCreateAgentExecution — executionConfig mapping", () => {
83
83
  expect(mockCreate.mock.calls[0][0].executionConfig).toBeUndefined();
84
84
  });
85
85
  });
86
+
87
+ describe("useCreateAgentExecution — supersede link (edit-and-resubmit)", () => {
88
+ it("maps supersedesExecutionId into the create call", async () => {
89
+ const { result } = renderHook(() => useCreateAgentExecution(), {
90
+ wrapper: createWrapper(makeMockClient()),
91
+ });
92
+
93
+ await act(async () => {
94
+ await result.current.create({
95
+ org: "acme",
96
+ sessionId: "ses-1",
97
+ message: "corrected message",
98
+ supersedesExecutionId: "aex-old",
99
+ });
100
+ });
101
+
102
+ expect(mockCreate.mock.calls[0][0].supersedesExecutionId).toBe("aex-old");
103
+ });
104
+
105
+ it("leaves supersedesExecutionId undefined for ordinary sends", async () => {
106
+ const { result } = renderHook(() => useCreateAgentExecution(), {
107
+ wrapper: createWrapper(makeMockClient()),
108
+ });
109
+
110
+ await act(async () => {
111
+ await result.current.create({
112
+ org: "acme",
113
+ sessionId: "ses-1",
114
+ message: "Hello",
115
+ });
116
+ });
117
+
118
+ expect(mockCreate.mock.calls[0][0].supersedesExecutionId).toBeUndefined();
119
+ });
120
+ });
@@ -242,12 +242,24 @@ export type { ApprovalContextValue, UseApprovalResult } from "./ApprovalContext.
242
242
  export { FileReviewContext, useFileReviewRowState } from "./FileReviewContext.js";
243
243
  export type { FileReviewContextValue } from "./FileReviewContext.js";
244
244
 
245
- export { ArtifactCard } from "./ArtifactCard.js";
246
- export type { ArtifactCardProps } from "./ArtifactCard.js";
245
+ export { ArtifactRow } from "./ArtifactRow.js";
246
+ export type { ArtifactRowProps } from "./ArtifactRow.js";
247
247
 
248
248
  export { ArtifactContentRenderer } from "./ArtifactContentRenderer.js";
249
249
  export type { ArtifactContentRendererProps } from "./ArtifactContentRenderer.js";
250
250
 
251
+ export { ArtifactContentBody } from "./ArtifactContentBody.js";
252
+ export type { ArtifactContentBodyProps } from "./ArtifactContentBody.js";
253
+
254
+ export { ArtifactDocument } from "./ArtifactDocument.js";
255
+ export type { ArtifactDocumentProps } from "./ArtifactDocument.js";
256
+
257
+ export { useArtifactInspection } from "./useArtifactInspection.js";
258
+ export type {
259
+ ArtifactInspection,
260
+ UseArtifactInspectionOptions,
261
+ } from "./useArtifactInspection.js";
262
+
251
263
  export { ArtifactPreviewContent, ArtifactPreviewModal } from "./ArtifactPreviewModal.js";
252
264
  export type { ArtifactPreviewContentProps, ArtifactPreviewModalProps } from "./ArtifactPreviewModal.js";
253
265
 
@@ -100,6 +100,11 @@ export interface UseArtifactContentReturn {
100
100
  * When the same file is overwritten during execution, the `storageKey` stays
101
101
  * stable but `contentHash` changes, triggering a re-fetch so the UI never
102
102
  * shows stale content. Pass `undefined` or omit for backwards compatibility.
103
+ * @param cacheKey - Optional cross-mount cache key (DD-014). When set, a remount
104
+ * with the same key renders the previously-fetched content instantly and
105
+ * refetches in the background (no skeleton flash) — used by the artifact
106
+ * document so switching back to a recently-viewed tab is instant. Omit for the
107
+ * default fetch-on-mount behavior (card / modal / plan callers are unchanged).
103
108
  *
104
109
  * @example
105
110
  * ```tsx
@@ -142,6 +147,7 @@ export function useArtifactContent(
142
147
  storageKey: string | null,
143
148
  entryPath?: string | null,
144
149
  contentHash?: string,
150
+ cacheKey?: string,
145
151
  ): UseArtifactContentReturn {
146
152
  const stigmer = useStigmer();
147
153
 
@@ -164,6 +170,7 @@ export function useArtifactContent(
164
170
  : null,
165
171
  [executionId, storageKey, entryPath, contentHash, stigmer],
166
172
  EMPTY_ARTIFACT,
173
+ cacheKey ? { cacheKey } : undefined,
167
174
  );
168
175
 
169
176
  return {
@@ -0,0 +1,252 @@
1
+ "use client";
2
+
3
+ import { useCallback, useMemo, useState } from "react";
4
+ import type { ExecutionArtifact } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/artifact_pb";
5
+ import { ExecutionArtifactKind } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
6
+ import { useArtifactContent } from "./useArtifactContent.js";
7
+ import { isTextArtifact } from "./artifact-utils.js";
8
+ import { useDetectStigmerResource } from "../library/useDetectStigmerResource.js";
9
+ import { useDetectSkillPackage } from "../library/useDetectSkillPackage.js";
10
+ import type { SkillPackageDetection } from "../library/detect-skill-package.js";
11
+ import {
12
+ useApplyResource,
13
+ type ApplyResourceResult,
14
+ } from "../library/useApplyResource.js";
15
+
16
+ const COPIED_FEEDBACK_MS = 2000;
17
+
18
+ /** Options for {@link useArtifactInspection}. */
19
+ export interface UseArtifactInspectionOptions {
20
+ /**
21
+ * Cross-mount cache key for the content fetch (DD-014). Set it so a remount
22
+ * with the same key renders the previously-fetched content instantly and
23
+ * refetches in the background — the artifact document passes it so switching
24
+ * back to a recently-viewed tab is instant. Omit for fetch-on-mount (the
25
+ * modal, which resets on every open).
26
+ */
27
+ readonly cacheKey?: string;
28
+ /**
29
+ * Called after a resource is successfully applied or a skill package pushed.
30
+ * The consumer uses it for post-apply behavior (toast, navigate to Library).
31
+ */
32
+ readonly onApplied?: (result: ApplyResourceResult) => void;
33
+ }
34
+
35
+ /**
36
+ * Everything a chrome (the modal action bar, the document toolbar, the content
37
+ * body) needs to inspect and act on one artifact: fetched content, resource
38
+ * detection, the Apply/Push action, and clipboard copy.
39
+ */
40
+ export interface ArtifactInspection {
41
+ /** Decoded text content, or `null` (directory / binary / loading / error). */
42
+ readonly content: string | null;
43
+ /** Server-detected content type, or `null`. */
44
+ readonly contentType: string | null;
45
+ /** Whether the fetched content was truncated by the server's size cap. */
46
+ readonly isTruncated: boolean;
47
+ /** `true` while the content request is in-flight (first load). */
48
+ readonly isLoading: boolean;
49
+ /** Content-fetch error, or `null`. */
50
+ readonly error: Error | null;
51
+ /** Re-fetch the artifact content. */
52
+ readonly refetch: () => void;
53
+
54
+ /** Whether the artifact is a directory (skill package candidate). */
55
+ readonly isDirectory: boolean;
56
+ /** Skill-package detection for directory artifacts. */
57
+ readonly skillDetection: SkillPackageDetection;
58
+
59
+ /** `true` when the artifact is a recognized Stigmer resource or skill. */
60
+ readonly isDetected: boolean;
61
+ /** `true` while detection is still resolving (content / skill fetch). */
62
+ readonly isDetecting: boolean;
63
+ /** Detection badge label (`"Agent detected"`, `"Skill · N files"`), or `null`. */
64
+ readonly detectionLabel: string | null;
65
+
66
+ /** Apply/Push CTA label (`"Apply to org"`, `"Push Skill to org"`), or `null`. */
67
+ readonly ctaLabel: string | null;
68
+ /** Apply the detected resource / push the detected skill. */
69
+ readonly apply: () => Promise<void>;
70
+ /** `true` while an apply/push is in-flight. */
71
+ readonly isApplying: boolean;
72
+ /** The successful apply result, or `null`. */
73
+ readonly applyResult: ApplyResourceResult | null;
74
+ /** Apply/push error, or `null`. */
75
+ readonly applyError: Error | null;
76
+
77
+ /** Copy the in-memory content to the clipboard. No-op without content. */
78
+ readonly copy: () => void;
79
+ /** `true` for a short window after a successful copy. */
80
+ readonly copied: boolean;
81
+ }
82
+
83
+ /**
84
+ * Headless behavior hook consolidating the artifact inspect-and-act pipeline
85
+ * that was previously inlined per artifact surface: content fetch,
86
+ * Agent/McpServer YAML detection, skill-package detection, the Apply/Push
87
+ * mutation, and in-memory clipboard copy.
88
+ *
89
+ * It is the single writer of this pipeline's derived state, consumed by every
90
+ * artifact chrome — the modal action bar and the editor-area
91
+ * `ArtifactDocument` toolbar (DD-003 headless-first). Because there is exactly
92
+ * one place computing `detectionLabel` / `ctaLabel` / the apply flow, the two
93
+ * surfaces cannot drift.
94
+ *
95
+ * All four underlying hooks are called unconditionally with null-gated
96
+ * arguments (their documented skip contract), so this composition is
97
+ * React-rules-clean regardless of the artifact kind.
98
+ *
99
+ * @param artifact - The artifact to inspect.
100
+ * @param executionId - Execution that produced it (content + skill fetching).
101
+ * @param org - Organization for the "Apply to [org]" / "Push Skill to [org]" CTA.
102
+ * @param options - {@link UseArtifactInspectionOptions}.
103
+ */
104
+ export function useArtifactInspection(
105
+ artifact: ExecutionArtifact,
106
+ executionId: string,
107
+ org: string,
108
+ options?: UseArtifactInspectionOptions,
109
+ ): ArtifactInspection {
110
+ const isDirectory = artifact.kind === ExecutionArtifactKind.DIRECTORY;
111
+ const canFetchContent = !isDirectory && isTextArtifact(artifact);
112
+
113
+ const {
114
+ content,
115
+ contentType,
116
+ isTruncated,
117
+ isLoading,
118
+ error,
119
+ refetch,
120
+ } = useArtifactContent(
121
+ canFetchContent ? executionId : null,
122
+ canFetchContent ? artifact.storageKey : null,
123
+ undefined,
124
+ artifact.contentHash || undefined,
125
+ options?.cacheKey,
126
+ );
127
+
128
+ const yamlDetection = useDetectStigmerResource(
129
+ canFetchContent ? content : null,
130
+ );
131
+
132
+ const { detection: skillDetection, isLoading: isSkillLoading } =
133
+ useDetectSkillPackage(
134
+ isDirectory ? artifact : null,
135
+ isDirectory ? executionId : null,
136
+ );
137
+
138
+ const isDetected = yamlDetection.detected || skillDetection.detected;
139
+ const isDetecting =
140
+ (canFetchContent && isLoading) || (isDirectory && isSkillLoading);
141
+
142
+ let detectionLabel: string | null = null;
143
+ if (yamlDetection.detected) {
144
+ detectionLabel = `${yamlDetection.displayName} detected`;
145
+ } else if (skillDetection.detected) {
146
+ const count = skillDetection.fileCount;
147
+ detectionLabel = `Skill \u00B7 ${count} ${count === 1 ? "file" : "files"}`;
148
+ }
149
+
150
+ let ctaLabel: string | null = null;
151
+ if (yamlDetection.detected) {
152
+ ctaLabel = `Apply to ${org}`;
153
+ } else if (skillDetection.detected) {
154
+ ctaLabel = `Push Skill to ${org}`;
155
+ }
156
+
157
+ // --- Apply / Push ---------------------------------------------------------
158
+
159
+ const { applyYamlResource, pushSkillPackage, isApplying, error: applyError, clearError } =
160
+ useApplyResource();
161
+ const [applyResult, setApplyResult] = useState<ApplyResourceResult | null>(
162
+ null,
163
+ );
164
+ const onApplied = options?.onApplied;
165
+
166
+ const apply = useCallback(async () => {
167
+ clearError();
168
+ try {
169
+ let result: ApplyResourceResult;
170
+ if (yamlDetection.detected && content) {
171
+ result = await applyYamlResource(content, org);
172
+ } else if (skillDetection.detected) {
173
+ result = await pushSkillPackage({
174
+ org,
175
+ executionId,
176
+ storageKey: artifact.storageKey,
177
+ });
178
+ } else {
179
+ return;
180
+ }
181
+ setApplyResult(result);
182
+ onApplied?.(result);
183
+ } catch {
184
+ // error state is owned by useApplyResource
185
+ }
186
+ }, [
187
+ yamlDetection.detected,
188
+ skillDetection.detected,
189
+ content,
190
+ org,
191
+ executionId,
192
+ artifact.storageKey,
193
+ applyYamlResource,
194
+ pushSkillPackage,
195
+ clearError,
196
+ onApplied,
197
+ ]);
198
+
199
+ // --- Copy -----------------------------------------------------------------
200
+
201
+ const [copied, setCopied] = useState(false);
202
+ const copy = useCallback(() => {
203
+ if (!content) return;
204
+ void navigator.clipboard.writeText(content).then(() => {
205
+ setCopied(true);
206
+ setTimeout(() => setCopied(false), COPIED_FEEDBACK_MS);
207
+ });
208
+ }, [content]);
209
+
210
+ return useMemo(
211
+ () => ({
212
+ content,
213
+ contentType,
214
+ isTruncated,
215
+ isLoading,
216
+ error,
217
+ refetch,
218
+ isDirectory,
219
+ skillDetection,
220
+ isDetected,
221
+ isDetecting,
222
+ detectionLabel,
223
+ ctaLabel,
224
+ apply,
225
+ isApplying,
226
+ applyResult,
227
+ applyError,
228
+ copy,
229
+ copied,
230
+ }),
231
+ [
232
+ content,
233
+ contentType,
234
+ isTruncated,
235
+ isLoading,
236
+ error,
237
+ refetch,
238
+ isDirectory,
239
+ skillDetection,
240
+ isDetected,
241
+ isDetecting,
242
+ detectionLabel,
243
+ ctaLabel,
244
+ apply,
245
+ isApplying,
246
+ applyResult,
247
+ applyError,
248
+ copy,
249
+ copied,
250
+ ],
251
+ );
252
+ }
@@ -93,6 +93,17 @@ export interface CreateAgentExecutionInput {
93
93
  * Populated by the drag-to-reference feature in SessionComposer.
94
94
  */
95
95
  readonly workspaceFileRefs?: string[];
96
+ /**
97
+ * ID of the execution this one supersedes via edit-and-resubmit.
98
+ *
99
+ * Set when the user stopped an in-flight turn, edited its message, and
100
+ * resubmitted. Chat threads hide the superseded execution so the edited
101
+ * message replaces the original in place; history surfaces keep the full
102
+ * record. Maps to `AgentExecutionSpec.supersedes_execution_id`.
103
+ *
104
+ * Display-level only — the runner does not rewind model context.
105
+ */
106
+ readonly supersedesExecutionId?: string;
96
107
  }
97
108
 
98
109
  /** Resolved output of {@link UseCreateAgentExecutionReturn.create}. */
@@ -199,6 +210,7 @@ export function useCreateAgentExecution(): UseCreateAgentExecutionReturn {
199
210
  runtimeEnv: input.runtimeEnv,
200
211
  attachments: input.attachments,
201
212
  workspaceFileRefs: input.workspaceFileRefs,
213
+ supersedesExecutionId: input.supersedesExecutionId,
202
214
  });
203
215
 
204
216
  return {
package/src/index.ts CHANGED
@@ -129,6 +129,7 @@ export {
129
129
  useSessionExecutions,
130
130
  useSessionConversation,
131
131
  useSessionArtifacts,
132
+ artifactKey,
132
133
  useSessionWriteBacks,
133
134
  useSessionFileChanges,
134
135
  useSessionUsage,
@@ -154,6 +155,7 @@ export {
154
155
  PlanStreamingDocument,
155
156
  PLAN_DOCUMENT_ENTRY_ID,
156
157
  PLAN_DOCUMENT_PATH,
158
+ ARTIFACT_DOCUMENT_ENTRY_ID,
157
159
  SetupTab,
158
160
  } from "./session/index.js";
159
161
  export type {
@@ -288,8 +290,11 @@ export {
288
290
  useApproval,
289
291
  FileReviewContext,
290
292
  useFileReviewRowState,
291
- ArtifactCard,
293
+ ArtifactRow,
292
294
  ArtifactContentRenderer,
295
+ ArtifactContentBody,
296
+ ArtifactDocument,
297
+ useArtifactInspection,
293
298
  ArtifactPreviewContent,
294
299
  ArtifactPreviewModal,
295
300
  ArtifactsWidget,
@@ -381,8 +386,12 @@ export type {
381
386
  ApprovalContextValue,
382
387
  UseApprovalResult,
383
388
  FileReviewContextValue,
384
- ArtifactCardProps,
389
+ ArtifactRowProps,
385
390
  ArtifactContentRendererProps,
391
+ ArtifactContentBodyProps,
392
+ ArtifactDocumentProps,
393
+ ArtifactInspection,
394
+ UseArtifactInspectionOptions,
386
395
  ArtifactRenderMode,
387
396
  ArtifactPreviewContentProps,
388
397
  ArtifactPreviewModalProps,