@pragma-sh/scratchpad 0.1.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 ADDED
@@ -0,0 +1,24 @@
1
+ # @pragma-sh/scratchpad
2
+
3
+ Interactive components for Pragma scratchpads. Part of [Pragma](https://github.com/pragma-sh/pragma) — a desktop workspace for
4
+ running persistent, worktree-scoped coding agents.
5
+
6
+ The browser-safe API bundled into an agent-authored MDX scratchpad: ask the user
7
+ a question, review a diff, show live agent progress, and prompt the attached
8
+ agent back. Re-exports `@pragma-sh/sdk`.
9
+
10
+ ```mdx
11
+ import { AskQuestion } from "@pragma-sh/scratchpad/ui";
12
+
13
+ <AskQuestion question="Which auth strategy?" options={[{ label: "JWT" }]} />
14
+ ```
15
+
16
+ Components render against the desktop's theme variables, so they follow whatever
17
+ theme the user has set. Presentational primitives live under
18
+ `@pragma-sh/scratchpad/ui/primitives`.
19
+
20
+ Docs: <https://pragma-app.sh/docs/user-guide/scratchpads>
21
+
22
+ ## License
23
+
24
+ AGPL-3.0-only. See [LICENSE](https://github.com/pragma-sh/pragma/blob/main/LICENSE).
package/dist/index.cjs ADDED
@@ -0,0 +1,96 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __reExport = (target, mod, secondTarget) => {
9
+ var keys = __getOwnPropNames(mod);
10
+ for (let key of keys)
11
+ if (!__hasOwnProp.call(target, key) && key !== "default")
12
+ __defProp(target, key, {
13
+ get: __accessProp.bind(mod, key),
14
+ enumerable: true
15
+ });
16
+ if (secondTarget) {
17
+ for (let key of keys)
18
+ if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
19
+ __defProp(secondTarget, key, {
20
+ get: __accessProp.bind(mod, key),
21
+ enumerable: true
22
+ });
23
+ return secondTarget;
24
+ }
25
+ };
26
+ var __toCommonJS = (from) => {
27
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
28
+ if (entry)
29
+ return entry;
30
+ entry = __defProp({}, "__esModule", { value: true });
31
+ if (from && typeof from === "object" || typeof from === "function") {
32
+ for (var key of __getOwnPropNames(from))
33
+ if (!__hasOwnProp.call(entry, key))
34
+ __defProp(entry, key, {
35
+ get: __accessProp.bind(from, key),
36
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
37
+ });
38
+ }
39
+ __moduleCache.set(from, entry);
40
+ return entry;
41
+ };
42
+ var __moduleCache;
43
+ var __returnValue = (v) => v;
44
+ function __exportSetter(name, newValue) {
45
+ this[name] = __returnValue.bind(null, newValue);
46
+ }
47
+ var __export = (target, all) => {
48
+ for (var name in all)
49
+ __defProp(target, name, {
50
+ get: all[name],
51
+ enumerable: true,
52
+ configurable: true,
53
+ set: __exportSetter.bind(all, name)
54
+ });
55
+ };
56
+
57
+ // src/index.ts
58
+ var exports_src = {};
59
+ __export(exports_src, {
60
+ scratchpadBridge: () => scratchpadBridge,
61
+ promptAgent: () => promptAgent
62
+ });
63
+ module.exports = __toCommonJS(exports_src);
64
+ __reExport(exports_src, require("@pragma-sh/sdk"), module.exports);
65
+ function bridge() {
66
+ const value = globalThis.pragmaScratchpad;
67
+ if (!value) {
68
+ throw new Error("@pragma-sh/scratchpad can only prompt agents inside a Pragma scratchpad");
69
+ }
70
+ return value;
71
+ }
72
+ function scratchpadBridge() {
73
+ return bridge();
74
+ }
75
+ async function promptAgent(text, options = {}) {
76
+ const value = text.trim();
77
+ if (!value)
78
+ return false;
79
+ const host = bridge();
80
+ const firstResult = await host.promptAgent(value);
81
+ if (firstResult === "sent")
82
+ return true;
83
+ if (firstResult === "cancelled")
84
+ return false;
85
+ const attach = () => host.requestAgentAttachment();
86
+ const customResult = await options.onMissingAgent?.({ text: value, attach });
87
+ const attached = options.onMissingAgent ? customResult === true : await attach();
88
+ if (!attached)
89
+ return false;
90
+ const retryResult = await host.promptAgent(value);
91
+ if (retryResult === "sent")
92
+ return true;
93
+ if (retryResult === "cancelled")
94
+ return false;
95
+ throw new Error("Selected agent tab is no longer available");
96
+ }
@@ -0,0 +1,46 @@
1
+ export * from "@pragma-sh/sdk";
2
+ /** Status rendered by scratchpad progress components. */
3
+ type ScratchpadAgentStatus = "running" | "attention" | "done" | "cleared";
4
+ /** One attached or explicitly tracked agent tab. */
5
+ interface ScratchpadAgentProgress {
6
+ tabId: string;
7
+ title?: string;
8
+ agent?: string;
9
+ status: ScratchpadAgentStatus;
10
+ }
11
+ /** Read-only host rendering of one worktree-scoped whiteboard. */
12
+ interface ScratchpadWhiteboardSnapshot {
13
+ id: string;
14
+ title: string;
15
+ version: number;
16
+ dataUrl: string;
17
+ }
18
+ /** Host bridge installed only inside a rendered Pragma scratchpad. */
19
+ interface ScratchpadBridge {
20
+ /** Delivers text, or reports a missing attachment or reader cancellation. */
21
+ promptAgent(text: string): Promise<"sent" | "missing-agent" | "cancelled">;
22
+ requestAgentAttachment(): Promise<boolean>;
23
+ subscribeAgentProgress(tabIds: readonly string[], listener: (progress: readonly ScratchpadAgentProgress[]) => void): () => void;
24
+ /** Returns a fresh PNG only when the board changed since `knownVersion`. */
25
+ getWhiteboardSnapshot(id: string, knownVersion?: number, dark?: boolean): Promise<ScratchpadWhiteboardSnapshot | null>;
26
+ /** Opens the board in the host's interactive editor when available. */
27
+ openWhiteboard?(id: string): Promise<void>;
28
+ }
29
+ /** Context passed when a scratchpad action has no attached agent tab. */
30
+ interface MissingAgentContext {
31
+ text: string;
32
+ attach(): Promise<boolean>;
33
+ }
34
+ /** Options for {@link promptAgent}. */
35
+ interface PromptAgentOptions {
36
+ onMissingAgent?: (context: MissingAgentContext) => void | boolean | Promise<void | boolean>;
37
+ }
38
+ /** Returns scratchpad host bridge for UI bindings. */
39
+ declare function scratchpadBridge(): ScratchpadBridge;
40
+ /**
41
+ * Sends text to attached agent tab. Missing attachment opens host picker by default;
42
+ * `onMissingAgent` can replace that behavior for one call. Returns false when
43
+ * user cancels sending or attachment without delivering a message.
44
+ */
45
+ declare function promptAgent(text: string, options?: PromptAgentOptions): Promise<boolean>;
46
+ export { scratchpadBridge, promptAgent, ScratchpadWhiteboardSnapshot, ScratchpadBridge, ScratchpadAgentStatus, ScratchpadAgentProgress, PromptAgentOptions, MissingAgentContext };
@@ -0,0 +1,46 @@
1
+ export * from "@pragma-sh/sdk";
2
+ /** Status rendered by scratchpad progress components. */
3
+ type ScratchpadAgentStatus = "running" | "attention" | "done" | "cleared";
4
+ /** One attached or explicitly tracked agent tab. */
5
+ interface ScratchpadAgentProgress {
6
+ tabId: string;
7
+ title?: string;
8
+ agent?: string;
9
+ status: ScratchpadAgentStatus;
10
+ }
11
+ /** Read-only host rendering of one worktree-scoped whiteboard. */
12
+ interface ScratchpadWhiteboardSnapshot {
13
+ id: string;
14
+ title: string;
15
+ version: number;
16
+ dataUrl: string;
17
+ }
18
+ /** Host bridge installed only inside a rendered Pragma scratchpad. */
19
+ interface ScratchpadBridge {
20
+ /** Delivers text, or reports a missing attachment or reader cancellation. */
21
+ promptAgent(text: string): Promise<"sent" | "missing-agent" | "cancelled">;
22
+ requestAgentAttachment(): Promise<boolean>;
23
+ subscribeAgentProgress(tabIds: readonly string[], listener: (progress: readonly ScratchpadAgentProgress[]) => void): () => void;
24
+ /** Returns a fresh PNG only when the board changed since `knownVersion`. */
25
+ getWhiteboardSnapshot(id: string, knownVersion?: number, dark?: boolean): Promise<ScratchpadWhiteboardSnapshot | null>;
26
+ /** Opens the board in the host's interactive editor when available. */
27
+ openWhiteboard?(id: string): Promise<void>;
28
+ }
29
+ /** Context passed when a scratchpad action has no attached agent tab. */
30
+ interface MissingAgentContext {
31
+ text: string;
32
+ attach(): Promise<boolean>;
33
+ }
34
+ /** Options for {@link promptAgent}. */
35
+ interface PromptAgentOptions {
36
+ onMissingAgent?: (context: MissingAgentContext) => void | boolean | Promise<void | boolean>;
37
+ }
38
+ /** Returns scratchpad host bridge for UI bindings. */
39
+ declare function scratchpadBridge(): ScratchpadBridge;
40
+ /**
41
+ * Sends text to attached agent tab. Missing attachment opens host picker by default;
42
+ * `onMissingAgent` can replace that behavior for one call. Returns false when
43
+ * user cancels sending or attachment without delivering a message.
44
+ */
45
+ declare function promptAgent(text: string, options?: PromptAgentOptions): Promise<boolean>;
46
+ export { scratchpadBridge, promptAgent, ScratchpadWhiteboardSnapshot, ScratchpadBridge, ScratchpadAgentStatus, ScratchpadAgentProgress, PromptAgentOptions, MissingAgentContext };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ // src/index.ts
2
+ export * from "@pragma-sh/sdk";
3
+ function bridge() {
4
+ const value = globalThis.pragmaScratchpad;
5
+ if (!value) {
6
+ throw new Error("@pragma-sh/scratchpad can only prompt agents inside a Pragma scratchpad");
7
+ }
8
+ return value;
9
+ }
10
+ function scratchpadBridge() {
11
+ return bridge();
12
+ }
13
+ async function promptAgent(text, options = {}) {
14
+ const value = text.trim();
15
+ if (!value)
16
+ return false;
17
+ const host = bridge();
18
+ const firstResult = await host.promptAgent(value);
19
+ if (firstResult === "sent")
20
+ return true;
21
+ if (firstResult === "cancelled")
22
+ return false;
23
+ const attach = () => host.requestAgentAttachment();
24
+ const customResult = await options.onMissingAgent?.({ text: value, attach });
25
+ const attached = options.onMissingAgent ? customResult === true : await attach();
26
+ if (!attached)
27
+ return false;
28
+ const retryResult = await host.promptAgent(value);
29
+ if (retryResult === "sent")
30
+ return true;
31
+ if (retryResult === "cancelled")
32
+ return false;
33
+ throw new Error("Selected agent tab is no longer available");
34
+ }
35
+ export {
36
+ scratchpadBridge,
37
+ promptAgent
38
+ };