@xbzbing/dsh-git-panel 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.
@@ -0,0 +1,16 @@
1
+ import type { SnapshotDeps, GitPanelConfig } from './core.ts';
2
+ import type { GitAction, GitActionRequest, GitActionResult, GitErrorCode } from './types.ts';
3
+ /** A repository-relative path is safe when it stays inside the work tree. */
4
+ export declare function isSafePath(path: string): boolean;
5
+ interface CommandPlan {
6
+ readonly argv: readonly (readonly string[])[];
7
+ }
8
+ type PlanResult = CommandPlan | {
9
+ readonly error: GitErrorCode;
10
+ readonly message?: string;
11
+ };
12
+ /** Build the git command sequence for an action. */
13
+ export declare function planAction(action: GitAction, unborn: boolean): PlanResult;
14
+ /** Execute a management action, returning the fresh snapshot on success. */
15
+ export declare function runAction(deps: SnapshotDeps, config: GitPanelConfig, request: GitActionRequest): Promise<GitActionResult>;
16
+ export {};
@@ -0,0 +1,69 @@
1
+ import type { GitRunner } from './git.ts';
2
+ import type { GitChange, GitSnapshotResult } from './types.ts';
3
+ export interface GitPanelConfig {
4
+ readonly timeoutMs: number;
5
+ /** Per-command stdout cap; also the per-side image-diff payload cap. */
6
+ readonly maxBytes: number;
7
+ readonly maxChanges: number;
8
+ readonly refreshIntervalMs: number;
9
+ /** Whether the input-bar git marker pill is shown. */
10
+ readonly showInputPill: boolean;
11
+ }
12
+ export declare const DEFAULT_CONFIG: GitPanelConfig;
13
+ export declare function normalizeConfig(raw: unknown): GitPanelConfig;
14
+ /**
15
+ * Read a boolean config field, unwrapping a schemastery volatile reference
16
+ * (`{ get() }`) so a live-editable toggle reflects the latest value. Absent or
17
+ * unrecognized shapes fall back to the default.
18
+ */
19
+ export declare function readBool(value: unknown, fallback: boolean): boolean;
20
+ /** Host capabilities the snapshot needs, structurally injected. */
21
+ export interface SnapshotDeps {
22
+ readonly run: GitRunner;
23
+ readonly fs: {
24
+ realpath(path: string): Promise<string>;
25
+ stat(path: string): Promise<{
26
+ mtimeMs: number;
27
+ size: number;
28
+ }>;
29
+ /** Raw bytes (no encoding) — image sides for the image-diff query. */
30
+ readFile(path: string): Promise<Buffer>;
31
+ /** Best-effort unlink (force) — temp-blob cleanup. */
32
+ remove(path: string): Promise<void>;
33
+ };
34
+ readonly sessions: {
35
+ liveCwd(sessionId: string): string | undefined;
36
+ persistedMeta(sessionId: string): Promise<{
37
+ cwd?: string;
38
+ } | undefined>;
39
+ };
40
+ readonly signal?: AbortSignal;
41
+ /**
42
+ * Optional cwd→root cache, keyed by the resolved cwd. Resolving the work-tree
43
+ * root runs a `git rev-parse` + `realpath` on every call; sharing this map
44
+ * across a session's snapshot/query/run calls collapses that to one spawn per
45
+ * distinct cwd (a session's cwd is effectively stable).
46
+ */
47
+ readonly rootCache?: Map<string, string>;
48
+ }
49
+ export type WorkspaceResolution = {
50
+ readonly ok: true;
51
+ readonly root: string;
52
+ } | {
53
+ readonly ok: false;
54
+ readonly failure: GitSnapshotResult & {
55
+ ok: false;
56
+ };
57
+ };
58
+ /** Resolve the git work-tree root for a session's cwd. */
59
+ export declare function resolveWorkspace(deps: SnapshotDeps, sessionId: string): Promise<WorkspaceResolution>;
60
+ /** Run one git command; a spawn-level failure returns { failure }. */
61
+ export declare function runCommand(runner: GitRunner, argv: readonly string[], cwd: string, _label: string, signal?: AbortSignal): Promise<{
62
+ run: Awaited<ReturnType<GitRunner['run']>>;
63
+ } | {
64
+ failure: unknown;
65
+ }>;
66
+ /** Produce a full snapshot for a session. */
67
+ export declare function snapshotForSession(deps: SnapshotDeps, config: GitPanelConfig, sessionId: string): Promise<GitSnapshotResult>;
68
+ /** Max mtime among changed files (epoch ms), capped for large sets. */
69
+ export declare function maxChangeMtime(deps: SnapshotDeps, root: string, changes: readonly GitChange[], cap?: number): Promise<number | null>;
@@ -0,0 +1,62 @@
1
+ interface CollectDisposition {
2
+ readonly collect: {
3
+ readonly maxBytes: number;
4
+ readonly spill?: {
5
+ readonly maxBytes: number;
6
+ };
7
+ };
8
+ }
9
+ interface SpawnSpec {
10
+ readonly argv: readonly string[];
11
+ readonly cwd: string;
12
+ readonly stdio: {
13
+ readonly stdin: 'ignore';
14
+ readonly stdout: CollectDisposition;
15
+ readonly stderr: CollectDisposition;
16
+ };
17
+ readonly graceMs: number;
18
+ readonly signal?: AbortSignal;
19
+ }
20
+ interface OutputRead {
21
+ readonly text: string;
22
+ readonly lossy: boolean;
23
+ readonly spillPath?: string;
24
+ }
25
+ interface SpawnHandle {
26
+ readonly done: Promise<{
27
+ readonly exitCode: number | null;
28
+ readonly signal: NodeJS.Signals | null;
29
+ }>;
30
+ readonly collected: {
31
+ readonly stdout?: {
32
+ readFrom(fromByte: number): OutputRead;
33
+ };
34
+ readonly stderr?: {
35
+ readFrom(fromByte: number): OutputRead;
36
+ };
37
+ };
38
+ }
39
+ /** Minimal subprocess service face the adapter consumes. */
40
+ export interface SubprocessLike {
41
+ spawn(spec: SpawnSpec): SpawnHandle;
42
+ }
43
+ export interface GitRunResult {
44
+ readonly exitCode: number | null;
45
+ readonly stdout: string;
46
+ readonly stderr: string;
47
+ readonly timedOut: boolean;
48
+ readonly stdoutLossy: boolean;
49
+ }
50
+ export interface GitRunner {
51
+ run(argv: readonly string[], opts: {
52
+ readonly cwd: string;
53
+ readonly signal?: AbortSignal;
54
+ }): Promise<GitRunResult>;
55
+ }
56
+ /**
57
+ * Adapt the subprocess service into a `GitRunner` with a per-command timeout.
58
+ * A timed-out run resolves (never rejects) with `timedOut: true`; only
59
+ * spawn-level failures (e.g. git not installed) reject.
60
+ */
61
+ export declare function createGitRunner(subprocess: SubprocessLike, timeoutMs: number, maxBytes: number): GitRunner;
62
+ export {};
@@ -0,0 +1,45 @@
1
+ /**
2
+ * dsh-git-panel host half: Cordis + typert Remote service.
3
+ *
4
+ * `GitPanelService` binds the `gitPanel` namespace and exposes three @Remote
5
+ * endpoints (snapshot / run / query) that delegate to the framework-neutral
6
+ * command layer. Host services (subprocess / sessions / sessionPersistence)
7
+ * are adapted into a structural `SnapshotDeps` face.
8
+ */
9
+ import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
10
+ import type { Context } from '@deepseek-ai/cordis';
11
+ import Schema from '@deepseek-ai/schemastery';
12
+ import type { GitActionRequest, GitActionResult, GitQueryRequest, GitQueryResponse, GitSnapshotRequest, GitSnapshotResult, GitVersionInfo, GitVersionRequest } from './types.ts';
13
+ export type { GitSnapshot, GitSnapshotResult, GitSnapshotRequest, GitFailure, GitCommit, GraphCommit, GitRef, GitChange, GitChangeStatus, GitAction, GitActionRequest, GitActionResult, GitErrorCode, GitQuery, GitQueryRequest, GitQueryResponse, GitQueryResult, GitBranch, GitFileStat, WorktreeStats, GitVersionRequest, GitVersionInfo, } from './types.ts';
14
+ export { normalizeConfig, DEFAULT_CONFIG, snapshotForSession, resolveWorkspace } from './core.ts';
15
+ export { createGitRunner } from './git.ts';
16
+ export { parseStatus, parseGraphLog, parseBranches, parseNameStatus, sumNumstat } from './parser.ts';
17
+ export { isSafePath, planAction, runAction } from './actions.ts';
18
+ export { runQuery } from './queries.ts';
19
+ export { readVersionInfo, checkLatestVersion, compareVersions, parseRepository } from './version.ts';
20
+ export declare class GitPanelService extends TypertRemoteService {
21
+ static inject: string[];
22
+ /**
23
+ * Config schema surfaced on the plugin detail page. Only `showInputPill` is
24
+ * `.volatile()`, so the settings host renders it as a live-editable toggle;
25
+ * the operational limits stay profile-only and out of the UI form.
26
+ */
27
+ static Config: Schema<Schemastery.ObjectS<NoInfer<{
28
+ showInputPill: Schema<boolean, boolean, "volatile-defined">;
29
+ }>>, Schemastery.ObjectT<NoInfer<{
30
+ showInputPill: Schema<boolean, boolean, "volatile-defined">;
31
+ }>>, "plain">;
32
+ private readonly deps;
33
+ private config;
34
+ private readonly rawConfig;
35
+ constructor(ctx: Context, config: unknown);
36
+ private buildDeps;
37
+ snapshot(request: GitSnapshotRequest, signal?: AbortSignal): Promise<GitSnapshotResult>;
38
+ run(request: GitActionRequest, signal?: AbortSignal): Promise<GitActionResult>;
39
+ query(request: GitQueryRequest, signal?: AbortSignal): Promise<GitQueryResponse>;
40
+ version(request: GitVersionRequest): Promise<GitVersionInfo>;
41
+ /** Re-read config so a live-edited volatile field (showInputPill) is current. */
42
+ private liveConfig;
43
+ private withSignal;
44
+ }
45
+ export default GitPanelService;