@dsh-stack/tweak-fork-undo 0.0.0-stage → 0.1.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.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # tweak-fork-undo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Fork-based session undo/redo: /undo and /redo fork a new session from an earlier logged boundary.
4
+
5
+ An extension of the `tweaks` settings surface, split out of the bundled `tweaks` package.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * tweak-fork-undo: fork-based undo/redo. `/undo` `/redo` fork a new session
3
+ * from an earlier logged boundary via `ctx.sessions.create`.
4
+ * @module tweak-fork-undo/fork-undo
5
+ */
6
+ import type { Context } from "@deepseek-ai/cordis";
7
+ import type { SessionEvent } from "@deepseek-ai/dsh-session";
8
+ /** Register the fork-based `/undo` and `/redo` commands. Returns the inject fiber. */
9
+ export declare function installForkUndo(ctx: Context): unknown;
10
+ /** Fork a new session from an earlier/later message boundary in the log. */
11
+ export declare function forkSession(sessions: {
12
+ create(id?: string, options?: {
13
+ seed?: readonly SessionEvent[];
14
+ }): unknown;
15
+ }, agent: {
16
+ session: {
17
+ snapshotEvents(): readonly SessionEvent[];
18
+ };
19
+ }, direction: -1 | 1): {
20
+ kind: "success";
21
+ text: string;
22
+ } | {
23
+ kind: "error";
24
+ text: string;
25
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * tweak-fork-undo: fork-based undo/redo. `/undo` `/redo` fork a new session
3
+ * from an earlier logged boundary via `ctx.sessions.create`.
4
+ * @module tweak-fork-undo/fork-undo
5
+ */
6
+ /** Register the fork-based `/undo` and `/redo` commands. Returns the inject fiber. */
7
+ export function installForkUndo(ctx) {
8
+ return ctx.inject(["commands", "sessions"], (commandCtx) => {
9
+ const disposers = [];
10
+ /**
11
+ * Registers commands to fork sessions in either direction (-1 for undo, 1 for redo).
12
+ *
13
+ * @param name - The name of the command.
14
+ * @param description - A description of the command's purpose.
15
+ * @param direction - Direction to fork the session (-1 for undo, 1 for redo).
16
+ *
17
+ * @returns Nothing on success, disposes of command registration on failure.
18
+ */
19
+ const make = (name, description, direction) => {
20
+ disposers.push(commandCtx.commands.register({
21
+ name,
22
+ description,
23
+ handler: (invocation) => forkSession(commandCtx.sessions, invocation.agent, direction),
24
+ }));
25
+ };
26
+ make("undo", "Fork this session from the previous message boundary", -1);
27
+ make("redo", "Fork this session from the latest message boundary", 1);
28
+ return () => {
29
+ for (const dispose of disposers)
30
+ dispose();
31
+ };
32
+ });
33
+ }
34
+ /** Fork a new session from an earlier/later message boundary in the log. */
35
+ export function forkSession(sessions, agent, direction) {
36
+ const events = agent.session.snapshotEvents();
37
+ if (events.length === 0)
38
+ return { kind: "error", text: "no events to fork from" };
39
+ const boundaries = [];
40
+ events.forEach((event, index) => {
41
+ if (event.type === "user/message")
42
+ boundaries.push(index);
43
+ });
44
+ const target = direction === -1
45
+ ? boundaries.length > 0
46
+ ? boundaries[boundaries.length - 1]
47
+ : 0
48
+ : events.length;
49
+ const seed = events.slice(0, target);
50
+ sessions.create(undefined, { seed });
51
+ return {
52
+ kind: "success",
53
+ text: `${direction === -1 ? "undo" : "redo"}: forked ${seed.length} events into a new session`,
54
+ };
55
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `tweak-fork-undo`: fork-based session undo/redo — the `/undo` `/redo`
3
+ * commands plus their `tweak-fork-undo` settings section. Split out of the
4
+ * bundled `tweaks` package.
5
+ * @module tweak-fork-undo
6
+ */
7
+ import type { Context } from "@deepseek-ai/cordis";
8
+ import type z from "@deepseek-ai/schemastery";
9
+ import { type ForkUndoConfig as ForkUndoConfigType } from "./settings.js";
10
+ export { NS_FORK_UNDO, ForkUndoConfig } from "./settings.js";
11
+ export type { ForkUndoConfig as ForkUndoConfigType } from "./settings.js";
12
+ export { forkSession, installForkUndo } from "./fork-undo.js";
13
+ export declare const name = "tweak-fork-undo";
14
+ export declare const inject: string[];
15
+ /** The fork-undo extension config: the fork-undo section itself. */
16
+ export type Config = ForkUndoConfigType;
17
+ export declare const Config: z<Config>;
18
+ /**
19
+ * Declares this plugin's own settings page and installs the fork-undo commands.
20
+ *
21
+ * Since 0.2.0 no form is registered: the settings service projects the volatile
22
+ * Config fields of the active profile's entries, so this plugin's own
23
+ * `ForkUndoConfig` is its form and its namespace is this plugin's entry id. All
24
+ * this plugin must declare is that it ships its own page for that form. The
25
+ * `/undo` `/redo` commands are then registered only when `config.enabled` is
26
+ * true.
27
+ *
28
+ * @param ctx - The context in which to declare the settings page and install the commands.
29
+ * @param config - The fork-undo config; `enabled` gates the command registration.
30
+ */
31
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `tweak-fork-undo`: fork-based session undo/redo — the `/undo` `/redo`
3
+ * commands plus their `tweak-fork-undo` settings section. Split out of the
4
+ * bundled `tweaks` package.
5
+ * @module tweak-fork-undo
6
+ */
7
+ import { declareCustomSettingsPage } from "@dsh-stack/plugin-kit";
8
+ import { installForkUndo } from "./fork-undo.js";
9
+ import { ForkUndoConfig } from "./settings.js";
10
+ export { NS_FORK_UNDO, ForkUndoConfig } from "./settings.js";
11
+ export { forkSession, installForkUndo } from "./fork-undo.js";
12
+ export const name = "tweak-fork-undo";
13
+ export const inject = [];
14
+ export const Config = ForkUndoConfig;
15
+ /**
16
+ * Declares this plugin's own settings page and installs the fork-undo commands.
17
+ *
18
+ * Since 0.2.0 no form is registered: the settings service projects the volatile
19
+ * Config fields of the active profile's entries, so this plugin's own
20
+ * `ForkUndoConfig` is its form and its namespace is this plugin's entry id. All
21
+ * this plugin must declare is that it ships its own page for that form. The
22
+ * `/undo` `/redo` commands are then registered only when `config.enabled` is
23
+ * true.
24
+ *
25
+ * @param ctx - The context in which to declare the settings page and install the commands.
26
+ * @param config - The fork-undo config; `enabled` gates the command registration.
27
+ */
28
+ export function apply(ctx, config) {
29
+ const session = { enabled: config?.enabled ?? true };
30
+ declareCustomSettingsPage(ctx);
31
+ if (session.enabled)
32
+ void installForkUndo(ctx);
33
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * tweak-fork-undo settings: the fork-based undo/redo section schema.
3
+ * @module tweak-fork-undo/settings
4
+ */
5
+ import z from "@deepseek-ai/schemastery";
6
+ /** Namespace of the fork-undo section — this plugin's own Loader entry id. */
7
+ export declare const NS_FORK_UNDO: import("@dsh-stack/plugin-kit").SettingsNamespace;
8
+ /** Fork-undo knobs. */
9
+ export interface ForkUndoConfig {
10
+ /** Whether `/undo` `/redo` fork commands are registered. */
11
+ enabled: boolean;
12
+ }
13
+ export declare const ForkUndoConfig: z<ForkUndoConfig>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * tweak-fork-undo settings: the fork-based undo/redo section schema.
3
+ * @module tweak-fork-undo/settings
4
+ */
5
+ import z from "@deepseek-ai/schemastery";
6
+ import { settingsNamespace } from "@dsh-stack/plugin-kit";
7
+ /** Namespace of the fork-undo section — this plugin's own Loader entry id. */
8
+ export const NS_FORK_UNDO = settingsNamespace("tweak-fork-undo");
9
+ export const ForkUndoConfig = z.object({
10
+ enabled: z.boolean().default(true),
11
+ });
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@dsh-stack/tweak-fork-undo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Fork-based session undo/redo: /undo and /redo fork a new session from an earlier logged boundary.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "default": "./lib/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "lib",
17
+ "README.md",
18
+ "package.json",
19
+ "stack.json"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "stack": {
25
+ "kind": "plugin",
26
+ "id": "stack.tweaks.fork-undo"
27
+ },
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.json",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit",
31
+ "test": "node check-plugin.mjs"
32
+ },
33
+ "peerDependencies": {
34
+ "@deepseek-ai/cordis": "^4.0.1",
35
+ "@deepseek-ai/schemastery": "*",
36
+ "@deepseek-ai/dsh-settings": "0.2.0-rc.2",
37
+ "@deepseek-ai/dsh-commands": "0.2.0-rc.2",
38
+ "@deepseek-ai/dsh-session": "0.2.0-rc.2"
39
+ },
40
+ "dependencies": {
41
+ "@dsh-stack/plugin-kit": "0.1.1"
42
+ },
43
+ "devDependencies": {
44
+ "typescript": "^6.0.3",
45
+ "@deepseek-ai/cordis": "^4.0.1",
46
+ "@deepseek-ai/schemastery": "*",
47
+ "@deepseek-ai/dsh-settings": "0.2.0-rc.2",
48
+ "@deepseek-ai/dsh-commands": "0.2.0-rc.2",
49
+ "@deepseek-ai/dsh-session": "0.2.0-rc.2"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/marius-patrik/dsh-stack.git",
54
+ "directory": "plugins/tweak-fork-undo"
55
+ }
56
+ }
package/stack.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "stack.tweaks.fork-undo",
3
+ "name": "@dsh-stack/tweak-fork-undo",
4
+ "version": "0.1.1",
5
+ "kind": "plugin",
6
+ "description": "Fork-based session undo/redo: /undo and /redo fork a new session from an earlier logged boundary.",
7
+ "files": ["lib", "README.md", "package.json", "stack.json"],
8
+ "dependencies": ["stack.library.plugin-kit"],
9
+ "optionalDependencies": []
10
+ }