kowlun 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -20,6 +20,8 @@ kowlun deploy [dir] deploy a folder with app.json (new version)
20
20
  kowlun list my apps
21
21
  kowlun info <name> versions of an app
22
22
  kowlun rollback <name> [v] roll back to a previous version
23
+ kowlun share <name> who can see it + share link (--private | --link | --public, --new-link)
24
+ kowlun pull <name> [dir] download your app's code (e.g. a copy you took) to change it
23
25
  kowlun mcp MCP server for agents (stdio)
24
26
  kowlun logout
25
27
  ```
@@ -40,7 +42,7 @@ Cursor, `.cursor/mcp.json`:
40
42
  { "mcpServers": { "kowlun": { "command": "npx", "args": ["-y", "kowlun", "mcp"] } } }
41
43
  ```
42
44
 
43
- Tools: `kowlun_deploy`, `kowlun_list`, `kowlun_info`, `kowlun_rollback`, `kowlun_whoami`. Sign in once with `npx kowlun login` before using them.
45
+ Tools: `kowlun_deploy`, `kowlun_list`, `kowlun_info`, `kowlun_rollback`, `kowlun_share`, `kowlun_pull`, `kowlun_whoami`. Sign in once with `npx kowlun login` before using them.
44
46
 
45
47
  ## App format
46
48
 
package/dist/core.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Действия с платформой, общие для CLI и MCP-сервера. Ничего не печатают и не завершают процесс:
2
2
  // возвращают данные или бросают CliError с понятным сообщением.
3
- import { readFile, readdir, stat } from "node:fs/promises";
4
- import { join, relative, resolve, sep } from "node:path";
3
+ import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
4
+ import { dirname, join, relative, resolve, sep } from "node:path";
5
5
  import { loadConfig } from "./config.js";
6
6
  import { lang, say } from "./i18n.js";
7
7
  export class CliError extends Error {
@@ -105,3 +105,71 @@ export async function rollback(name, version) {
105
105
  export async function whoami() {
106
106
  return (await api("/v1/me")).user;
107
107
  }
108
+ export const VISIBILITIES = ["private", "link", "public"];
109
+ const json = (method, body = {}) => ({
110
+ method,
111
+ headers: { "content-type": "application/json" },
112
+ body: JSON.stringify(body),
113
+ });
114
+ export async function getAccess(name) {
115
+ return api(`/v1/apps/${encodeURIComponent(name)}/access`);
116
+ }
117
+ export async function setVisibility(name, visibility) {
118
+ return api(`/v1/apps/${encodeURIComponent(name)}/access`, json("PUT", { visibility }));
119
+ }
120
+ export async function newShareLink(name) {
121
+ return api(`/v1/apps/${encodeURIComponent(name)}/share-link`, json("POST"));
122
+ }
123
+ /** Описание доступа одной-двумя строками (для CLI и MCP). */
124
+ export function describeAccess(a) {
125
+ const vis = {
126
+ private: say("only you (private)", "только вам (закрытая)"),
127
+ link: say("anyone with the link", "всем, у кого есть ссылка"),
128
+ public: say("public: by link and in the catalog", "всем: по ссылке и в каталоге"),
129
+ }[a.visibility];
130
+ const lines = [`${a.title} (${a.name}) — ${say("visible to", "видна")}: ${vis}`];
131
+ if (a.visibility === "public") {
132
+ lines.push(a.review === "approved"
133
+ ? say("Approved and listed in the catalog.", "Одобрена и есть в каталоге.")
134
+ : a.review === "rejected"
135
+ ? say("Not approved for the catalog; works by link.", "В каталог не прошла; по ссылке работает.")
136
+ : say("Under review: appears in the catalog once approved. Each new version is reviewed again.", "На проверке: появится в каталоге после одобрения. Каждая новая версия проверяется заново."));
137
+ }
138
+ if (a.shareUrl)
139
+ lines.push(`${say("Share link", "Ссылка")}: ${a.shareUrl}`);
140
+ if (a.takes)
141
+ lines.push(say(`Copies taken: ${a.takes}`, `Забрали себе: ${a.takes}`));
142
+ if (a.copy && a.source) {
143
+ lines.push(say(`This is your copy of “${a.source.title}” by ${a.source.owner ?? "?"}.`, `Это ваша копия «${a.source.title}» от ${a.source.owner ?? "?"}.`));
144
+ if (a.updateAvailable)
145
+ lines.push(say("The author released an update — open the app settings in Kowlun to update.", "Автор выпустил обновление — обновить можно в настройках апки в Kowlun."));
146
+ }
147
+ return lines;
148
+ }
149
+ export async function pull(name, dirArg) {
150
+ const dir = resolve(dirArg ?? name);
151
+ const existing = await readdir(dir).catch(() => []);
152
+ if (existing.length)
153
+ throw new CliError(say(`Folder ${dir} is not empty. Choose an empty or new folder.`, `Папка ${dir} не пустая. Укажите пустую или новую.`));
154
+ const list = await api(`/v1/apps/${encodeURIComponent(name)}/files`);
155
+ const config = await loadConfig();
156
+ let bytes = 0;
157
+ for (const f of list.files) {
158
+ const target = resolve(dir, f.path);
159
+ if (!target.startsWith(dir + sep))
160
+ throw new CliError(say(`Unsafe file path: ${f.path}`, `Небезопасный путь файла: ${f.path}`));
161
+ const res = await fetch(`${config.api}/v1/apps/${encodeURIComponent(name)}/files/${f.path.split("/").map(encodeURIComponent).join("/")}`, {
162
+ headers: { authorization: `Bearer ${config.token}` },
163
+ });
164
+ if (!res.ok)
165
+ throw new CliError(say(`Couldn't download ${f.path} (${res.status}).`, `Не получилось скачать ${f.path} (${res.status}).`));
166
+ const data = Buffer.from(await res.arrayBuffer());
167
+ await mkdir(dirname(target), { recursive: true });
168
+ await writeFile(target, data);
169
+ bytes += data.length;
170
+ }
171
+ // app.json — от этой апки: имя = её имя (у копии оно своё), остальное из манифеста версии.
172
+ await mkdir(dir, { recursive: true });
173
+ await writeFile(join(dir, "app.json"), JSON.stringify({ ...list.manifest, name: list.app }, null, 2) + "\n");
174
+ return { app: list.app, version: list.version, dir, files: list.files.length, bytes };
175
+ }
package/dist/index.js CHANGED
@@ -8,15 +8,17 @@
8
8
  // kowlun list мои апки
9
9
  // kowlun info <name> версии апки
10
10
  // kowlun rollback <name> откатить на прошлую версию
11
+ // kowlun share <name> кому видна апка и ссылка «Поделиться» (--private | --link | --public, --new-link)
12
+ // kowlun pull <name> [dir] скачать код своей апки (например, забранной копии), чтобы доработать
11
13
  // kowlun mcp MCP-сервер для агентов (stdio)
12
14
  //
13
15
  // Переменные окружения: KOWLUN_API (адрес платформы), KOWLUN_TOKEN (токен вместо входа, для CI).
14
16
  import { Command } from "commander";
15
17
  import { spawn } from "node:child_process";
16
18
  import { clearConfig, configPath, loadConfig, saveConfig } from "./config.js";
17
- import { appInfo, CliError, deploy, http, kb, listApps, rollback, whoami } from "./core.js";
19
+ import { appInfo, CliError, deploy, describeAccess, getAccess, http, kb, listApps, newShareLink, pull, rollback, setVisibility, whoami } from "./core.js";
18
20
  import { filesCount, say } from "./i18n.js";
19
- const VERSION = "0.3.0";
21
+ const VERSION = "0.4.0";
20
22
  const CLIENT_ID = "kowlun-cli";
21
23
  function fail(message) {
22
24
  console.error(`✖ ${message}`);
@@ -165,6 +167,37 @@ program
165
167
  const r = await rollback(name, version);
166
168
  console.log(say(`✔ ${name} is now on version ${r.version}`, `✔ ${name} теперь на версии ${r.version}`));
167
169
  }));
170
+ program
171
+ .command("share")
172
+ .description(say("Who can see the app, and its share link", "Кому видна апка и ссылка «Поделиться»"))
173
+ .argument("<name>")
174
+ .option("--private", say("only you", "только вам"))
175
+ .option("--link", say("anyone with the link can see it and take a copy", "всем по ссылке: видят апку и могут забрать копию"))
176
+ .option("--public", say("by link and in the catalog (after review)", "по ссылке и в каталоге (после проверки)"))
177
+ .option("--new-link", say("make a new link; the old one stops working", "сделать новую ссылку; старая перестанет работать"))
178
+ .action(run(async (name, o) => {
179
+ const chosen = ["private", "link", "public"].filter((v) => o[v]);
180
+ if (chosen.length > 1)
181
+ fail(say("Choose one: --private, --link or --public.", "Выберите одно: --private, --link или --public."));
182
+ let a = chosen.length ? await setVisibility(name, chosen[0]) : await getAccess(name);
183
+ if (o.newLink) {
184
+ if (a.visibility === "private")
185
+ fail(say("A private app has no link. Use --link first.", "У закрытой апки нет ссылки. Сначала --link."));
186
+ a = await newShareLink(name);
187
+ }
188
+ for (const line of describeAccess(a))
189
+ console.log(line);
190
+ }));
191
+ program
192
+ .command("pull")
193
+ .description(say("Download your app's code (e.g. a copy you took) to change it", "Скачать код своей апки (например, забранной копии), чтобы доработать"))
194
+ .argument("<name>")
195
+ .argument("[dir]", say("empty or new folder (default: app name)", "пустая или новая папка (по умолчанию — имя апки)"))
196
+ .action(run(async (name, dir) => {
197
+ const r = await pull(name, dir);
198
+ console.log(say(`✔ ${r.app}: version ${r.version} saved to ${r.dir}`, `✔ ${r.app}: версия ${r.version} сохранена в ${r.dir}`) + ` (${filesCount(r.files)}, ${kb(r.bytes)})`);
199
+ console.log(say(`Change it and deploy back: npx kowlun deploy ${r.dir}`, `Доработайте и залейте обратно: npx kowlun deploy ${r.dir}`));
200
+ }));
168
201
  // --- MCP ---------------------------------------------------------------------------------
169
202
  program
170
203
  .command("mcp")
package/dist/mcp.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
6
  import { z } from "zod";
7
- import { appInfo, CliError, deploy, kb, listApps, rollback, whoami } from "./core.js";
7
+ import { appInfo, CliError, deploy, describeAccess, getAccess, kb, listApps, pull, rollback, setVisibility, whoami } from "./core.js";
8
8
  const ok = (text) => ({ content: [{ type: "text", text }] });
9
9
  async function run(fn) {
10
10
  try {
@@ -27,7 +27,7 @@ export async function startMcp(version) {
27
27
  const lines = [`Deployed ${r.app}, version ${r.version} (${r.files} files, ${kb(r.bytes)}).`, `URL: ${r.url}`];
28
28
  for (const w of r.warnings)
29
29
  lines.push(`Warning: ${w}`);
30
- lines.push("Open the URL to check it. The user may be asked to sign in and allow the app on first open.");
30
+ lines.push("New apps are private (only the author can open them). Open the URL to check it; the user may be asked to sign in. To share, use kowlun_share.");
31
31
  return lines.join("\n");
32
32
  }));
33
33
  server.registerTool("kowlun_list", {
@@ -63,6 +63,28 @@ export async function startMcp(version) {
63
63
  const r = await rollback(name, version);
64
64
  return `${r.app} is now on version ${r.version}. URL: ${r.url}`;
65
65
  }));
66
+ server.registerTool("kowlun_share", {
67
+ title: "Share a Kowlun app",
68
+ description: "Show or change who can see an app, and get its share link. Visibility: private (only the author; default), " +
69
+ "link (anyone with the link sees the app profile and can take their own copy — their own data, never the author's), " +
70
+ "public (link + the shared catalog after review; every new version is reviewed again). Only change visibility when the user asked for it.",
71
+ inputSchema: {
72
+ name: z.string().describe("App name"),
73
+ visibility: z.enum(["private", "link", "public"]).optional().describe("New visibility; omit to just show the current one and the link"),
74
+ },
75
+ }, ({ name, visibility }) => run(async () => describeAccess(visibility ? await setVisibility(name, visibility) : await getAccess(name)).join("\n")));
76
+ server.registerTool("kowlun_pull", {
77
+ title: "Download a Kowlun app's code",
78
+ description: "Download the current version of one of the user's own apps (including a copy they took from someone) into an empty folder, " +
79
+ "so you can change it and deploy it back with kowlun_deploy. After changes, the copy no longer receives updates from the original author.",
80
+ inputSchema: {
81
+ name: z.string().describe("App name"),
82
+ path: z.string().describe("Absolute path to an empty or new folder"),
83
+ },
84
+ }, ({ name, path }) => run(async () => {
85
+ const r = await pull(name, path);
86
+ return `Saved ${r.app} version ${r.version} to ${r.dir} (${r.files} files, ${kb(r.bytes)}) with app.json. Deploy changes with kowlun_deploy.`;
87
+ }));
66
88
  server.registerTool("kowlun_whoami", {
67
89
  title: "Kowlun account",
68
90
  description: "Check which Kowlun account is signed in. If not signed in, ask the user to run `npx -y kowlun login` in a terminal.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kowlun",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Deploy personal AI-made apps to Kowlun (kowlun.com): CLI and MCP server for coding agents",
5
5
  "type": "module",
6
6
  "bin": {