teamshare-bridge 0.22.7 → 0.22.9

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 (98) hide show
  1. package/README.md +383 -383
  2. package/dist/bridge/auto-upgrade.d.ts +92 -0
  3. package/dist/bridge/auto-upgrade.js +159 -6
  4. package/dist/bridge/auto-upgrade.js.map +1 -1
  5. package/dist/bridge/daemon-instance.d.ts +17 -0
  6. package/dist/bridge/daemon-instance.js +58 -0
  7. package/dist/bridge/daemon-instance.js.map +1 -1
  8. package/dist/bridge/daemon.js +88 -45
  9. package/dist/bridge/daemon.js.map +1 -1
  10. package/dist/bridge/doctor.js +30 -0
  11. package/dist/bridge/doctor.js.map +1 -1
  12. package/dist/bridge/index.js +37 -3
  13. package/dist/bridge/index.js.map +1 -1
  14. package/dist/bridge/install-verify.js +8 -8
  15. package/dist/bridge/spawn.d.ts +14 -0
  16. package/dist/bridge/spawn.js +7 -1
  17. package/dist/bridge/spawn.js.map +1 -1
  18. package/dist/bridge/upgrade-marker.d.ts +24 -2
  19. package/dist/bridge/upgrade-marker.js +30 -2
  20. package/dist/bridge/upgrade-marker.js.map +1 -1
  21. package/dist/bridge/upgrade-preflight.d.ts +49 -0
  22. package/dist/bridge/upgrade-preflight.js +164 -0
  23. package/dist/bridge/upgrade-preflight.js.map +1 -0
  24. package/dist/bridge/wake-handler.d.ts +8 -15
  25. package/dist/bridge/wake-handler.js +109 -14
  26. package/dist/bridge/wake-handler.js.map +1 -1
  27. package/dist/bridge/wake-outbox.js +7 -0
  28. package/dist/bridge/wake-outbox.js.map +1 -1
  29. package/dist/cli/commands/plan.js +4 -0
  30. package/dist/cli/commands/plan.js.map +1 -1
  31. package/dist/lib/browser/human-input-guard.js +98 -98
  32. package/dist/lib/browser/screen-change.js +60 -60
  33. package/dist/lib/llm/usage-reader.js +4 -4
  34. package/dist/lib/workspace/classify.d.ts +29 -0
  35. package/dist/lib/workspace/classify.js +62 -0
  36. package/dist/lib/workspace/classify.js.map +1 -1
  37. package/dist/lib/workspace/presence.d.ts +31 -0
  38. package/dist/lib/workspace/presence.js +35 -1
  39. package/dist/lib/workspace/presence.js.map +1 -1
  40. package/dist/lib/workspace/shim-runner.js +23 -0
  41. package/dist/lib/workspace/shim-runner.js.map +1 -1
  42. package/package.json +70 -70
  43. package/skills/THIRD_PARTY_NOTICES.md +26 -26
  44. package/skills/architect/LICENSE +21 -21
  45. package/skills/codebase-design/LICENSE +21 -21
  46. package/skills/diagnosing-bugs/LICENSE +21 -21
  47. package/skills/domain-modeling/LICENSE +21 -21
  48. package/skills/improve-codebase-architecture/LICENSE +21 -21
  49. package/skills/recover/LICENSE +21 -21
  50. package/skills/review/LICENSE +21 -21
  51. package/skills/tdd/LICENSE +21 -21
  52. package/skills/teamshare-auth-rbac/SKILL.md +78 -78
  53. package/skills/teamshare-cdd/SKILL.md +205 -205
  54. package/skills/teamshare-modularity/SKILL.md +146 -146
  55. package/skills/teamshare-orchestrator-ask/SKILL.md +77 -77
  56. package/skills/teamshare-scaffold/SKILL.md +116 -116
  57. package/templates/backend/.env.example.tpl +13 -13
  58. package/templates/backend/nest-cli.json.tpl +8 -8
  59. package/templates/backend/package.json.tpl +41 -41
  60. package/templates/backend/prisma/schema.prisma.tpl +39 -39
  61. package/templates/backend/src/app.module.ts.tpl +24 -24
  62. package/templates/backend/src/common/filters/all-exceptions.filter.ts.tpl +59 -59
  63. package/templates/backend/src/common/guards/jwt-auth.guard.ts.tpl +27 -27
  64. package/templates/backend/src/common/guards/rbac.guard.ts.tpl +48 -48
  65. package/templates/backend/src/common/interceptors/transform.interceptor.ts.tpl +44 -44
  66. package/templates/backend/src/common/pipes/zod-validation.pipe.ts.tpl +29 -29
  67. package/templates/backend/src/common/swagger/envelope.schemas.ts.tpl +53 -53
  68. package/templates/backend/src/common/swagger/error.schemas.ts.tpl +62 -62
  69. package/templates/backend/src/main.ts.tpl +27 -27
  70. package/templates/backend/src/modules/example/example.controller.ts.tpl +102 -102
  71. package/templates/backend/src/modules/example/example.dto.ts.tpl +14 -14
  72. package/templates/backend/src/modules/example/example.module.ts.tpl +10 -10
  73. package/templates/backend/src/modules/example/example.service.ts.tpl +45 -45
  74. package/templates/backend/tsconfig.json.tpl +26 -26
  75. package/templates/common/.gitignore.tpl +42 -42
  76. package/templates/common/AGENTS.md.tpl +58 -58
  77. package/templates/common/docs/adr/README.md +25 -25
  78. package/templates/common/docs/api-contract.md.tpl +72 -72
  79. package/templates/web/next.config.ts.tpl +7 -7
  80. package/templates/web/package.json.tpl +37 -37
  81. package/templates/web/src/app/globals.css.tpl +48 -48
  82. package/templates/web/src/app/layout.tsx.tpl +25 -25
  83. package/templates/web/src/components/shared/app-button.tsx.tpl +59 -59
  84. package/templates/web/src/components/shared/app-empty-state.tsx.tpl +39 -39
  85. package/templates/web/src/components/shared/app-list-toolbar.tsx.tpl +63 -63
  86. package/templates/web/src/components/shared/app-skeleton.tsx.tpl +14 -14
  87. package/templates/web/src/components/shared/app-table.tsx.tpl +128 -128
  88. package/templates/web/src/components/shared/index.ts.tpl +5 -5
  89. package/templates/web/src/hooks/use-list-state.ts.tpl +72 -72
  90. package/templates/web/src/hooks/use-url-tab.ts.tpl +25 -25
  91. package/templates/web/src/lib/api/client.ts.tpl +123 -123
  92. package/templates/web/src/lib/providers.tsx.tpl +35 -35
  93. package/templates/web/src/lib/query-keys.ts.tpl +21 -21
  94. package/templates/web/src/lib/utils.ts.tpl +7 -7
  95. package/templates/web/src/lib/validation/schemas.ts.tpl +15 -15
  96. package/templates/web/src/modules/example/views/example-list-view.tsx.tpl +97 -97
  97. package/templates/web/tsconfig.json.tpl +23 -23
  98. package/tools/workspace-arbitration-check.mjs +389 -389
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 JavaScript Mastery
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JavaScript Mastery
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Matt Pocock
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matt Pocock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,79 +1,79 @@
1
- ---
2
- name: teamshare-auth-rbac
3
- description: TeamShare auth & authorization rules for every endpoint you write or change. Pick the correct guard stack (@Permissions for human-only, @Public + AgentsDualAuthGuard + @ApiKeyScopes for agent+human surfaces, @Public for truly public, ApiKeyGuard + canUseTool for MCP). Enforce capability + key scope + project access (never less than two layers). Use envelope + zod validation + UPPER_SNAKE error codes, and write AgentLog rows for every agent action.
4
- ---
5
-
6
- # TeamShare Auth & Authorization (RBAC)
7
-
8
- Every endpoint in `teamshare-backend` must declare its access story. Use this
9
- decision table; never leave an endpoint with default guards and no metadata.
10
-
11
- ## 1. Choose the guard stack
12
-
13
- | Who calls it | What to use on the route |
14
- |---|---|
15
- | Human JWT only (company/team/env-var/roles/webhooks/invitations/attachments) | Leave global guards, add `@Permissions('<entity>.<action>')` (e.g. `document.create`) |
16
- | Agents AND humans (tasks, comments, chat, documents, search, projects, agents self-service) | Class-level `@Public()` + `@UseGuards(AgentsDualAuthGuard)` + per-route `@ApiKeyScopes('<entity>:read' \| '<entity>:write')` |
17
- | Truly public (auth, verify, reset, billing webhook, run-token redeem) | `@Public()` only |
18
- | MCP tools (`/mcp`) | `ApiKeyGuard` + per-tool `canUseTool(capabilities, keyScopes, required)` |
19
-
20
- `AgentsDualAuthGuard` accepts `X-Api-Key` (enforces `@ApiKeyScopes`) OR a
21
- `Bearer` JWT. **Do not combine `@Permissions` with `AgentsDualAuthGuard` on the
22
- same route** — global RbacGuard runs before the route guard can set
23
- `request.user` for key callers. Dual-auth routes delegate access to the
24
- service layer.
25
-
26
- ## 2. The three enforcement layers (never less than two)
27
-
28
- For every agent action: **capability** (`Agent.capabilities`) + **API-key
29
- scope** (`@ApiKeyScopes`, minted by `scopesForCapabilities`) + **project
30
- access** (`assertProjectAccess`). Never gate access on env vars.
31
-
32
- - MCP tool → `ctx.canUse('<capability>')` (capability + scope) then the shared
33
- service runs `assertProjectAccess` as the agent user.
34
- - Agent REST → `@ApiKeyScopes` (scope) then the service runs
35
- `assertProjectAccess` (project role).
36
- - Service layer helpers: `assertProjectAccess(prisma, projectId, userId,
37
- minRole)`, `assertCompanyMembership`, `isCompanyOwnerOrAdmin`.
38
-
39
- ## 3. Permission vocabulary (CRUDL)
40
-
41
- - `src/common/constants/rbac.ts`: `ENTITIES` (17) × `ACTIONS`
42
- (`create | read | list | update | delete`) → `Permission = entity.action`
43
- plus `SPECIAL_PERMISSIONS` (`env_var.reveal`, `env_var.export`, ...).
44
- - Static role matrices: `COMPANY_ROLE_PERMISSIONS`
45
- (owner/admin/member/secret_manager/viewer) and `PROJECT_ROLE_PERMISSIONS`
46
- (owner/member/viewer). Dynamic roles add `companyPermissions` claims.
47
- - Agent capabilities live in `src/common/constants/enums.ts`
48
- (`AGENT_CAPABILITIES`, `CAPABILITY_SCOPES`). A key never exceeds its
49
- agent's capabilities and a capability never exceeds the key's scopes.
50
- - Add a new capability → add its scope in `API_KEY_SCOPES` + a mapping in
51
- `CAPABILITY_SCOPES`, so `scopesForCapabilities` mints the right key.
52
-
53
- ## 4. Error codes & envelope
54
-
55
- - Throw `new XxxException({ code: 'UPPER_SNAKE', message, details? })`
56
- (`VALIDATION_ERROR`, `PROJECT_NOT_FOUND`, `INSUFFICIENT_PROJECT_ROLE`,
57
- `API_KEY_SCOPE_MISSING`, `DOCUMENT_UPDATE_DENIED`, ...). Secrets never
58
- appear in messages/logs.
59
- - Responses: `{ success: true, data, pagination? }` /
60
- `{ success: false, error: { code, message, details? } }` (global
61
- interceptor/filter — your handler returns raw data).
62
-
63
- ## 5. AgentLog — never bypass
64
-
65
- Every agent mutation logs an `AgentLog` row via the shared services:
66
- `logAgentActionIfAgent(prisma, userId, { action, taskId?, detail })`
67
- (best-effort; humans skipped). Actions are in `AGENT_LOG_ACTIONS`
68
- (`task_created`, `comment_created`, `document_created`, `document_updated`,
69
- `subtask_updated`, `wake_sent`, ...). If you add an agent-facing mutation,
70
- wire the log in the service — never in the controller.
71
-
72
- ## 6. Checklist for a new endpoint
73
-
74
- - [ ] Guard stack chosen from the table; metadata declared on the route.
75
- - [ ] zod `ZodValidationPipe` on body/query/param; generated zod for enums.
76
- - [ ] Service re-checks project/company access (guards are a first filter).
77
- - [ ] Envelope-compliant return; UPPER_SNAKE error codes.
78
- - [ ] Agent actions write `AgentLog` via `logAgentActionIfAgent`.
1
+ ---
2
+ name: teamshare-auth-rbac
3
+ description: TeamShare auth & authorization rules for every endpoint you write or change. Pick the correct guard stack (@Permissions for human-only, @Public + AgentsDualAuthGuard + @ApiKeyScopes for agent+human surfaces, @Public for truly public, ApiKeyGuard + canUseTool for MCP). Enforce capability + key scope + project access (never less than two layers). Use envelope + zod validation + UPPER_SNAKE error codes, and write AgentLog rows for every agent action.
4
+ ---
5
+
6
+ # TeamShare Auth & Authorization (RBAC)
7
+
8
+ Every endpoint in `teamshare-backend` must declare its access story. Use this
9
+ decision table; never leave an endpoint with default guards and no metadata.
10
+
11
+ ## 1. Choose the guard stack
12
+
13
+ | Who calls it | What to use on the route |
14
+ |---|---|
15
+ | Human JWT only (company/team/env-var/roles/webhooks/invitations/attachments) | Leave global guards, add `@Permissions('<entity>.<action>')` (e.g. `document.create`) |
16
+ | Agents AND humans (tasks, comments, chat, documents, search, projects, agents self-service) | Class-level `@Public()` + `@UseGuards(AgentsDualAuthGuard)` + per-route `@ApiKeyScopes('<entity>:read' \| '<entity>:write')` |
17
+ | Truly public (auth, verify, reset, billing webhook, run-token redeem) | `@Public()` only |
18
+ | MCP tools (`/mcp`) | `ApiKeyGuard` + per-tool `canUseTool(capabilities, keyScopes, required)` |
19
+
20
+ `AgentsDualAuthGuard` accepts `X-Api-Key` (enforces `@ApiKeyScopes`) OR a
21
+ `Bearer` JWT. **Do not combine `@Permissions` with `AgentsDualAuthGuard` on the
22
+ same route** — global RbacGuard runs before the route guard can set
23
+ `request.user` for key callers. Dual-auth routes delegate access to the
24
+ service layer.
25
+
26
+ ## 2. The three enforcement layers (never less than two)
27
+
28
+ For every agent action: **capability** (`Agent.capabilities`) + **API-key
29
+ scope** (`@ApiKeyScopes`, minted by `scopesForCapabilities`) + **project
30
+ access** (`assertProjectAccess`). Never gate access on env vars.
31
+
32
+ - MCP tool → `ctx.canUse('<capability>')` (capability + scope) then the shared
33
+ service runs `assertProjectAccess` as the agent user.
34
+ - Agent REST → `@ApiKeyScopes` (scope) then the service runs
35
+ `assertProjectAccess` (project role).
36
+ - Service layer helpers: `assertProjectAccess(prisma, projectId, userId,
37
+ minRole)`, `assertCompanyMembership`, `isCompanyOwnerOrAdmin`.
38
+
39
+ ## 3. Permission vocabulary (CRUDL)
40
+
41
+ - `src/common/constants/rbac.ts`: `ENTITIES` (17) × `ACTIONS`
42
+ (`create | read | list | update | delete`) → `Permission = entity.action`
43
+ plus `SPECIAL_PERMISSIONS` (`env_var.reveal`, `env_var.export`, ...).
44
+ - Static role matrices: `COMPANY_ROLE_PERMISSIONS`
45
+ (owner/admin/member/secret_manager/viewer) and `PROJECT_ROLE_PERMISSIONS`
46
+ (owner/member/viewer). Dynamic roles add `companyPermissions` claims.
47
+ - Agent capabilities live in `src/common/constants/enums.ts`
48
+ (`AGENT_CAPABILITIES`, `CAPABILITY_SCOPES`). A key never exceeds its
49
+ agent's capabilities and a capability never exceeds the key's scopes.
50
+ - Add a new capability → add its scope in `API_KEY_SCOPES` + a mapping in
51
+ `CAPABILITY_SCOPES`, so `scopesForCapabilities` mints the right key.
52
+
53
+ ## 4. Error codes & envelope
54
+
55
+ - Throw `new XxxException({ code: 'UPPER_SNAKE', message, details? })`
56
+ (`VALIDATION_ERROR`, `PROJECT_NOT_FOUND`, `INSUFFICIENT_PROJECT_ROLE`,
57
+ `API_KEY_SCOPE_MISSING`, `DOCUMENT_UPDATE_DENIED`, ...). Secrets never
58
+ appear in messages/logs.
59
+ - Responses: `{ success: true, data, pagination? }` /
60
+ `{ success: false, error: { code, message, details? } }` (global
61
+ interceptor/filter — your handler returns raw data).
62
+
63
+ ## 5. AgentLog — never bypass
64
+
65
+ Every agent mutation logs an `AgentLog` row via the shared services:
66
+ `logAgentActionIfAgent(prisma, userId, { action, taskId?, detail })`
67
+ (best-effort; humans skipped). Actions are in `AGENT_LOG_ACTIONS`
68
+ (`task_created`, `comment_created`, `document_created`, `document_updated`,
69
+ `subtask_updated`, `wake_sent`, ...). If you add an agent-facing mutation,
70
+ wire the log in the service — never in the controller.
71
+
72
+ ## 6. Checklist for a new endpoint
73
+
74
+ - [ ] Guard stack chosen from the table; metadata declared on the route.
75
+ - [ ] zod `ZodValidationPipe` on body/query/param; generated zod for enums.
76
+ - [ ] Service re-checks project/company access (guards are a first filter).
77
+ - [ ] Envelope-compliant return; UPPER_SNAKE error codes.
78
+ - [ ] Agent actions write `AgentLog` via `logAgentActionIfAgent`.
79
79
  - [ ] Swagger `@ApiOperation` mentions the RBAC; `@errs(...)` lists the codes.