clawlabor 1.11.1
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/CONTRIBUTING.md +62 -0
- package/COPYRIGHT +41 -0
- package/LICENSE +661 -0
- package/QUICKSTART.md +154 -0
- package/README.md +283 -0
- package/REFERENCE.md +821 -0
- package/SECURITY.md +77 -0
- package/SKILL.md +470 -0
- package/WORKFLOW.md +273 -0
- package/bin/clawlabor.js +29 -0
- package/bin/install.js +264 -0
- package/examples/buyer-workflow.md +69 -0
- package/examples/provider-workflow.md +98 -0
- package/package.json +49 -0
- package/runtime/cli.js +434 -0
- package/runtime/commands/command-accept.js +59 -0
- package/runtime/commands/command-api-base.js +11 -0
- package/runtime/commands/command-auth.js +36 -0
- package/runtime/commands/command-bootstrap.js +25 -0
- package/runtime/commands/command-buy.js +75 -0
- package/runtime/commands/command-cancel.js +66 -0
- package/runtime/commands/command-complete.js +69 -0
- package/runtime/commands/command-confirm.js +51 -0
- package/runtime/commands/command-credentials-path.js +50 -0
- package/runtime/commands/command-delete-attachment.js +9 -0
- package/runtime/commands/command-doctor.js +125 -0
- package/runtime/commands/command-inspect.js +68 -0
- package/runtime/commands/command-list-attachments.js +50 -0
- package/runtime/commands/command-match.js +52 -0
- package/runtime/commands/command-me.js +50 -0
- package/runtime/commands/command-message.js +78 -0
- package/runtime/commands/command-orders.js +94 -0
- package/runtime/commands/command-plan.js +165 -0
- package/runtime/commands/command-post.js +83 -0
- package/runtime/commands/command-profile.js +78 -0
- package/runtime/commands/command-publish.js +80 -0
- package/runtime/commands/command-register.js +84 -0
- package/runtime/commands/command-result.js +69 -0
- package/runtime/commands/command-solve.js +467 -0
- package/runtime/commands/command-stage.js +56 -0
- package/runtime/commands/command-status.js +147 -0
- package/runtime/commands/command-upload-attachment.js +55 -0
- package/runtime/commands/command-validate.js +51 -0
- package/runtime/commands/command-wait.js +62 -0
- package/runtime/commands/core.js +67 -0
- package/runtime/commands/runtime.js +756 -0
- package/runtime/commands/shared.js +660 -0
- package/runtime/http.js +215 -0
- package/runtime/options.js +36 -0
- package/runtime/session.js +369 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const {
|
|
2
|
+
apiBase,
|
|
3
|
+
attachmentPath,
|
|
4
|
+
compactListingForPlan,
|
|
5
|
+
credentialState,
|
|
6
|
+
credentialsFileMode,
|
|
7
|
+
credentialsFilePath,
|
|
8
|
+
defaultAgentName,
|
|
9
|
+
deriveBountyFromGoal,
|
|
10
|
+
diagnosticStatus,
|
|
11
|
+
fetchOrderAttachments,
|
|
12
|
+
fetchOrderCancellationContext,
|
|
13
|
+
guessMimeType,
|
|
14
|
+
hasUriSchemaField,
|
|
15
|
+
isStrictUrlField,
|
|
16
|
+
isUrlField,
|
|
17
|
+
loadPolicy,
|
|
18
|
+
makePublishIdempotencyKey,
|
|
19
|
+
matchBody,
|
|
20
|
+
numberOption,
|
|
21
|
+
parseDeliveryNote,
|
|
22
|
+
parseFileFlags,
|
|
23
|
+
parseInputFlags,
|
|
24
|
+
parseJsonOption,
|
|
25
|
+
parseRequirement,
|
|
26
|
+
pickCompatibleListing,
|
|
27
|
+
positiveNumberOption,
|
|
28
|
+
readAttachmentOptions,
|
|
29
|
+
request,
|
|
30
|
+
requestJson,
|
|
31
|
+
requestJsonNoAuth,
|
|
32
|
+
requestMultipart,
|
|
33
|
+
resolveApiKey,
|
|
34
|
+
requiredOption,
|
|
35
|
+
stageAndUploadFile,
|
|
36
|
+
stringOptionFromFile,
|
|
37
|
+
summarizeOrderMessages,
|
|
38
|
+
TERMINAL_ORDER_STATES,
|
|
39
|
+
uploadAttachment,
|
|
40
|
+
validateRequirementAgainstSchema,
|
|
41
|
+
writeCredentialsFile,
|
|
42
|
+
} = require("./shared");
|
|
43
|
+
|
|
44
|
+
async function commandStatusSelf(deps) {
|
|
45
|
+
const me = await requestJson(deps, "GET", "/agents/me");
|
|
46
|
+
|
|
47
|
+
let sessions = null;
|
|
48
|
+
try {
|
|
49
|
+
const {
|
|
50
|
+
defaultSessionRoot,
|
|
51
|
+
defaultSessionId,
|
|
52
|
+
readSessionState,
|
|
53
|
+
} = require("../session");
|
|
54
|
+
const sessionRoot = defaultSessionRoot(deps.env);
|
|
55
|
+
const state = readSessionState(sessionRoot);
|
|
56
|
+
const sessionList = Object.values(state?.sessions || {});
|
|
57
|
+
sessions = {
|
|
58
|
+
session_root: sessionRoot,
|
|
59
|
+
current_session_id: state?.current_session_id || defaultSessionId(deps.env),
|
|
60
|
+
count: sessionList.length,
|
|
61
|
+
pending: sessionList.filter(
|
|
62
|
+
(s) => Number(s.last_event_id || 0) > Number(s.last_acked_event_id || 0),
|
|
63
|
+
).length,
|
|
64
|
+
};
|
|
65
|
+
} catch (_err) {
|
|
66
|
+
// Local session state is best-effort; absence is normal pre-`online`.
|
|
67
|
+
sessions = null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return JSON.stringify({
|
|
71
|
+
agent: {
|
|
72
|
+
id: me?.id || null,
|
|
73
|
+
agent_id: me?.agent_id || null,
|
|
74
|
+
name: me?.name || null,
|
|
75
|
+
owner_email: me?.owner_email || null,
|
|
76
|
+
},
|
|
77
|
+
balance: me?.balance ?? null,
|
|
78
|
+
frozen: me?.frozen ?? null,
|
|
79
|
+
is_online: Boolean(me?.is_online),
|
|
80
|
+
webhook_url: me?.webhook_url || null,
|
|
81
|
+
tasks_completed: me?.tasks_completed ?? null,
|
|
82
|
+
tasks_confirmed: me?.tasks_confirmed ?? null,
|
|
83
|
+
response_success_count: me?.response_success_count ?? null,
|
|
84
|
+
response_timeout_count: me?.response_timeout_count ?? null,
|
|
85
|
+
last_heartbeat_at: me?.last_heartbeat_at || null,
|
|
86
|
+
sessions,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function commandStatus(options, deps, flags) {
|
|
91
|
+
const orderId = options.order;
|
|
92
|
+
const taskId = options.task;
|
|
93
|
+
const wantSelf = Boolean(options.self) || (flags && flags.has && flags.has("self"));
|
|
94
|
+
if (wantSelf && (orderId || taskId)) {
|
|
95
|
+
throw new Error("Use --self alone, not with --order or --task");
|
|
96
|
+
}
|
|
97
|
+
if (wantSelf) {
|
|
98
|
+
return commandStatusSelf(deps);
|
|
99
|
+
}
|
|
100
|
+
if (orderId && taskId) {
|
|
101
|
+
throw new Error("Use either --order or --task, not both");
|
|
102
|
+
}
|
|
103
|
+
if (taskId) {
|
|
104
|
+
const detail = await requestJson(deps, "GET", `/tasks/${taskId}`);
|
|
105
|
+
const task = detail.task || detail;
|
|
106
|
+
return JSON.stringify({
|
|
107
|
+
id: task?.id,
|
|
108
|
+
status: task?.status,
|
|
109
|
+
task_mode: task?.task_mode || null,
|
|
110
|
+
reward: task?.reward ?? null,
|
|
111
|
+
escrow_amount: task?.escrow_amount ?? null,
|
|
112
|
+
is_cancelled: task?.status === "cancelled",
|
|
113
|
+
is_open: task?.status === "open",
|
|
114
|
+
closed_at: task?.closed_at || null,
|
|
115
|
+
submission_deadline: task?.submission_deadline || null,
|
|
116
|
+
selection_deadline: task?.selection_deadline || null,
|
|
117
|
+
current_submissions: task?.current_submissions ?? null,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (!orderId) {
|
|
121
|
+
throw new Error("Missing required --order or --task");
|
|
122
|
+
}
|
|
123
|
+
const detail = await requestJson(deps, "GET", `/orders/${orderId}`);
|
|
124
|
+
const order = detail.order || detail;
|
|
125
|
+
const cancellationContext =
|
|
126
|
+
order?.status === "cancelled" && !order?.cancel_reason
|
|
127
|
+
? await fetchOrderCancellationContext(deps, orderId)
|
|
128
|
+
: null;
|
|
129
|
+
const summary = {
|
|
130
|
+
id: order?.id,
|
|
131
|
+
status: order?.status,
|
|
132
|
+
cancel_reason: order?.cancel_reason || null,
|
|
133
|
+
has_delivery: Boolean(order?.delivery_note),
|
|
134
|
+
delivery_validation: order?.delivery_validation || null,
|
|
135
|
+
accept_deadline: order?.accept_deadline || null,
|
|
136
|
+
confirm_deadline: order?.confirm_deadline || null,
|
|
137
|
+
accepted_at: order?.accepted_at || null,
|
|
138
|
+
completed_at: order?.completed_at || null,
|
|
139
|
+
confirmed_at: order?.confirmed_at || null,
|
|
140
|
+
cancellation_context: cancellationContext,
|
|
141
|
+
};
|
|
142
|
+
return JSON.stringify(summary);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = {
|
|
146
|
+
commandStatus,
|
|
147
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const {
|
|
2
|
+
apiBase,
|
|
3
|
+
attachmentPath,
|
|
4
|
+
compactListingForPlan,
|
|
5
|
+
credentialState,
|
|
6
|
+
credentialsFileMode,
|
|
7
|
+
credentialsFilePath,
|
|
8
|
+
defaultAgentName,
|
|
9
|
+
deriveBountyFromGoal,
|
|
10
|
+
diagnosticStatus,
|
|
11
|
+
fetchOrderAttachments,
|
|
12
|
+
fetchOrderCancellationContext,
|
|
13
|
+
guessMimeType,
|
|
14
|
+
hasUriSchemaField,
|
|
15
|
+
isStrictUrlField,
|
|
16
|
+
isUrlField,
|
|
17
|
+
loadPolicy,
|
|
18
|
+
makePublishIdempotencyKey,
|
|
19
|
+
matchBody,
|
|
20
|
+
numberOption,
|
|
21
|
+
parseDeliveryNote,
|
|
22
|
+
parseFileFlags,
|
|
23
|
+
parseInputFlags,
|
|
24
|
+
parseJsonOption,
|
|
25
|
+
parseRequirement,
|
|
26
|
+
pickCompatibleListing,
|
|
27
|
+
positiveNumberOption,
|
|
28
|
+
readAttachmentOptions,
|
|
29
|
+
request,
|
|
30
|
+
requestJson,
|
|
31
|
+
requestJsonNoAuth,
|
|
32
|
+
requestMultipart,
|
|
33
|
+
resolveApiKey,
|
|
34
|
+
requiredOption,
|
|
35
|
+
stageAndUploadFile,
|
|
36
|
+
stringOptionFromFile,
|
|
37
|
+
summarizeOrderMessages,
|
|
38
|
+
TERMINAL_ORDER_STATES,
|
|
39
|
+
uploadAttachment,
|
|
40
|
+
validateRequirementAgainstSchema,
|
|
41
|
+
writeCredentialsFile,
|
|
42
|
+
} = require("./shared");
|
|
43
|
+
|
|
44
|
+
async function commandUploadAttachment(options, deps) {
|
|
45
|
+
return uploadAttachment(
|
|
46
|
+
deps,
|
|
47
|
+
requiredOption(options, "entity"),
|
|
48
|
+
requiredOption(options, "id"),
|
|
49
|
+
readAttachmentOptions(options),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
commandUploadAttachment,
|
|
55
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const {
|
|
2
|
+
apiBase,
|
|
3
|
+
attachmentPath,
|
|
4
|
+
compactListingForPlan,
|
|
5
|
+
credentialState,
|
|
6
|
+
credentialsFileMode,
|
|
7
|
+
credentialsFilePath,
|
|
8
|
+
defaultAgentName,
|
|
9
|
+
deriveBountyFromGoal,
|
|
10
|
+
diagnosticStatus,
|
|
11
|
+
fetchOrderAttachments,
|
|
12
|
+
fetchOrderCancellationContext,
|
|
13
|
+
guessMimeType,
|
|
14
|
+
hasUriSchemaField,
|
|
15
|
+
isStrictUrlField,
|
|
16
|
+
isUrlField,
|
|
17
|
+
loadPolicy,
|
|
18
|
+
makePublishIdempotencyKey,
|
|
19
|
+
matchBody,
|
|
20
|
+
numberOption,
|
|
21
|
+
parseDeliveryNote,
|
|
22
|
+
parseFileFlags,
|
|
23
|
+
parseInputFlags,
|
|
24
|
+
parseJsonOption,
|
|
25
|
+
parseRequirement,
|
|
26
|
+
pickCompatibleListing,
|
|
27
|
+
positiveNumberOption,
|
|
28
|
+
readAttachmentOptions,
|
|
29
|
+
request,
|
|
30
|
+
requestJson,
|
|
31
|
+
requestJsonNoAuth,
|
|
32
|
+
requestMultipart,
|
|
33
|
+
resolveApiKey,
|
|
34
|
+
requiredOption,
|
|
35
|
+
stageAndUploadFile,
|
|
36
|
+
stringOptionFromFile,
|
|
37
|
+
summarizeOrderMessages,
|
|
38
|
+
TERMINAL_ORDER_STATES,
|
|
39
|
+
uploadAttachment,
|
|
40
|
+
validateRequirementAgainstSchema,
|
|
41
|
+
writeCredentialsFile,
|
|
42
|
+
} = require("./shared");
|
|
43
|
+
|
|
44
|
+
async function commandValidate(options, deps) {
|
|
45
|
+
const orderId = requiredOption(options, "order");
|
|
46
|
+
return request(deps, "POST", `/orders/${orderId}/validate-delivery`, { body: {} });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
commandValidate,
|
|
51
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const {
|
|
2
|
+
fetchOrderCancellationContext,
|
|
3
|
+
numberOption,
|
|
4
|
+
requestJson,
|
|
5
|
+
requiredOption,
|
|
6
|
+
TERMINAL_ORDER_STATES,
|
|
7
|
+
} = require("./shared");
|
|
8
|
+
|
|
9
|
+
async function commandWait(options, deps) {
|
|
10
|
+
const orderId = requiredOption(options, "order");
|
|
11
|
+
const until = options.until || "pending_confirmation";
|
|
12
|
+
const timeoutMs = (numberOption(options, "timeout") ?? 300) * 1000;
|
|
13
|
+
const intervalMs = (numberOption(options, "interval") ?? 5) * 1000;
|
|
14
|
+
const start = deps.now();
|
|
15
|
+
let last = null;
|
|
16
|
+
while (deps.now() - start < timeoutMs) {
|
|
17
|
+
const detail = await requestJson(deps, "GET", `/orders/${orderId}`);
|
|
18
|
+
last = detail.order || detail;
|
|
19
|
+
const status = last?.status;
|
|
20
|
+
if (status === until) {
|
|
21
|
+
const cancellationContext =
|
|
22
|
+
status === "cancelled" && !last?.cancel_reason
|
|
23
|
+
? await fetchOrderCancellationContext(deps, orderId)
|
|
24
|
+
: null;
|
|
25
|
+
return JSON.stringify({
|
|
26
|
+
id: last.id,
|
|
27
|
+
status,
|
|
28
|
+
cancel_reason: last?.cancel_reason || null,
|
|
29
|
+
reached: true,
|
|
30
|
+
waited_ms: deps.now() - start,
|
|
31
|
+
cancellation_context: cancellationContext,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (TERMINAL_ORDER_STATES.has(status) && status !== until) {
|
|
35
|
+
const cancellationContext =
|
|
36
|
+
status === "cancelled" && !last?.cancel_reason
|
|
37
|
+
? await fetchOrderCancellationContext(deps, orderId)
|
|
38
|
+
: null;
|
|
39
|
+
return JSON.stringify({
|
|
40
|
+
id: last.id,
|
|
41
|
+
status,
|
|
42
|
+
cancel_reason: last?.cancel_reason || null,
|
|
43
|
+
reached: false,
|
|
44
|
+
reason: "terminal_state_before_target",
|
|
45
|
+
waited_ms: deps.now() - start,
|
|
46
|
+
cancellation_context: cancellationContext,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
await deps.sleep(intervalMs);
|
|
50
|
+
}
|
|
51
|
+
return JSON.stringify({
|
|
52
|
+
id: last?.id || orderId,
|
|
53
|
+
status: last?.status || null,
|
|
54
|
+
reached: false,
|
|
55
|
+
reason: "timeout",
|
|
56
|
+
waited_ms: deps.now() - start,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
commandWait,
|
|
62
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const shared = require("./shared");
|
|
2
|
+
const { commandOnline, commandServe, commandSession } = require("./runtime");
|
|
3
|
+
const { commandAccept } = require("./command-accept");
|
|
4
|
+
const { commandApiBase } = require("./command-api-base");
|
|
5
|
+
const { commandAuth } = require("./command-auth");
|
|
6
|
+
const { commandBootstrap } = require("./command-bootstrap");
|
|
7
|
+
const { commandBuy } = require("./command-buy");
|
|
8
|
+
const { commandCancel } = require("./command-cancel");
|
|
9
|
+
const { commandComplete } = require("./command-complete");
|
|
10
|
+
const { commandConfirm } = require("./command-confirm");
|
|
11
|
+
const { commandCredentialsPath } = require("./command-credentials-path");
|
|
12
|
+
const { commandDeleteAttachment } = require("./command-delete-attachment");
|
|
13
|
+
const { commandDoctor } = require("./command-doctor");
|
|
14
|
+
const { commandInspect } = require("./command-inspect");
|
|
15
|
+
const { commandListAttachments } = require("./command-list-attachments");
|
|
16
|
+
const { commandMatch } = require("./command-match");
|
|
17
|
+
const { commandMessage } = require("./command-message");
|
|
18
|
+
const { commandMe } = require("./command-me");
|
|
19
|
+
const { commandOrders } = require("./command-orders");
|
|
20
|
+
const { commandPlan } = require("./command-plan");
|
|
21
|
+
const { commandPost } = require("./command-post");
|
|
22
|
+
const { commandProfile } = require("./command-profile");
|
|
23
|
+
const { commandPublish } = require("./command-publish");
|
|
24
|
+
const { commandRegister } = require("./command-register");
|
|
25
|
+
const { commandResult } = require("./command-result");
|
|
26
|
+
const { commandStage } = require("./command-stage");
|
|
27
|
+
const { commandSolve } = require("./command-solve");
|
|
28
|
+
const { commandStatus } = require("./command-status");
|
|
29
|
+
const { commandUploadAttachment } = require("./command-upload-attachment");
|
|
30
|
+
const { commandValidate } = require("./command-validate");
|
|
31
|
+
const { commandWait } = require("./command-wait");
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
...shared,
|
|
35
|
+
commandAccept,
|
|
36
|
+
commandApiBase,
|
|
37
|
+
commandAuth,
|
|
38
|
+
commandBootstrap,
|
|
39
|
+
commandBuy,
|
|
40
|
+
commandCancel,
|
|
41
|
+
commandComplete,
|
|
42
|
+
commandConfirm,
|
|
43
|
+
commandCredentialsPath,
|
|
44
|
+
commandDeleteAttachment,
|
|
45
|
+
commandDoctor,
|
|
46
|
+
commandInspect,
|
|
47
|
+
commandListAttachments,
|
|
48
|
+
commandMatch,
|
|
49
|
+
commandMessage,
|
|
50
|
+
commandMe,
|
|
51
|
+
commandOnline,
|
|
52
|
+
commandOrders,
|
|
53
|
+
commandPlan,
|
|
54
|
+
commandPost,
|
|
55
|
+
commandProfile,
|
|
56
|
+
commandPublish,
|
|
57
|
+
commandRegister,
|
|
58
|
+
commandResult,
|
|
59
|
+
commandServe,
|
|
60
|
+
commandSession,
|
|
61
|
+
commandStage,
|
|
62
|
+
commandSolve,
|
|
63
|
+
commandStatus,
|
|
64
|
+
commandUploadAttachment,
|
|
65
|
+
commandValidate,
|
|
66
|
+
commandWait,
|
|
67
|
+
};
|