@somewhere-cloud/cli 0.38.74 → 0.38.75
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const AGENT_WORKFLOW = "## Build, deploy, test\n\nEnough to start a typical app: declare access and use the browser client; docs are for exceptions.\n\n| Requirement | Declaration below |\n| --- | --- |\n| Each user sees only their own rows | notes: owner() |\n| Team: owner adds members; members read/write; creator rights | teams/team_members/tasks: owner() + member(); role-owner delete branch |\n| Owner/staff record with staff-only child notes | tickets: owner() or appRole(); parent() thread; staff-only notes; POST setup below |\n| Public pages from private drafts | pages: conditional publicRead |\n| Share one record read-only | shared_notes/note_shares: read-only grant() |\n\ndb/schema.ts is declaration only: imports, constants/spreads, default schema;\nno helpers/expressions. id() is random text; owner() stamps user_id. client.read\nincludes the key. Inside anyOf(), owner() takes only column/read: it stamps the\ncreator, not create/delete options; member() gates placement (non-member create is\nrefused), while creators or the allowed branch can delete. Other fields: timestamp({ default: 'now' }), text({ nullable: true });\nindexes: [['team_id']].\n\n```ts\nimport { schema, table, id, text, owner, member, anyOf, serverOnly, parent, appRole, boolean, grant } from 'somewhere/db';\nexport default schema({\n notes: table({ id: id(), title: text() }, { scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'], delete: true },\n }),\n teams: table({ id: id(), name: text(), owner_id: text() }, {\n scope: member({ group: 'id', membership: 'team_members', member_user: 'user_id', member_group: 'team_id' }),\n client: { read: ['id', 'name'] },\n }),\n team_members: table({ id: id(), team_id: text(), user_id: text(), role: text() }, {\n scope: serverOnly(), unique: [['team_id', 'user_id']],\n }),\n tasks: table({ id: id(), team_id: text({ references: 'teams' }), title: text() }, {\n scope: anyOf(owner(), member({ group: 'team_id', membership: 'team_members',\n member_user: 'user_id', member_group: 'team_id', operations: ['read', 'create', 'update'] }),\n member({ group: 'team_id', membership: 'team_members', member_user: 'user_id',\n member_group: 'team_id', where: { role: 'owner' }, operations: ['delete'] })),\n client: { read: ['id', 'team_id', 'title'], create: ['team_id', 'title'], update: ['title'], delete: true },\n }),\n tickets: table({ id: id(), subject: text() }, {\n scope: anyOf(owner(), appRole({ roles: { read: ['staff'], create: ['staff'], update: ['staff'] } })),\n client: { read: true, create: ['subject'], update: ['subject'] },\n }),\n messages: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: parent({ via: 'ticket_id' }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n staff_notes: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: appRole({ roles: { read: ['staff'], create: ['staff'] } }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n pages: table({ id: id(), title: text(), published: boolean({ default: false }) }, {\n scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'],\n publicRead: { where: { published: true } } },\n }),\n note_shares: table({ id: id(), grantee_id: text(), note_id: text({ references: 'shared_notes', onDelete: 'cascade' }) }, {\n scope: owner(), unique: [['note_id', 'grantee_id']],\n }),\n shared_notes: table({ id: id(), title: text() }, {\n scope: anyOf(owner(), grant({ table: 'note_shares', grantee: 'grantee_id', row: 'note_id', operations: ['read'] })),\n client: { read: ['id', 'title'], create: ['title'], update: ['title'] },\n }),\n}, { appRoles: { staff: { assignedBy: 'server' } } });\n```\n\nPOST role setup once after sign-up/profile completion, not GET/every request:\ncookie-authenticated GET cannot mutate roles.\nCheck admin here, or your own assignment rule.\nmessages use parent(): owner() would hide staff replies from the customer.\nUse emailDomain for staff at your verified domain; assignedBy: 'server' when the\napp decides (promotion, payment, invitation). An email ending proves identity only\nwhen verified; assigning a role anyway is your app's decision, whose permissions the platform enforces.\nPublish pages in an owner-checked endpoint. Share with caller-scoped\nsw.db.insert('note_shares', { grantee_id, note_id }); it checks row ownership.\nBrowser calls THROW, not { error }; catch below.\nBrowser list: max 100, paginate after; no order (sort locally or in an endpoint).\n\n```ts\nimport { data } from 'somewhere:data';\nexport async function save(title: string) {\n try { await data.notes.create({ title }); return null; }\n catch (e) { return e instanceof Error ? e.message : 'Save failed'; }\n}\nexport const list = (after?: string) => data.notes.list({ limit: 100, after });\n```\n\nTeams without verification: own membership table + member(); sw.groups and domain\nroles need VERIFIED emails. Members read/create/update tasks; creators or team owners delete while members.\nRestrictions narrow operations, not grant read.\nComment-author-or-team-owner deletion stays a small endpoint.\nCreate the team and its owner membership atomically:\n\n```ts\n// api/teams.ts\nexport default sw.endpoint({\n auth: 'required', body: { name: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const id = crypto.randomUUID();\n await sw.db.server.tx([\n { op: 'insert', table: 'teams', values: { id, name: body.name, owner_id: user.id } },\n { op: 'insert', table: 'team_members', values: { id: crypto.randomUUID(), team_id: id, user_id: user.id, role: 'owner' } },\n ]);\n return { id, email: user.email };\n },\n});\n```\n\n```ts\n// api/teams/[id]/members.ts \u2014 only the team owner adds a member\nexport default sw.endpoint({\n auth: 'required', body: { email: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const { data: teams } = await sw.db.from('teams', { where: { id: params.id, owner_id: user.id }, limit: 1 });\n if (!teams[0]) return Response.json({ error: 'Team owner required' }, { status: 403 });\n const { users: [target] } = await sw.auth.server.listUsers({ emails: [body.email] });\n if (!target) return Response.json({ error: 'Account not found' }, { status: 404 });\n await sw.db.server.insert('team_members', {\n id: crypto.randomUUID(), team_id: params.id, user_id: target.id, role: 'member',\n }, { onConflict: 'ignore' });\n return { ok: true };\n },\n});\n```\n\n```ts\n// api/complete-profile.ts \u2014 POST once when an admin assigns staff after sign-up\nexport default sw.endpoint({\n auth: 'required', body: { userId: 'string' },\n handler: async ({ request, body }, sw) => {\n await sw.auth.requireUser(request, { role: 'admin' });\n await sw.auth.server.setRoles(body.userId, { add: ['staff'] });\n return { ok: true };\n },\n});\n```\n\nDo not hand-write access to app-read/write data: declare who may read/write it.\nserverOnly() fits job/import/audit/counter state and protected membership ledgers.\nGrant ledgers use owner() without browser writes. Undeclarable: arbitrary predicates\n(e.g. expiry) or per-role writable fields (split tables or check that write).\n\nBuild src/pages/HomePage.tsx; routes src/App.tsx + src/routes.ts; auth src/auth/hooks.ts.\nAuth is wired: keep api/auth/[...path].ts; src/config.ts controls providers.\napi/notes/[id]/sub.ts \u2192 params.id; underscore files are helpers. POST: default export;\nGET/DELETE: named exports.\n\n```ts\nexport const GET = sw.endpoint({ auth: 'required', handler: async (_, sw) => sw.db.from('notes', { limit: 100 }) });\n```\n\nsw.db applies caller scopes; sw.db.server bypasses them: authorize first.\nReads: from(table, { where, columns, order: [['id', 'asc']], limit, offset }).\nFilter: { id: { in: ids } }; unique: [['a', 'b']] in schema.\nWrites: insert(table, values), update(table, { where, set }), remove(table, { where }).\ntx takes an ARRAY of write intents, never a callback; pre-generate related IDs.\n\nBrowser: fetch(path, { method: 'POST', credentials: 'same-origin',\nheaders: { 'content-type': 'application/json' }, body: JSON.stringify(values) }).\nAccess cookies refresh automatically. Cookie-auth POST/PATCH/DELETE from scripts\nneed Origin equal to the app URL.\n\nPublish: somewhere typecheck \u2192 npx @somewhere-cloud/cli deploy \u2192 somewhere verify \u2192 somewhere test.\nDeploy raw source, no frontend build. Type errors stop upload; override: somewhere deploy --allow-type-errors.\nnewUser() gives a signed-in page/API client; call N times (owner, member, outsider).\nNo chosen email argument: assign roles/memberships through your app's authorized POST setup.\nDiagnose with somewhere errors and somewhere logs.\n\nOn demand:\n- Server paging: `somewhere docs sw.db --section server-read-paging`\n";
|
|
1
|
+
export declare const AGENT_WORKFLOW = "## Build, deploy, test\n\nEnough to start a typical app: declare access and use the browser client; docs are for exceptions.\n\n| Requirement | Declaration below |\n| --- | --- |\n| Each user sees only their own rows | notes: owner() |\n| Team: owner adds members; members read/write; creator rights | teams/team_members/tasks: owner() + member(); role-owner delete branch |\n| Owner/staff record with staff-only child notes | tickets: owner() or appRole(); parent() thread; staff-only notes; POST setup below |\n| Public pages from private drafts | pages: conditional publicRead |\n| Share one record read-only | shared_notes/note_shares: read-only grant() |\n\ndb/schema.ts is declaration only: imports, constants/spreads, default schema;\nno helpers/expressions. id() is random text; owner() stamps user_id. client.read\nincludes the key. Inside anyOf(), owner() takes only column/read: it stamps the\ncreator, not create/delete options; member() gates placement (non-member create is\nrefused), while creators or the allowed branch can delete. Other fields: timestamp({ default: 'now' }), text({ nullable: true });\nindexes: [['team_id']].\n\n```ts\nimport { schema, table, id, text, owner, member, anyOf, serverOnly, parent, appRole, boolean, grant } from 'somewhere/db';\nexport default schema({\n notes: table({ id: id(), title: text() }, { scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'], delete: true },\n }),\n teams: table({ id: id(), name: text(), owner_id: text() }, {\n scope: member({ group: 'id', membership: 'team_members', member_user: 'user_id', member_group: 'team_id' }),\n client: { read: ['id', 'name'] },\n }),\n team_members: table({ id: id(), team_id: text(), user_id: text(), role: text() }, {\n scope: serverOnly(), unique: [['team_id', 'user_id']],\n }),\n tasks: table({ id: id(), team_id: text({ references: 'teams' }), title: text() }, {\n scope: anyOf(owner(), member({ group: 'team_id', membership: 'team_members',\n member_user: 'user_id', member_group: 'team_id', operations: ['read', 'create', 'update'] }),\n member({ group: 'team_id', membership: 'team_members', member_user: 'user_id',\n member_group: 'team_id', where: { role: 'owner' }, operations: ['delete'] })),\n client: { read: ['id', 'team_id', 'title'], create: ['team_id', 'title'], update: ['title'], delete: true },\n }),\n tickets: table({ id: id(), subject: text() }, {\n scope: anyOf(owner(), appRole({ roles: { read: ['staff'], create: ['staff'], update: ['staff'] } })),\n client: { read: true, create: ['subject'], update: ['subject'] },\n }),\n messages: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: parent({ via: 'ticket_id' }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n staff_notes: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: appRole({ roles: { read: ['staff'], create: ['staff'] } }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n pages: table({ id: id(), title: text(), published: boolean({ default: false }) }, {\n scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'],\n publicRead: { where: { published: true } } },\n }),\n note_shares: table({ id: id(), grantee_id: text(), note_id: text({ references: 'shared_notes', onDelete: 'cascade' }) }, {\n scope: owner(), unique: [['note_id', 'grantee_id']],\n }),\n shared_notes: table({ id: id(), title: text() }, {\n scope: anyOf(owner(), grant({ table: 'note_shares', grantee: 'grantee_id', row: 'note_id', operations: ['read'] })),\n client: { read: ['id', 'title'], create: ['title'], update: ['title'] },\n }),\n}, { appRoles: { staff: { assignedBy: 'server' } } });\n```\n\nPOST role setup once after sign-up/profile completion, not GET/every request:\ncookie-authenticated GET cannot mutate roles.\nCheck admin here, or your own assignment rule.\nmessages use parent(): owner() would hide staff replies from the customer.\nUse emailDomain for staff at your verified domain; assignedBy: 'server' when the\napp decides (promotion, payment, invitation). An email ending proves identity only\nwhen verified; assigning a role anyway is your app's decision, whose permissions the platform enforces.\nPublish pages in an owner-checked endpoint. Share with caller-scoped\nsw.db.insert('note_shares', { grantee_id, note_id }); it checks row ownership.\nBrowser calls THROW, not { error }; catch below.\nBrowser list: max 100, paginate after; no order (sort locally or in an endpoint).\n\n```ts\nimport { data } from 'somewhere:data';\nexport async function save(title: string) {\n try { await data.notes.create({ title }); return null; }\n catch (e) { return e instanceof Error ? e.message : 'Save failed'; }\n}\nexport const list = (after?: string) => data.notes.list({ limit: 100, after });\n```\n\nTeams without verification: own membership table + member(); sw.groups and domain\nroles need VERIFIED emails. Members read/create/update tasks; creators or team owners delete while members.\nRestrictions narrow operations, not grant read.\nComment-author-or-team-owner deletion stays a small endpoint.\nCreate the team and its owner membership atomically:\n\n```ts\n// api/teams.ts\nexport default sw.endpoint({\n auth: 'required', body: { name: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const id = crypto.randomUUID();\n await sw.db.server.tx([\n { op: 'insert', table: 'teams', values: { id, name: body.name, owner_id: user.id } },\n { op: 'insert', table: 'team_members', values: { id: crypto.randomUUID(), team_id: id, user_id: user.id, role: 'owner' } },\n ]);\n return { id, email: user.email };\n },\n});\n```\n\n```ts\n// api/teams/[id]/members.ts \u2014 only the team owner adds a member\nexport default sw.endpoint({\n auth: 'required', body: { email: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const { data: teams } = await sw.db.from('teams', { where: { id: params.id, owner_id: user.id }, limit: 1 });\n if (!teams[0]) return Response.json({ error: 'Team owner required' }, { status: 403 });\n const { users: [target] } = await sw.auth.server.listUsers({ emails: [body.email] });\n if (!target) return Response.json({ error: 'Account not found' }, { status: 404 });\n await sw.db.server.insert('team_members', {\n id: crypto.randomUUID(), team_id: params.id, user_id: target.id, role: 'member',\n }, { onConflict: 'ignore' });\n return { ok: true };\n },\n});\n```\n\n```ts\n// api/complete-profile.ts \u2014 POST once when an admin assigns staff after sign-up\nexport default sw.endpoint({\n auth: 'required', body: { userId: 'string' },\n handler: async ({ request, body }, sw) => {\n await sw.auth.requireUser(request, { role: 'admin' });\n await sw.auth.server.setRoles(body.userId, { add: ['staff'] });\n return { ok: true };\n },\n});\n```\n\nDo not hand-write access to app-read/write data: declare who may read/write it.\nserverOnly() fits job/import/audit/counter state and protected membership ledgers.\nGrant ledgers use owner() without browser writes. Undeclarable: arbitrary predicates\n(e.g. expiry) or per-role writable fields (split tables or check that write).\n\nBuild src/pages/HomePage.tsx; routes src/App.tsx + src/routes.ts; auth src/auth/hooks.ts.\nAuth is wired: keep api/auth/[...path].ts; src/config.ts controls providers.\napi/notes/[id]/sub.ts \u2192 params.id; underscore files are helpers. POST: default export;\nGET/DELETE: named exports.\n\n```ts\nexport const GET = sw.endpoint({ auth: 'required', handler: async (_, sw) => sw.db.from('notes', { limit: 100 }) });\n```\n\nsw.db applies caller scopes; sw.db.server bypasses them: authorize first.\nReads: from(table, { where, columns, order: [['id', 'asc']], limit, offset }).\nFilter: { id: { in: ids } }; unique: [['a', 'b']] in schema.\nWrites: insert(table, values), update(table, { where, set }), remove(table, { where }).\ntx takes an ARRAY of write intents, never a callback; pre-generate related IDs.\n\nBrowser: fetch(path, { method: 'POST', credentials: 'same-origin',\nheaders: { 'content-type': 'application/json' }, body: JSON.stringify(values) }).\nAccess cookies refresh automatically. Cookie-auth POST/PATCH/DELETE from scripts\nneed Origin equal to the app URL.\n\nPublish: somewhere typecheck \u2192 npx @somewhere-cloud/cli deploy \u2192 somewhere verify \u2192 somewhere test.\nDeploy raw source, no frontend build. Type errors stop upload; override: somewhere deploy --allow-type-errors.\nnewUser() gives a signed-in page/API client; call N times (owner, member, outsider).\nNo chosen email argument: assign roles/memberships through your app's authorized POST setup.\nTest users are verified and visible to this project's server user lookup.\nFor the complete owner-adds-member-by-email test and its endpoints, run\nsomewhere docs test and follow Two users sharing through the app.\nDiagnose with somewhere errors and somewhere logs.\n\nOn demand:\n- Server paging: `somewhere docs sw.db --section server-read-paging`\n\n## Testing shared access\n\nWith the teams and membership endpoints above, the owner adds a fixture by email\nand that fixture reads the shared team row:\n\n```ts\n// tests/team.spec.ts\nimport { test, expect, data } from '@somewhere-cloud/cli/testing';\ntest('owner adds a second user by email', async ({ newUser }) => {\n const owner = await newUser();\n const bob = await newUser();\n const name = `Shared team ${crypto.randomUUID()}`;\n const created = await owner.request.post('/api/teams', { data: { name } });\n expect(created.ok()).toBeTruthy();\n const { id } = await created.json();\n const added = await owner.request.post(`/api/teams/${id}/members`, { data: { email: bob.email } });\n expect(added.ok()).toBeTruthy();\n const response = await data(bob.request, 'teams', { operation: 'get', id });\n expect(response.ok()).toBeTruthy();\n expect((await response.json()).data).toMatchObject({ id, name });\n});\n```\n";
|
|
2
2
|
export declare const SKILLS_POINTER = "Task-specific skills: `.agents/skills/`. Inspect/update with somewhere skills status/update.";
|
|
3
3
|
export declare const DECLARED_ACCESS_POINTER = "";
|
|
4
4
|
/** One line telling agents the app's data and code can leave:
|
|
5
5
|
* an evaluating agent concluded the platform had no exits. Kept outside
|
|
6
6
|
* AGENT_WORKFLOW, which is a byte mirror of the platform's agent workflow. */
|
|
7
7
|
export declare const PORTABILITY_POINTER = "Data/code export limits: `somewhere docs portability`.";
|
|
8
|
-
export declare const INIT_AGENTS_MD = "# somewhere.cloud project contract\n## Build, deploy, test\n\nEnough to start a typical app: declare access and use the browser client; docs are for exceptions.\n\n| Requirement | Declaration below |\n| --- | --- |\n| Each user sees only their own rows | notes: owner() |\n| Team: owner adds members; members read/write; creator rights | teams/team_members/tasks: owner() + member(); role-owner delete branch |\n| Owner/staff record with staff-only child notes | tickets: owner() or appRole(); parent() thread; staff-only notes; POST setup below |\n| Public pages from private drafts | pages: conditional publicRead |\n| Share one record read-only | shared_notes/note_shares: read-only grant() |\n\ndb/schema.ts is declaration only: imports, constants/spreads, default schema;\nno helpers/expressions. id() is random text; owner() stamps user_id. client.read\nincludes the key. Inside anyOf(), owner() takes only column/read: it stamps the\ncreator, not create/delete options; member() gates placement (non-member create is\nrefused), while creators or the allowed branch can delete. Other fields: timestamp({ default: 'now' }), text({ nullable: true });\nindexes: [['team_id']].\n\n```ts\nimport { schema, table, id, text, owner, member, anyOf, serverOnly, parent, appRole, boolean, grant } from 'somewhere/db';\nexport default schema({\n notes: table({ id: id(), title: text() }, { scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'], delete: true },\n }),\n teams: table({ id: id(), name: text(), owner_id: text() }, {\n scope: member({ group: 'id', membership: 'team_members', member_user: 'user_id', member_group: 'team_id' }),\n client: { read: ['id', 'name'] },\n }),\n team_members: table({ id: id(), team_id: text(), user_id: text(), role: text() }, {\n scope: serverOnly(), unique: [['team_id', 'user_id']],\n }),\n tasks: table({ id: id(), team_id: text({ references: 'teams' }), title: text() }, {\n scope: anyOf(owner(), member({ group: 'team_id', membership: 'team_members',\n member_user: 'user_id', member_group: 'team_id', operations: ['read', 'create', 'update'] }),\n member({ group: 'team_id', membership: 'team_members', member_user: 'user_id',\n member_group: 'team_id', where: { role: 'owner' }, operations: ['delete'] })),\n client: { read: ['id', 'team_id', 'title'], create: ['team_id', 'title'], update: ['title'], delete: true },\n }),\n tickets: table({ id: id(), subject: text() }, {\n scope: anyOf(owner(), appRole({ roles: { read: ['staff'], create: ['staff'], update: ['staff'] } })),\n client: { read: true, create: ['subject'], update: ['subject'] },\n }),\n messages: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: parent({ via: 'ticket_id' }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n staff_notes: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: appRole({ roles: { read: ['staff'], create: ['staff'] } }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n pages: table({ id: id(), title: text(), published: boolean({ default: false }) }, {\n scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'],\n publicRead: { where: { published: true } } },\n }),\n note_shares: table({ id: id(), grantee_id: text(), note_id: text({ references: 'shared_notes', onDelete: 'cascade' }) }, {\n scope: owner(), unique: [['note_id', 'grantee_id']],\n }),\n shared_notes: table({ id: id(), title: text() }, {\n scope: anyOf(owner(), grant({ table: 'note_shares', grantee: 'grantee_id', row: 'note_id', operations: ['read'] })),\n client: { read: ['id', 'title'], create: ['title'], update: ['title'] },\n }),\n}, { appRoles: { staff: { assignedBy: 'server' } } });\n```\n\nPOST role setup once after sign-up/profile completion, not GET/every request:\ncookie-authenticated GET cannot mutate roles.\nCheck admin here, or your own assignment rule.\nmessages use parent(): owner() would hide staff replies from the customer.\nUse emailDomain for staff at your verified domain; assignedBy: 'server' when the\napp decides (promotion, payment, invitation). An email ending proves identity only\nwhen verified; assigning a role anyway is your app's decision, whose permissions the platform enforces.\nPublish pages in an owner-checked endpoint. Share with caller-scoped\nsw.db.insert('note_shares', { grantee_id, note_id }); it checks row ownership.\nBrowser calls THROW, not { error }; catch below.\nBrowser list: max 100, paginate after; no order (sort locally or in an endpoint).\n\n```ts\nimport { data } from 'somewhere:data';\nexport async function save(title: string) {\n try { await data.notes.create({ title }); return null; }\n catch (e) { return e instanceof Error ? e.message : 'Save failed'; }\n}\nexport const list = (after?: string) => data.notes.list({ limit: 100, after });\n```\n\nTeams without verification: own membership table + member(); sw.groups and domain\nroles need VERIFIED emails. Members read/create/update tasks; creators or team owners delete while members.\nRestrictions narrow operations, not grant read.\nComment-author-or-team-owner deletion stays a small endpoint.\nCreate the team and its owner membership atomically:\n\n```ts\n// api/teams.ts\nexport default sw.endpoint({\n auth: 'required', body: { name: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const id = crypto.randomUUID();\n await sw.db.server.tx([\n { op: 'insert', table: 'teams', values: { id, name: body.name, owner_id: user.id } },\n { op: 'insert', table: 'team_members', values: { id: crypto.randomUUID(), team_id: id, user_id: user.id, role: 'owner' } },\n ]);\n return { id, email: user.email };\n },\n});\n```\n\n```ts\n// api/teams/[id]/members.ts \u2014 only the team owner adds a member\nexport default sw.endpoint({\n auth: 'required', body: { email: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const { data: teams } = await sw.db.from('teams', { where: { id: params.id, owner_id: user.id }, limit: 1 });\n if (!teams[0]) return Response.json({ error: 'Team owner required' }, { status: 403 });\n const { users: [target] } = await sw.auth.server.listUsers({ emails: [body.email] });\n if (!target) return Response.json({ error: 'Account not found' }, { status: 404 });\n await sw.db.server.insert('team_members', {\n id: crypto.randomUUID(), team_id: params.id, user_id: target.id, role: 'member',\n }, { onConflict: 'ignore' });\n return { ok: true };\n },\n});\n```\n\n```ts\n// api/complete-profile.ts \u2014 POST once when an admin assigns staff after sign-up\nexport default sw.endpoint({\n auth: 'required', body: { userId: 'string' },\n handler: async ({ request, body }, sw) => {\n await sw.auth.requireUser(request, { role: 'admin' });\n await sw.auth.server.setRoles(body.userId, { add: ['staff'] });\n return { ok: true };\n },\n});\n```\n\nDo not hand-write access to app-read/write data: declare who may read/write it.\nserverOnly() fits job/import/audit/counter state and protected membership ledgers.\nGrant ledgers use owner() without browser writes. Undeclarable: arbitrary predicates\n(e.g. expiry) or per-role writable fields (split tables or check that write).\n\nBuild src/pages/HomePage.tsx; routes src/App.tsx + src/routes.ts; auth src/auth/hooks.ts.\nAuth is wired: keep api/auth/[...path].ts; src/config.ts controls providers.\napi/notes/[id]/sub.ts \u2192 params.id; underscore files are helpers. POST: default export;\nGET/DELETE: named exports.\n\n```ts\nexport const GET = sw.endpoint({ auth: 'required', handler: async (_, sw) => sw.db.from('notes', { limit: 100 }) });\n```\n\nsw.db applies caller scopes; sw.db.server bypasses them: authorize first.\nReads: from(table, { where, columns, order: [['id', 'asc']], limit, offset }).\nFilter: { id: { in: ids } }; unique: [['a', 'b']] in schema.\nWrites: insert(table, values), update(table, { where, set }), remove(table, { where }).\ntx takes an ARRAY of write intents, never a callback; pre-generate related IDs.\n\nBrowser: fetch(path, { method: 'POST', credentials: 'same-origin',\nheaders: { 'content-type': 'application/json' }, body: JSON.stringify(values) }).\nAccess cookies refresh automatically. Cookie-auth POST/PATCH/DELETE from scripts\nneed Origin equal to the app URL.\n\nPublish: somewhere typecheck \u2192 npx @somewhere-cloud/cli deploy \u2192 somewhere verify \u2192 somewhere test.\nDeploy raw source, no frontend build. Type errors stop upload; override: somewhere deploy --allow-type-errors.\nnewUser() gives a signed-in page/API client; call N times (owner, member, outsider).\nNo chosen email argument: assign roles/memberships through your app's authorized POST setup.\nDiagnose with somewhere errors and somewhere logs.\n\nOn demand:\n- Server paging: `somewhere docs sw.db --section server-read-paging`\n\nTask-specific skills: `.agents/skills/`. Inspect/update with somewhere skills status/update.\nData/code export limits: `somewhere docs portability`.\n";
|
|
8
|
+
export declare const INIT_AGENTS_MD = "# somewhere.cloud project contract\n## Build, deploy, test\n\nEnough to start a typical app: declare access and use the browser client; docs are for exceptions.\n\n| Requirement | Declaration below |\n| --- | --- |\n| Each user sees only their own rows | notes: owner() |\n| Team: owner adds members; members read/write; creator rights | teams/team_members/tasks: owner() + member(); role-owner delete branch |\n| Owner/staff record with staff-only child notes | tickets: owner() or appRole(); parent() thread; staff-only notes; POST setup below |\n| Public pages from private drafts | pages: conditional publicRead |\n| Share one record read-only | shared_notes/note_shares: read-only grant() |\n\ndb/schema.ts is declaration only: imports, constants/spreads, default schema;\nno helpers/expressions. id() is random text; owner() stamps user_id. client.read\nincludes the key. Inside anyOf(), owner() takes only column/read: it stamps the\ncreator, not create/delete options; member() gates placement (non-member create is\nrefused), while creators or the allowed branch can delete. Other fields: timestamp({ default: 'now' }), text({ nullable: true });\nindexes: [['team_id']].\n\n```ts\nimport { schema, table, id, text, owner, member, anyOf, serverOnly, parent, appRole, boolean, grant } from 'somewhere/db';\nexport default schema({\n notes: table({ id: id(), title: text() }, { scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'], delete: true },\n }),\n teams: table({ id: id(), name: text(), owner_id: text() }, {\n scope: member({ group: 'id', membership: 'team_members', member_user: 'user_id', member_group: 'team_id' }),\n client: { read: ['id', 'name'] },\n }),\n team_members: table({ id: id(), team_id: text(), user_id: text(), role: text() }, {\n scope: serverOnly(), unique: [['team_id', 'user_id']],\n }),\n tasks: table({ id: id(), team_id: text({ references: 'teams' }), title: text() }, {\n scope: anyOf(owner(), member({ group: 'team_id', membership: 'team_members',\n member_user: 'user_id', member_group: 'team_id', operations: ['read', 'create', 'update'] }),\n member({ group: 'team_id', membership: 'team_members', member_user: 'user_id',\n member_group: 'team_id', where: { role: 'owner' }, operations: ['delete'] })),\n client: { read: ['id', 'team_id', 'title'], create: ['team_id', 'title'], update: ['title'], delete: true },\n }),\n tickets: table({ id: id(), subject: text() }, {\n scope: anyOf(owner(), appRole({ roles: { read: ['staff'], create: ['staff'], update: ['staff'] } })),\n client: { read: true, create: ['subject'], update: ['subject'] },\n }),\n messages: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: parent({ via: 'ticket_id' }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n staff_notes: table({ id: id(), ticket_id: text({ references: 'tickets' }), body: text() }, {\n scope: appRole({ roles: { read: ['staff'], create: ['staff'] } }),\n client: { read: true, create: ['ticket_id', 'body'] },\n }),\n pages: table({ id: id(), title: text(), published: boolean({ default: false }) }, {\n scope: owner(), client: { read: ['id', 'title'], create: ['title'], update: ['title'],\n publicRead: { where: { published: true } } },\n }),\n note_shares: table({ id: id(), grantee_id: text(), note_id: text({ references: 'shared_notes', onDelete: 'cascade' }) }, {\n scope: owner(), unique: [['note_id', 'grantee_id']],\n }),\n shared_notes: table({ id: id(), title: text() }, {\n scope: anyOf(owner(), grant({ table: 'note_shares', grantee: 'grantee_id', row: 'note_id', operations: ['read'] })),\n client: { read: ['id', 'title'], create: ['title'], update: ['title'] },\n }),\n}, { appRoles: { staff: { assignedBy: 'server' } } });\n```\n\nPOST role setup once after sign-up/profile completion, not GET/every request:\ncookie-authenticated GET cannot mutate roles.\nCheck admin here, or your own assignment rule.\nmessages use parent(): owner() would hide staff replies from the customer.\nUse emailDomain for staff at your verified domain; assignedBy: 'server' when the\napp decides (promotion, payment, invitation). An email ending proves identity only\nwhen verified; assigning a role anyway is your app's decision, whose permissions the platform enforces.\nPublish pages in an owner-checked endpoint. Share with caller-scoped\nsw.db.insert('note_shares', { grantee_id, note_id }); it checks row ownership.\nBrowser calls THROW, not { error }; catch below.\nBrowser list: max 100, paginate after; no order (sort locally or in an endpoint).\n\n```ts\nimport { data } from 'somewhere:data';\nexport async function save(title: string) {\n try { await data.notes.create({ title }); return null; }\n catch (e) { return e instanceof Error ? e.message : 'Save failed'; }\n}\nexport const list = (after?: string) => data.notes.list({ limit: 100, after });\n```\n\nTeams without verification: own membership table + member(); sw.groups and domain\nroles need VERIFIED emails. Members read/create/update tasks; creators or team owners delete while members.\nRestrictions narrow operations, not grant read.\nComment-author-or-team-owner deletion stays a small endpoint.\nCreate the team and its owner membership atomically:\n\n```ts\n// api/teams.ts\nexport default sw.endpoint({\n auth: 'required', body: { name: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const id = crypto.randomUUID();\n await sw.db.server.tx([\n { op: 'insert', table: 'teams', values: { id, name: body.name, owner_id: user.id } },\n { op: 'insert', table: 'team_members', values: { id: crypto.randomUUID(), team_id: id, user_id: user.id, role: 'owner' } },\n ]);\n return { id, email: user.email };\n },\n});\n```\n\n```ts\n// api/teams/[id]/members.ts \u2014 only the team owner adds a member\nexport default sw.endpoint({\n auth: 'required', body: { email: 'string' },\n handler: async ({ user, params, body }, sw) => {\n const { data: teams } = await sw.db.from('teams', { where: { id: params.id, owner_id: user.id }, limit: 1 });\n if (!teams[0]) return Response.json({ error: 'Team owner required' }, { status: 403 });\n const { users: [target] } = await sw.auth.server.listUsers({ emails: [body.email] });\n if (!target) return Response.json({ error: 'Account not found' }, { status: 404 });\n await sw.db.server.insert('team_members', {\n id: crypto.randomUUID(), team_id: params.id, user_id: target.id, role: 'member',\n }, { onConflict: 'ignore' });\n return { ok: true };\n },\n});\n```\n\n```ts\n// api/complete-profile.ts \u2014 POST once when an admin assigns staff after sign-up\nexport default sw.endpoint({\n auth: 'required', body: { userId: 'string' },\n handler: async ({ request, body }, sw) => {\n await sw.auth.requireUser(request, { role: 'admin' });\n await sw.auth.server.setRoles(body.userId, { add: ['staff'] });\n return { ok: true };\n },\n});\n```\n\nDo not hand-write access to app-read/write data: declare who may read/write it.\nserverOnly() fits job/import/audit/counter state and protected membership ledgers.\nGrant ledgers use owner() without browser writes. Undeclarable: arbitrary predicates\n(e.g. expiry) or per-role writable fields (split tables or check that write).\n\nBuild src/pages/HomePage.tsx; routes src/App.tsx + src/routes.ts; auth src/auth/hooks.ts.\nAuth is wired: keep api/auth/[...path].ts; src/config.ts controls providers.\napi/notes/[id]/sub.ts \u2192 params.id; underscore files are helpers. POST: default export;\nGET/DELETE: named exports.\n\n```ts\nexport const GET = sw.endpoint({ auth: 'required', handler: async (_, sw) => sw.db.from('notes', { limit: 100 }) });\n```\n\nsw.db applies caller scopes; sw.db.server bypasses them: authorize first.\nReads: from(table, { where, columns, order: [['id', 'asc']], limit, offset }).\nFilter: { id: { in: ids } }; unique: [['a', 'b']] in schema.\nWrites: insert(table, values), update(table, { where, set }), remove(table, { where }).\ntx takes an ARRAY of write intents, never a callback; pre-generate related IDs.\n\nBrowser: fetch(path, { method: 'POST', credentials: 'same-origin',\nheaders: { 'content-type': 'application/json' }, body: JSON.stringify(values) }).\nAccess cookies refresh automatically. Cookie-auth POST/PATCH/DELETE from scripts\nneed Origin equal to the app URL.\n\nPublish: somewhere typecheck \u2192 npx @somewhere-cloud/cli deploy \u2192 somewhere verify \u2192 somewhere test.\nDeploy raw source, no frontend build. Type errors stop upload; override: somewhere deploy --allow-type-errors.\nnewUser() gives a signed-in page/API client; call N times (owner, member, outsider).\nNo chosen email argument: assign roles/memberships through your app's authorized POST setup.\nTest users are verified and visible to this project's server user lookup.\nFor the complete owner-adds-member-by-email test and its endpoints, run\nsomewhere docs test and follow Two users sharing through the app.\nDiagnose with somewhere errors and somewhere logs.\n\nOn demand:\n- Server paging: `somewhere docs sw.db --section server-read-paging`\n\n## Testing shared access\n\nWith the teams and membership endpoints above, the owner adds a fixture by email\nand that fixture reads the shared team row:\n\n```ts\n// tests/team.spec.ts\nimport { test, expect, data } from '@somewhere-cloud/cli/testing';\ntest('owner adds a second user by email', async ({ newUser }) => {\n const owner = await newUser();\n const bob = await newUser();\n const name = `Shared team ${crypto.randomUUID()}`;\n const created = await owner.request.post('/api/teams', { data: { name } });\n expect(created.ok()).toBeTruthy();\n const { id } = await created.json();\n const added = await owner.request.post(`/api/teams/${id}/members`, { data: { email: bob.email } });\n expect(added.ok()).toBeTruthy();\n const response = await data(bob.request, 'teams', { operation: 'get', id });\n expect(response.ok()).toBeTruthy();\n expect((await response.json()).data).toMatchObject({ id, name });\n});\n```\n\nTask-specific skills: `.agents/skills/`. Inspect/update with somewhere skills status/update.\nData/code export limits: `somewhere docs portability`.\n";
|
|
9
9
|
export declare const INIT_CLAUDE_MD = "Read AGENTS.md for project instructions.\n";
|
|
@@ -165,10 +165,36 @@ Publish: somewhere typecheck → npx @somewhere-cloud/cli deploy → somewhere v
|
|
|
165
165
|
Deploy raw source, no frontend build. Type errors stop upload; override: somewhere deploy --allow-type-errors.
|
|
166
166
|
newUser() gives a signed-in page/API client; call N times (owner, member, outsider).
|
|
167
167
|
No chosen email argument: assign roles/memberships through your app's authorized POST setup.
|
|
168
|
+
Test users are verified and visible to this project's server user lookup.
|
|
169
|
+
For the complete owner-adds-member-by-email test and its endpoints, run
|
|
170
|
+
somewhere docs test and follow Two users sharing through the app.
|
|
168
171
|
Diagnose with somewhere errors and somewhere logs.
|
|
169
172
|
|
|
170
173
|
On demand:
|
|
171
174
|
- Server paging: \`somewhere docs sw.db --section server-read-paging\`
|
|
175
|
+
|
|
176
|
+
## Testing shared access
|
|
177
|
+
|
|
178
|
+
With the teams and membership endpoints above, the owner adds a fixture by email
|
|
179
|
+
and that fixture reads the shared team row:
|
|
180
|
+
|
|
181
|
+
\`\`\`ts
|
|
182
|
+
// tests/team.spec.ts
|
|
183
|
+
import { test, expect, data } from '@somewhere-cloud/cli/testing';
|
|
184
|
+
test('owner adds a second user by email', async ({ newUser }) => {
|
|
185
|
+
const owner = await newUser();
|
|
186
|
+
const bob = await newUser();
|
|
187
|
+
const name = \`Shared team \${crypto.randomUUID()}\`;
|
|
188
|
+
const created = await owner.request.post('/api/teams', { data: { name } });
|
|
189
|
+
expect(created.ok()).toBeTruthy();
|
|
190
|
+
const { id } = await created.json();
|
|
191
|
+
const added = await owner.request.post(\`/api/teams/\${id}/members\`, { data: { email: bob.email } });
|
|
192
|
+
expect(added.ok()).toBeTruthy();
|
|
193
|
+
const response = await data(bob.request, 'teams', { operation: 'get', id });
|
|
194
|
+
expect(response.ok()).toBeTruthy();
|
|
195
|
+
expect((await response.json()).data).toMatchObject({ id, name });
|
|
196
|
+
});
|
|
197
|
+
\`\`\`
|
|
172
198
|
`;
|
|
173
199
|
export const SKILLS_POINTER = `Task-specific skills: \`${SKILLS_DIR}/\`. Inspect/update with somewhere skills status/update.`;
|
|
174
200
|
export const DECLARED_ACCESS_POINTER = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-agent-guide.js","sourceRoot":"","sources":["../../src/lib/init-agent-guide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,2EAA2E;AAC3E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG
|
|
1
|
+
{"version":3,"file":"init-agent-guide.js","sourceRoot":"","sources":["../../src/lib/init-agent-guide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,2EAA2E;AAC3E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkM7B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,UAAU,0DAA0D,CAAC;AAE9H,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C;;+EAE+E;AAC/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,wDAAwD,CAAC;AAE5F,MAAM,CAAC,MAAM,cAAc,GAAG,uCAAuC,cAAc,KAAK,cAAc,KAAK,mBAAmB,IAAI,CAAC;AACnI,MAAM,CAAC,MAAM,cAAc,GAAG,4CAA4C,CAAC"}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@somewhere-cloud/cli",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.75",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@somewhere-cloud/cli",
|
|
9
|
-
"version": "0.38.
|
|
9
|
+
"version": "0.38.75",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@modelcontextprotocol/sdk",
|
|
12
12
|
"chokidar",
|