cloudgpu-mcp 0.6.0 → 0.7.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
@@ -261,3 +261,14 @@ MIT, see [LICENSE](LICENSE).
261
261
  Use `list_workspace_instances`, then `get_workspace_application` with the saved `version_id` and the selected `instance_id`. After the user agrees, call `apply_workspace` with `user_confirmed: true`, then poll status. The files appear in a new private project directory; existing files are never overwritten. This does not install dependencies, execute project code or start, stop, or restart a GPU. Rental billing continues during transfer. Budgeted Agent keys can only target instances created with the same key. Workspace requires a funded account.
262
262
 
263
263
  Repeated application of the same version to the same instance returns the existing result, including user edits after success. On `needs_attention`, `failed` or `conflict`, inspect the result rather than automatically retrying. A new saved version creates a separate directory. The feature must be enabled by the server; unavailable storage does not disable ordinary GPU rental or Job tools.
264
+
265
+
266
+ ## Small Job output snapshots and diagnosis (0.7.0)
267
+
268
+ This branch adds `diagnose_job` (read-only) and `save_job_output` (explicit storage write). Check the installed tool list before using them; they are not a claim about the currently published npm release.
269
+
270
+ `save_job_output` stores only the ended Job output tail as a small Artifact. It is not a full log, file collector, disk snapshot or automatic backup. Known credential patterns and queried URLs are refused. Review output for other sensitive data before approving storage. Existing eligibility, quota, retention and explicit paid-storage consent apply; the GPU Job budget does not authorize paid storage. No GPU is created, kept alive or stopped by these tools. Matching snapshots are verified and reused when found; concurrent different client processes may still create duplicate artifacts.
271
+
272
+ `diagnose_job` reports the error category, platform instance status and whether platform charges are final. It does not prove supplier release, infer that command failures are always user errors, or automatically rerun work. `needs_attention` requires resource reconciliation before a new task. A rerun requires a fresh quote, explicit approval and a new idempotency key.
273
+
274
+ Registry configuration allows discovery and connect-link approval without pre-entering a key. A tool-enabled MCP client is still required; a link does not install a client or grant unlimited spending. No new fixed infrastructure or model storage is introduced.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudgpu-mcp",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "mcpName": "io.github.mrhy7176/cloudgpu-mcp",
5
5
  "description": "MCP server and command-line tool for cloudgpu.app: let Claude Code, Cursor, Cline, opencode, goose and other MCP clients (or you, from a terminal) rent a GPU per minute, run a job, fetch the results and shut it down, with spending limits the platform enforces.",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -19,6 +19,7 @@ import { SshPool, exec, upload, download, writeFile } from "./ssh.js";
19
19
  import { loadStoredKey, saveStoredKey } from "./credentials.js";
20
20
  import crypto from "node:crypto";
21
21
  import { registerStorageTools } from "./storage.js";
22
+ import { registerJobResultTools } from "./job-results.js";
22
23
  import {
23
24
  checkCommand,
24
25
  sensitiveReason,
@@ -30,7 +31,7 @@ import {
30
31
  shq,
31
32
  } from "./guards.js";
32
33
 
33
- const VERSION = "0.6.0";
34
+ const VERSION = "0.7.0";
34
35
  const HERE = path.dirname(fileURLToPath(import.meta.url));
35
36
  const RULES = fs.readFileSync(path.join(HERE, "..", "rules", "cloudgpu.md"), "utf8");
36
37
 
@@ -64,6 +65,7 @@ The same API key also works for the OpenAI-compatible model API at ${cfg.baseUrl
64
65
 
65
66
  const server = new McpServer({ name: "cloudgpu", version: VERSION }, { instructions: INSTRUCTIONS });
66
67
  registerStorageTools(server, { api, wrap, ok, fail, readOnly: cfg.readOnly, expandHome });
68
+ registerJobResultTools(server, { api, wrap, ok, readOnly: cfg.readOnly });
67
69
 
68
70
  // ── helpers ──────────────────────────────────────────────────────────────
69
71
 
@@ -772,5 +774,5 @@ process.on("SIGINT", bye);
772
774
  process.on("SIGTERM", bye);
773
775
  process.stdin.on("close", bye);
774
776
  if (!cfg.apiKey) {
775
- console.error("cloudgpu-mcp: CLOUDGPU_API_KEY is not set; tools will return an error until it is. Create a key at https://cloudgpu.app/api");
777
+ console.error("cloudgpu-mcp: no saved key. Public discovery is available; use connect_account and finish_connect for owner-approved access.");
776
778
  }
@@ -0,0 +1,54 @@
1
+ // 轻量 D14:只保存已结束 Job 的有限输出,不访问 GPU、不增加 GPU 等待时间。
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import {createHash} from 'node:crypto';
6
+ import {z} from 'zod';
7
+ import {PersistentStorage} from './storage.js';
8
+ const terminal=new Set(['succeeded','failed','cancelled']);
9
+ const idSchema=z.string().regex(/^job_[a-f0-9]{32}$/);
10
+ const locks=new Map();
11
+ function assertId(id){if(!/^job_[a-f0-9]{32}$/.test(id))throw Error('Invalid Job ID.');}
12
+ export function checkedTail(text,apiKey){
13
+ if(typeof text!=='string'||Buffer.byteLength(text)>16384)throw Error('Job output tail exceeds the bounded snapshot limit.');
14
+ const secrets=[/-----BEGIN [^-]*PRIVATE KEY-----/,/\bsk-[A-Za-z0-9_-]{16,}/,/\b(?:password|secret|token|api[_-]?key|authorization)\s*[:=]\s*["']?[^\s"',}]+/i,/https?:\/\/[^\s]+\?[^\s]+/i];
15
+ if((apiKey&&apiKey.length>=4&&text.includes(apiKey))||secrets.some(re=>re.test(text)))throw Error('Output may contain credentials or a signed URL. Sanitize it before saving; nothing was uploaded.');
16
+ return text;
17
+ }
18
+ export async function diagnoseJob(api,id){
19
+ assertId(id);const job=await api.job(id);const code=job.error?.code||null;
20
+ let observed='not_checked';if(job.instance_id){try{const r=await api.instance(job.instance_id);observed=String(r.status);}catch{observed='unavailable';}}
21
+ const groups={model_load_failed:'model_preparation',workspace_restore_failed:'workspace_restore',workspace_unavailable:'workspace_restore',command_failed:'command_execution',instance_unreachable:'connectivity',command_lost:'execution_lost',insufficient_balance:'funding',cannot_create:'provisioning'};
22
+ let category=job.status==='needs_attention'?'release_uncertainty':groups[code]||(job.status==='succeeded'?'completed':'inspect_job');
23
+ return {job_id:job.id,status:job.status,category,error_code:code,observed_instance_status:observed,
24
+ supplier_release_verified:false,cost_usd:job.cost_usd,cost_status:job.cost_status,
25
+ cost_note:job.cost_status==='final'?'Final platform Job charge.':'Unsettled; may include preauthorisation and refunds not yet applied.',
26
+ automatic_retry_allowed:false,next:category==='release_uncertainty'?'Stop and ask support to reconcile resources; do not create another GPU.':job.status==='succeeded'?'Reuse the Workspace and parameters only after a fresh quote and explicit budget approval.':'Inspect the error and remaining resources. Do not blame user code or rerun automatically; obtain a fresh quote and approval for a new Job.'};
27
+ }
28
+ async function saveOne(api,storage,id,acceptCharges){
29
+ const job=await api.job(id);if(!terminal.has(job.status))throw Error('Wait until the Job has ended; no running GPU will be changed.');
30
+ const logs=await api.jobLogs(id);const tail=checkedTail(logs.tail??job.output_tail??'',api.apiKey);
31
+ const content=JSON.stringify({object:'job_output_tail',job_id:job.id,status:job.status,tail_only:true,complete_output:false,output_tail:tail},null,2)+'\n';
32
+ const sha=createHash('sha256').update(content).digest('hex');const name=`${id}-${sha.slice(0,16)}.json`;
33
+ // 同一客户端串行保存并核验已有内容。跨进程不承诺exactly-once。
34
+ const files=(await api.request('GET','/v1/files')).data||[];
35
+ const existing=files.find(f=>f.name===name&&f.purpose==='artifact'&&f.status==='ready'&&Number(f.size_bytes)===Buffer.byteLength(content));
36
+ const dir=await fs.mkdtemp(path.join(os.tmpdir(),'cgpu-job-output-'));
37
+ try{
38
+ const local=path.join(dir,'output.json');
39
+ if(existing){await storage.download(existing.file_id,local);if(createHash('sha256').update(await fs.readFile(local)).digest('hex')!==sha)throw Error('Existing snapshot does not match; inspect it before saving another.');return {file_id:existing.file_id,reused:true,tail_only:true,complete_output:false,sha256:sha};}
40
+ await fs.writeFile(local,content,{mode:0o600});const saved=await storage.upload(local,'artifact',name,acceptCharges===true);
41
+ return {...saved,reused:false,tail_only:true,complete_output:false,sha256:sha};
42
+ }finally{await fs.rm(dir,{recursive:true,force:true});}
43
+ }
44
+ export async function saveJobOutput(api,storage,id,confirmed,acceptCharges=false){
45
+ assertId(id);if(confirmed!==true)throw Error('Ask the user before storing Job output.');
46
+ const previous=locks.get(id)||Promise.resolve();const current=previous.catch(()=>{}).then(()=>saveOne(api,storage,id,acceptCharges));locks.set(id,current);
47
+ try{return await current;}finally{if(locks.get(id)===current)locks.delete(id);}
48
+ }
49
+ export function registerJobResultTools(server,{api,wrap,ok,readOnly}){
50
+ const storage=new PersistentStorage(api);
51
+ server.registerTool('diagnose_job',{title:'Inspect Job failure and cost state',description:'Read-only Job diagnosis and observed platform instance state. Never creates, stops or retries a GPU. Does not claim supplier release verification or classify every command failure as user error.',inputSchema:{job_id:idSchema},annotations:{readOnlyHint:true,openWorldHint:true}},wrap(async({job_id})=>ok(await diagnoseJob(api,job_id))));
52
+ if(readOnly)return;
53
+ server.registerTool('save_job_output',{title:'Save ended Job output tail',description:'With approval, persist the ended Job log tail as a small Artifact using existing storage quota and retention. This is not the full log or binary output collection. Refuses recognizable credentials and queried URLs. Never touches GPU resources. Reuses a matching verified snapshot when found; cross-client concurrent calls may create duplicates.',inputSchema:{job_id:idSchema,user_confirmed:z.boolean(),accept_storage_charges:z.boolean().default(false)},annotations:{readOnlyHint:false,destructiveHint:false,idempotentHint:false,openWorldHint:true}},wrap(async({job_id,user_confirmed,accept_storage_charges})=>ok(await saveJobOutput(api,storage,job_id,user_confirmed,accept_storage_charges))));
54
+ }