dsh-live-teams 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.
Files changed (69) hide show
  1. package/LICENSE +176 -0
  2. package/NOTICE +11 -0
  3. package/README.md +85 -0
  4. package/cordis.patch.yml +25 -0
  5. package/lib/binding.d.ts +18 -0
  6. package/lib/binding.js +42 -0
  7. package/lib/changed-paths.d.ts +26 -0
  8. package/lib/changed-paths.js +69 -0
  9. package/lib/client.js +6753 -0
  10. package/lib/command-queue.d.ts +60 -0
  11. package/lib/command-queue.js +185 -0
  12. package/lib/compatibility.js +109 -0
  13. package/lib/context-provider.d.ts +110 -0
  14. package/lib/context-provider.js +249 -0
  15. package/lib/dispatch.d.ts +174 -0
  16. package/lib/dispatch.js +624 -0
  17. package/lib/errors.d.ts +36 -0
  18. package/lib/errors.js +103 -0
  19. package/lib/git-artifacts.d.ts +50 -0
  20. package/lib/git-artifacts.js +242 -0
  21. package/lib/index.d.ts +14 -0
  22. package/lib/index.js +14 -0
  23. package/lib/mailbox.d.ts +274 -0
  24. package/lib/mailbox.js +721 -0
  25. package/lib/member-tools.d.ts +57 -0
  26. package/lib/member-tools.js +1265 -0
  27. package/lib/migrations.d.ts +17 -0
  28. package/lib/migrations.js +47 -0
  29. package/lib/plugin.d.ts +106 -0
  30. package/lib/plugin.js +1003 -0
  31. package/lib/roles.d.ts +35 -0
  32. package/lib/roles.js +284 -0
  33. package/lib/routes.d.ts +586 -0
  34. package/lib/routes.js +2816 -0
  35. package/lib/scope.d.ts +62 -0
  36. package/lib/scope.js +133 -0
  37. package/lib/session-bridge.d.ts +76 -0
  38. package/lib/session-bridge.js +147 -0
  39. package/lib/session-title.js +35 -0
  40. package/lib/storage.d.ts +9 -0
  41. package/lib/storage.js +65 -0
  42. package/lib/task-store.d.ts +729 -0
  43. package/lib/task-store.js +2205 -0
  44. package/lib/team-store.d.ts +216 -0
  45. package/lib/team-store.js +765 -0
  46. package/lib/tree-snapshot.d.ts +28 -0
  47. package/lib/tree-snapshot.js +80 -0
  48. package/lib/types/client/TeamView.d.ts +26 -0
  49. package/lib/types/client/TeamView.dom.test.d.ts +1 -0
  50. package/lib/types/client/api.d.ts +522 -0
  51. package/lib/types/client/api.test.d.ts +1 -0
  52. package/lib/types/client/attention.d.ts +65 -0
  53. package/lib/types/client/attention.test.d.ts +1 -0
  54. package/lib/types/client/index.d.ts +31 -0
  55. package/lib/types/client/locales.d.ts +577 -0
  56. package/lib/types/client/member-name.d.ts +14 -0
  57. package/lib/types/client/member-name.test.d.ts +1 -0
  58. package/lib/types/client/roster.d.ts +26 -0
  59. package/lib/types/client/roster.test.d.ts +1 -0
  60. package/lib/types/client/styles.d.ts +3 -0
  61. package/package.json +104 -0
  62. package/roles/builder.md +40 -0
  63. package/roles/delegate.md +36 -0
  64. package/roles/lead.md +46 -0
  65. package/roles/oracle.md +36 -0
  66. package/roles/researcher.md +37 -0
  67. package/roles/reviewer.md +45 -0
  68. package/roles/scout.md +36 -0
  69. package/roles/verifier.md +36 -0
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1,11 @@
1
+ dsh-live-teams
2
+ Copyright 2026
3
+
4
+ This product includes software adapted from dsh-context v0.52.1
5
+ (https://github.com/bowenliang123/dsh-context), Copyright 2025 bowenliang123,
6
+ licensed under the Apache License, Version 2.0.
7
+
8
+ The Team tab's card geometry, type scale and interaction patterns are transcribed
9
+ and modified from that project. The coordination model, the durable task store, the
10
+ dispatcher, the review transaction and the Git-bound submission flow are original
11
+ to dsh-live-teams.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # dsh-live-teams
2
+
3
+ Host half of DSH Live Teams.
4
+
5
+ The Team tab's card geometry, type scale and interaction patterns are adapted from
6
+ [dsh-context](https://github.com/bowenliang123/dsh-context) v0.52.1 by bowenliang123,
7
+ Copyright 2025, under the Apache License 2.0; the implementation is transcribed and
8
+ modified for dsh-live-teams.
9
+
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ dsh plugin --profile <profile> add dsh-live-teams
15
+ ```
16
+
17
+ Then enable it in that profile's `cordis.patch.yml` row (`DSH_LIVE_TEAMS=1`) and restart DSH. From a
18
+ checkout instead of the registry:
19
+
20
+ ```bash
21
+ dsh plugin --profile <profile> add github:Gdenich/dsh-live-teams
22
+ ```
23
+
24
+ Requirements: DSH Desktop 0.1.5-rc.1 or newer. The plugin checks the host when it mounts and turns
25
+ the team off with a readable reason if a required service is missing, so a DSH update cannot leave it
26
+ half-working. Supported releases are declared in `package.json` under `dsh.compatibility.dshReleases`.
27
+
28
+ What it does today: durable workspace-owned team state; a narrow Session port; a
29
+ deduplicating command queue; the Session-scoped context provider; tasks with attempts,
30
+ declared paths, review and acceptance; a reconciling dispatcher that starts what the lead
31
+ assigned and shows silence instead of guessing; Git-bound submissions whose review is a
32
+ commit range and whose integration is a compare-and-swap; and a human task surface in the
33
+ panel that creates, edits and releases work directly. The decisions behind each are in
34
+ `docs/decisions/` (ADR 0001–0012) and the live evidence in
35
+ `docs/implementation/pilot-findings.md`.
36
+
37
+ Mounting is opt-in through this package's Cordis patch. The row is disabled unless the
38
+ composition sets `DSH_LIVE_TEAMS=1`, and enabling it without a workspace path fails
39
+ loudly instead of running half-wired.
40
+
41
+ ## Layout
42
+
43
+ TypeScript sources live in `src/`; `lib/` is the build output and is not edited by hand.
44
+ The package follows the first-party DSH conventions: ESM `lib/<entry>.js`, declarations
45
+ next to it, `exports` with `types`/`default` pairs, `files`, peer dependencies on the
46
+ Harness packages, and `dsh.bundle.patch`.
47
+
48
+ The build is unbundled on purpose: each entry is self-contained, so no hashed shared
49
+ chunk can fall outside the published `files` list, and `lib/` mirrors `src/`.
50
+
51
+ ## Modules
52
+
53
+ | Module | Responsibility |
54
+ |---|---|
55
+ | `errors.ts` | Domain taxonomy, platform error translation, audit-only detail |
56
+ | `storage.ts` | Atomic publish (temp file, `fsync`, `rename`, directory `fsync`) and a process-local lock |
57
+ | `team-store.ts` | Team state under `<workspace>/.dsh-live-teams`, revision CAS, `bindingGeneration`, tolerant `events.jsonl` |
58
+ | `session-bridge.ts` | The eight-method Session port from the architecture document §9 |
59
+ | `command-queue.ts` | Durable admission, semantic deduplication, generation fencing, retry |
60
+ | `context-provider.ts` | Session-scoped membership context for `systemPrompt.context(...)` |
61
+
62
+ ## Invariants enforced here
63
+
64
+ 1. Member identity, Session identity, role and model route are independent values.
65
+ 2. Every plugin-originated command is admitted by `command-queue` before it reaches the port.
66
+ 3. Admission is idempotent on `idempotencyKey`. The platform seam is not: two `prompt`
67
+ calls sharing one `requestId` were both accepted in the compatibility spike.
68
+ 4. A command records the `bindingGeneration` it was admitted for and is refused when the
69
+ member was rebound.
70
+ 5. `interrupt` cancels a turn and never touches task attempt ownership.
71
+ 6. Team context is recomputed from authoritative state on every assembly and is never cached.
72
+ 7. Model selection is deliberately not implemented: the platform call also rewrites the
73
+ deployment-wide default model, and that policy needs an explicit human decision.
74
+
75
+ ## Tests
76
+
77
+ ```sh
78
+ pnpm --filter dsh-live-teams check
79
+ pnpm --filter dsh-live-teams build
80
+ pnpm --filter dsh-live-teams test
81
+ ```
82
+
83
+ Test files cover the error taxonomy, the store, the bridge, the queue, the context
84
+ provider, and one integration file that drives the real store through the provider and
85
+ the bridge on temporary workspaces.
@@ -0,0 +1,25 @@
1
+ # Optional mount for the DSH Live Teams host half.
2
+ #
3
+ # The row stays disabled unless the composition explicitly enables it, so a
4
+ # profile that merely depends on this package never runs team coordination.
5
+ # `webServer` is used for the read-only Team tab snapshot route; the host half
6
+ # tolerates its absence so a headless composition still mounts.
7
+ - insert:
8
+ - id: live-teams
9
+ name: dsh-live-teams
10
+ disabled: !!js process.env.DSH_LIVE_TEAMS !== '1'
11
+ inject: [sessionController, sessions, agents, systemPrompt, workspaceRegistry]
12
+ config:
13
+ enabled: !!js process.env.DSH_LIVE_TEAMS === '1'
14
+ workspacePath: !!js process.env.DSH_LIVE_TEAMS_WORKSPACE
15
+ workspaceId: !!js process.env.DSH_LIVE_TEAMS_WORKSPACE_ID
16
+ teamId: !!js process.env.DSH_LIVE_TEAMS_TEAM_ID
17
+ teamName: !!js process.env.DSH_LIVE_TEAMS_TEAM_NAME
18
+ # Unattended coding stays refused unless a stand explicitly accepts it: it
19
+ # needs the worktree isolation ADR 0008 has not built (design §22).
20
+ codingDispatch: !!js process.env.DSH_LIVE_TEAMS_CODING === 'automatic' ? 'automatic' : 'manual'
21
+ # B32: how the scope record observes the workspace. `auto` (the default) uses git in a
22
+ # work tree and tree fingerprints in a plain folder; the explicit values exist for a
23
+ # repository whose status is unusable, and for exercising the fingerprint path in a
24
+ # repository during verification.
25
+ scopeMode: !!js process.env.DSH_LIVE_TEAMS_SCOPE_MODE ?? 'auto'
@@ -0,0 +1,18 @@
1
+ import { SessionBridge, SessionDescriptor } from "./session-bridge.js";
2
+ //#region src/binding.d.ts
3
+ /** Resolve symlinked temporary directories to one comparable form. */
4
+ export declare function canonicalPath(value: string): string;
5
+ export type WorkspaceGuardOptions = {
6
+ bridge: Pick<SessionBridge, 'inspect'>;
7
+ workspacePath: string;
8
+ };
9
+ /**
10
+ * Verify that a Session may become a member of this team's workspace.
11
+ *
12
+ * @returns the descriptor, so the caller does not inspect twice.
13
+ * @throws LiveTeamsError `SESSION_NOT_FOUND`, `CAPABILITY_UNAVAILABLE` for a
14
+ * subagent-owned Session, or `SESSION_WRONG_WORKSPACE` on a cwd mismatch.
15
+ */
16
+ export declare function assertSessionDescriptorInTeamWorkspace(options: Pick<WorkspaceGuardOptions, 'workspacePath'>, descriptor: SessionDescriptor): SessionDescriptor;
17
+ export declare function assertSessionInTeamWorkspace(options: WorkspaceGuardOptions, sessionId: string): Promise<SessionDescriptor>;
18
+ //#endregion
package/lib/binding.js ADDED
@@ -0,0 +1,42 @@
1
+ import { ERROR_CODES, LiveTeamsError } from "./errors.js";
2
+ import { realpathSync } from "node:fs";
3
+ //#region src/binding.ts
4
+ /**
5
+ * Workspace membership rules for binding a Session to a member.
6
+ *
7
+ * A member is a member *of a workspace*, so a Session that works somewhere else
8
+ * must not become part of that team: its scoped context, its controls and the
9
+ * work it performs would all describe a different directory. The Session header
10
+ * carries a working directory and not a workspace identity, so the comparison is
11
+ * on the canonical cwd.
12
+ */
13
+ /** Resolve symlinked temporary directories to one comparable form. */
14
+ function canonicalPath(value) {
15
+ try {
16
+ return realpathSync.native(value);
17
+ } catch {
18
+ return value;
19
+ }
20
+ }
21
+ /**
22
+ * Verify that a Session may become a member of this team's workspace.
23
+ *
24
+ * @returns the descriptor, so the caller does not inspect twice.
25
+ * @throws LiveTeamsError `SESSION_NOT_FOUND`, `CAPABILITY_UNAVAILABLE` for a
26
+ * subagent-owned Session, or `SESSION_WRONG_WORKSPACE` on a cwd mismatch.
27
+ */
28
+ function assertSessionDescriptorInTeamWorkspace(options, descriptor) {
29
+ const sessionId = descriptor.sessionId;
30
+ if (descriptor.subagentOwned) throw new LiveTeamsError(ERROR_CODES.CAPABILITY_UNAVAILABLE, `Session "${sessionId}" is owned by subagent routing`, { auditDetail: "workspace guard: a subagent-owned Session cannot be a member" });
31
+ const sessionCwd = descriptor.cwd;
32
+ if (sessionCwd === void 0 || sessionCwd.length === 0) throw new LiveTeamsError(ERROR_CODES.SESSION_WRONG_WORKSPACE, `Session "${sessionId}" has no working directory to compare`, { auditDetail: "workspace guard: the Session header carries no cwd" });
33
+ if (canonicalPath(sessionCwd) !== canonicalPath(options.workspacePath)) throw new LiveTeamsError(ERROR_CODES.SESSION_WRONG_WORKSPACE, `Session "${sessionId}" works in "${sessionCwd}", not in the team workspace "${options.workspacePath}"`, { auditDetail: `workspace guard: Session ${sessionCwd}, team ${options.workspacePath}` });
34
+ return descriptor;
35
+ }
36
+ async function assertSessionInTeamWorkspace(options, sessionId) {
37
+ const descriptor = await options.bridge.inspect(sessionId);
38
+ if (descriptor === void 0) throw new LiveTeamsError(ERROR_CODES.SESSION_NOT_FOUND, `Session "${sessionId}" does not exist`, { auditDetail: "workspace guard: inspect returned no Session" });
39
+ return assertSessionDescriptorInTeamWorkspace(options, descriptor);
40
+ }
41
+ //#endregion
42
+ export { assertSessionDescriptorInTeamWorkspace, assertSessionInTeamWorkspace, canonicalPath };
@@ -0,0 +1,26 @@
1
+ //#region src/changed-paths.d.ts
2
+ /**
3
+ * What changed in a workspace, for the declared-scope check (B30).
4
+ *
5
+ * The store never shells out itself: it takes a port, and the plugin supplies this
6
+ * adapter. `undefined` means "not observable" — no git, not a repository, an
7
+ * unparsable answer, or more changes than the cap — and is recorded as `unchecked`
8
+ * rather than as a clean result.
9
+ *
10
+ * `--porcelain -z` is used because the output is byte-exact: entries are NUL separated,
11
+ * a rename prints the *new* path first and the original as the next record, and no
12
+ * quoting or escaping is applied to unusual file names.
13
+ */
14
+ export declare const CHANGED_PATHS_LIMIT = 2000;
15
+ export declare function parsePorcelainZ(stdout: string): string[] | undefined;
16
+ export declare function gitChangedPaths(workspacePath: string): Promise<string[] | undefined>;
17
+ /**
18
+ * B32: which observation a workspace supports.
19
+ *
20
+ * `git` when the workspace is a work tree, `files` otherwise. A directory that is not a
21
+ * repository is a first-class case (a plugin folder, a document, a research tree), not a
22
+ * degraded one: the declaration is checked the same way, only the evidence differs.
23
+ */
24
+ export type WorkspaceMode = 'git' | 'files';
25
+ export declare function workspaceMode(workspacePath: string): Promise<WorkspaceMode | undefined>;
26
+ //#endregion
@@ -0,0 +1,69 @@
1
+ import { execFile } from "node:child_process";
2
+ //#region src/changed-paths.ts
3
+ /**
4
+ * What changed in a workspace, for the declared-scope check (B30).
5
+ *
6
+ * The store never shells out itself: it takes a port, and the plugin supplies this
7
+ * adapter. `undefined` means "not observable" — no git, not a repository, an
8
+ * unparsable answer, or more changes than the cap — and is recorded as `unchecked`
9
+ * rather than as a clean result.
10
+ *
11
+ * `--porcelain -z` is used because the output is byte-exact: entries are NUL separated,
12
+ * a rename prints the *new* path first and the original as the next record, and no
13
+ * quoting or escaping is applied to unusual file names.
14
+ */
15
+ const CHANGED_PATHS_LIMIT = 2e3;
16
+ function parsePorcelainZ(stdout) {
17
+ const records = stdout.split("\0");
18
+ const changed = [];
19
+ for (let index = 0; index < records.length; index += 1) {
20
+ const record = records[index];
21
+ if (record.length === 0) continue;
22
+ if (record.length < 4 || record[2] !== " ") return void 0;
23
+ const status = record.slice(0, 2);
24
+ const target = record.slice(3);
25
+ if (target.length === 0) return void 0;
26
+ changed.push(target);
27
+ if (status[0] === "R" || status[0] === "C") index += 1;
28
+ if (changed.length > 2e3) return void 0;
29
+ }
30
+ return changed;
31
+ }
32
+ async function gitChangedPaths(workspacePath) {
33
+ return await new Promise((resolve) => {
34
+ execFile("git", [
35
+ "-C",
36
+ workspacePath,
37
+ "status",
38
+ "--porcelain",
39
+ "-z"
40
+ ], {
41
+ timeout: 5e3,
42
+ maxBuffer: 4194304
43
+ }, (error, stdout) => {
44
+ if (error) {
45
+ resolve(void 0);
46
+ return;
47
+ }
48
+ resolve(parsePorcelainZ(stdout));
49
+ });
50
+ });
51
+ }
52
+ async function workspaceMode(workspacePath) {
53
+ return await new Promise((resolve) => {
54
+ execFile("git", [
55
+ "-C",
56
+ workspacePath,
57
+ "rev-parse",
58
+ "--is-inside-work-tree"
59
+ ], { timeout: 5e3 }, (error, stdout) => {
60
+ if (error) {
61
+ resolve("files");
62
+ return;
63
+ }
64
+ resolve(stdout.trim() === "true" ? "git" : "files");
65
+ });
66
+ });
67
+ }
68
+ //#endregion
69
+ export { CHANGED_PATHS_LIMIT, gitChangedPaths, parsePorcelainZ, workspaceMode };