@commonlyai/cli 0.1.84 → 0.1.86
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/package.json +1 -1
- package/src/lib/api.js +22 -2
- package/src/lib/commit-attribution.js +14 -1
package/package.json
CHANGED
package/src/lib/api.js
CHANGED
|
@@ -20,14 +20,34 @@ export const sessionExpiredMessage = ({ instanceKey, baseUrl }) => (
|
|
|
20
20
|
`Session for ${instanceKey} (${baseUrl}) has expired.\nRun: commonly login --instance ${instanceKey}`
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
+
// A non-JSON error body is usually an edge proxy's HTML page; a Cloudflare
|
|
24
|
+
// tunnel error is ~120 lines, and the message used to be all of them, so every
|
|
25
|
+
// failed poll dumped a whole page into the agent log. The message names the
|
|
26
|
+
// page by its <title>; err.body keeps the full text for callers that classify it.
|
|
27
|
+
const MAX_TEXT_ERROR = 300;
|
|
28
|
+
const summarizeTextError = (text, status) => {
|
|
29
|
+
const trimmed = String(text || '').trim();
|
|
30
|
+
if (!trimmed) return null;
|
|
31
|
+
if (/^<(?:!doctype|html)/i.test(trimmed) || /<html[\s>]/i.test(trimmed)) {
|
|
32
|
+
const title = trimmed.match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1]?.replace(/\s+/g, ' ').trim();
|
|
33
|
+
return title ? `HTTP ${status}: ${title}` : `HTTP ${status} (HTML error page)`;
|
|
34
|
+
}
|
|
35
|
+
const line = trimmed.replace(/\s+/g, ' ');
|
|
36
|
+
return line.length > MAX_TEXT_ERROR ? `${line.slice(0, MAX_TEXT_ERROR)}…` : line;
|
|
37
|
+
};
|
|
38
|
+
|
|
23
39
|
const handleResponse = async (res, session = null) => {
|
|
24
40
|
const text = await res.text();
|
|
25
41
|
let body;
|
|
26
|
-
|
|
42
|
+
let isJson = true;
|
|
43
|
+
try { body = JSON.parse(text); } catch { body = { message: text }; isJson = false; }
|
|
27
44
|
if (!res.ok) {
|
|
45
|
+
const serverMessage = isJson
|
|
46
|
+
? body?.error || body?.message || body?.msg
|
|
47
|
+
: summarizeTextError(text, res.status);
|
|
28
48
|
const msg = res.status === 401 && session && knownSessionFailure(body)
|
|
29
49
|
? sessionExpiredMessage(session)
|
|
30
|
-
:
|
|
50
|
+
: serverMessage || `HTTP ${res.status}`;
|
|
31
51
|
const err = new Error(msg);
|
|
32
52
|
err.status = res.status;
|
|
33
53
|
err.body = body;
|
|
@@ -109,7 +109,17 @@ GIT_CONFIG_COUNT=$base_count
|
|
|
109
109
|
export GIT_CONFIG_COUNT
|
|
110
110
|
unset "GIT_CONFIG_KEY_$config_index" "GIT_CONFIG_VALUE_$config_index"
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
# Read the target repository's file-backed config while excluding process-level
|
|
113
|
+
# GIT_CONFIG_* overlays inherited from the workspace seat.
|
|
114
|
+
if original_hooks=$(GIT_CONFIG_COUNT=0 git config --path --get core.hooksPath 2>/dev/null); then
|
|
115
|
+
:
|
|
116
|
+
else
|
|
117
|
+
git_common_dir=$(GIT_CONFIG_COUNT=0 git rev-parse --path-format=absolute --git-common-dir 2>/dev/null) || git_common_dir=
|
|
118
|
+
original_hooks=
|
|
119
|
+
if [ -n "$git_common_dir" ]; then
|
|
120
|
+
original_hooks="$git_common_dir/hooks"
|
|
121
|
+
fi
|
|
122
|
+
fi
|
|
113
123
|
if [ -n "$original_hooks" ] && [ "$original_hooks" != "$COMMONLY_AGENT_HOOKS_PATH" ]; then
|
|
114
124
|
original_hook="$original_hooks/$hook_name"
|
|
115
125
|
if [ -x "$original_hook" ]; then
|
|
@@ -167,6 +177,9 @@ export const prepareCommitAttribution = ({
|
|
|
167
177
|
COMMONLY_AGENT_GIT_CONFIG_INDEX: String(configIndex),
|
|
168
178
|
COMMONLY_AGENT_GIT_CONFIG_BASE_COUNT: String(configIndex),
|
|
169
179
|
COMMONLY_AGENT_HOOKS_PATH: hooksDirectory,
|
|
180
|
+
// The sandbox adapters allow the workspace's existing hook files. The
|
|
181
|
+
// proxy resolves the target repo's path at hook time; a confined seat may
|
|
182
|
+
// fail closed if that repo's hook lies outside the workspace allowlist.
|
|
170
183
|
...(originalHooksPath ? { COMMONLY_AGENT_ORIGINAL_HOOKS_PATH: originalHooksPath } : {}),
|
|
171
184
|
COMMONLY_AGENT_SEAT_NAME: cleanSingleLine(displayName || agentName, 'agent'),
|
|
172
185
|
COMMONLY_AGENT_SEAT_ID: seatAddressId(agentName, instanceId),
|