@cloop/runner 0.0.0-stage → 0.2.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 +65 -2
- package/dist/box-SQVB3OUM.js +246 -0
- package/dist/chunk-4LFQXBWP.js +26 -0
- package/dist/chunk-4UE33DYW.js +88 -0
- package/dist/chunk-7K5W6ELQ.js +8 -0
- package/dist/chunk-CMOMRXTA.js +161 -0
- package/dist/chunk-HS5CIDQF.js +146 -0
- package/dist/chunk-IIUHGZKX.js +2316 -0
- package/dist/chunk-IR3P526R.js +131 -0
- package/dist/chunk-SQJ7ZO4G.js +69 -0
- package/dist/chunk-UYTSOW2C.js +97 -0
- package/dist/chunk-ZILLDYL4.js +150 -0
- package/dist/connect-SFXN3UHJ.js +41 -0
- package/dist/hook-activity-JHLSVNFG.js +91 -0
- package/dist/hook-session-start-BIO5QJKT.js +153 -0
- package/dist/index.js +103 -0
- package/dist/install-2AYAXFYF.js +100 -0
- package/dist/login-TLO4ZXLI.js +13 -0
- package/dist/mcp-server-VGCZ6AGJ.js +399 -0
- package/dist/runner-TOCZ4RXC.js +147 -0
- package/dist/statusline-YIRFJQWY.js +177 -0
- package/package.json +57 -5
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
api
|
|
4
|
+
} from "./chunk-4UE33DYW.js";
|
|
5
|
+
|
|
6
|
+
// src/presence.ts
|
|
7
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
8
|
+
import { randomUUID } from "crypto";
|
|
9
|
+
import { hostname, platform as osPlatform } from "os";
|
|
10
|
+
|
|
11
|
+
// src/git.ts
|
|
12
|
+
import { execFileSync } from "child_process";
|
|
13
|
+
import { basename } from "path";
|
|
14
|
+
var GIT_OPTS = {
|
|
15
|
+
encoding: "utf-8",
|
|
16
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
17
|
+
timeout: 2e3
|
|
18
|
+
};
|
|
19
|
+
function getRepoName() {
|
|
20
|
+
try {
|
|
21
|
+
const remote = execFileSync("git", ["remote", "get-url", "origin"], GIT_OPTS).trim();
|
|
22
|
+
const slug = parseRemoteSlug(remote);
|
|
23
|
+
if (slug) return slug;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const top = execFileSync("git", ["rev-parse", "--show-toplevel"], GIT_OPTS).trim();
|
|
28
|
+
if (top) return basename(top);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function getBranch() {
|
|
34
|
+
try {
|
|
35
|
+
const branch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], GIT_OPTS).trim();
|
|
36
|
+
return branch && branch !== "HEAD" ? branch : null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var SLUG_PART = /^[a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?$/;
|
|
42
|
+
function parseRemoteSlug(url) {
|
|
43
|
+
const ssh = url.match(/[^:/]+[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
44
|
+
if (ssh) {
|
|
45
|
+
const owner = ssh[1];
|
|
46
|
+
const name = ssh[2];
|
|
47
|
+
if (owner && name && SLUG_PART.test(owner) && SLUG_PART.test(name)) return `${owner}/${name}`;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/presence.ts
|
|
53
|
+
var SCUTIL_OPTS = {
|
|
54
|
+
encoding: "utf-8",
|
|
55
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
56
|
+
timeout: 2e3
|
|
57
|
+
};
|
|
58
|
+
var cachedMachine = null;
|
|
59
|
+
function getMachine() {
|
|
60
|
+
if (cachedMachine === null) cachedMachine = resolveMachine();
|
|
61
|
+
return cachedMachine;
|
|
62
|
+
}
|
|
63
|
+
function resolveMachine() {
|
|
64
|
+
if (osPlatform() === "darwin") {
|
|
65
|
+
try {
|
|
66
|
+
const local = execFileSync2("scutil", ["--get", "LocalHostName"], SCUTIL_OPTS).trim();
|
|
67
|
+
if (local) return local;
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return hostname().replace(/\.local$/i, "");
|
|
72
|
+
}
|
|
73
|
+
var PLATFORM_LABELS = {
|
|
74
|
+
claude: "Claude Code",
|
|
75
|
+
codex: "Codex",
|
|
76
|
+
cowork: "Cowork"
|
|
77
|
+
};
|
|
78
|
+
function getName(platform) {
|
|
79
|
+
if (PLATFORM_LABELS[platform]) return PLATFORM_LABELS[platform];
|
|
80
|
+
if (!platform || platform === "unknown") return "Agent";
|
|
81
|
+
return platform.charAt(0).toUpperCase() + platform.slice(1);
|
|
82
|
+
}
|
|
83
|
+
function getSurface() {
|
|
84
|
+
const surface = {};
|
|
85
|
+
const repo = getRepoName();
|
|
86
|
+
if (repo) surface.repo = repo;
|
|
87
|
+
const branch = getBranch();
|
|
88
|
+
if (branch) surface.branch = branch;
|
|
89
|
+
return surface;
|
|
90
|
+
}
|
|
91
|
+
function detectPlatform(argv = process.argv.slice(2)) {
|
|
92
|
+
const flag = argv.find((a) => a.startsWith("--platform="));
|
|
93
|
+
if (flag) return flag.slice("--platform=".length) || "unknown";
|
|
94
|
+
const idx = argv.indexOf("--platform");
|
|
95
|
+
if (idx >= 0 && argv[idx + 1]) return argv[idx + 1];
|
|
96
|
+
if (process.env.CLAUDECODE === "1" || process.env.CLAUDE_CODE) return "claude";
|
|
97
|
+
if (process.env.CODEX || process.env.CODEX_CI) return "codex";
|
|
98
|
+
return "unknown";
|
|
99
|
+
}
|
|
100
|
+
function sanitizeSessionKey(value) {
|
|
101
|
+
if (!value) return null;
|
|
102
|
+
const trimmed = value.trim();
|
|
103
|
+
return /^[A-Za-z0-9_-]{1,128}$/.test(trimmed) ? trimmed : null;
|
|
104
|
+
}
|
|
105
|
+
function newSessionKey() {
|
|
106
|
+
return sanitizeSessionKey(process.env.CLAUDE_CODE_SESSION_ID) ?? sanitizeSessionKey(process.env.CLAUDE_SESSION_ID) ?? randomUUID();
|
|
107
|
+
}
|
|
108
|
+
var HeartbeatClient = class {
|
|
109
|
+
constructor(deps = {}) {
|
|
110
|
+
this.deps = deps;
|
|
111
|
+
}
|
|
112
|
+
deps;
|
|
113
|
+
warned = false;
|
|
114
|
+
async send(body) {
|
|
115
|
+
try {
|
|
116
|
+
await api("/api/agent/mesh/heartbeat", {
|
|
117
|
+
method: "POST",
|
|
118
|
+
body: { kind: "agent", capabilities: ["receive"], ...body },
|
|
119
|
+
...this.deps.fetchFn ? { fetchFn: this.deps.fetchFn } : {}
|
|
120
|
+
});
|
|
121
|
+
return true;
|
|
122
|
+
} catch (err) {
|
|
123
|
+
if (!this.warned) {
|
|
124
|
+
this.warned = true;
|
|
125
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
126
|
+
process.stderr.write(`cloop: heartbeat failed (${msg}). Presence may be stale.
|
|
127
|
+
`);
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Test/introspection helper. */
|
|
133
|
+
hasWarned() {
|
|
134
|
+
return this.warned;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
getMachine,
|
|
140
|
+
getName,
|
|
141
|
+
getSurface,
|
|
142
|
+
detectPlatform,
|
|
143
|
+
sanitizeSessionKey,
|
|
144
|
+
newSessionKey,
|
|
145
|
+
HeartbeatClient
|
|
146
|
+
};
|