atris 3.15.30 → 3.15.36
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/bin/atris.js +1 -1
- package/commands/business.js +21 -2
- package/commands/computer.js +515 -10
- package/commands/gm.js +4 -2
- package/commands/lifecycle.js +115 -0
- package/commands/mission.js +9 -3
- package/commands/play.js +4 -2
- package/commands/xp.js +309 -3
- package/lib/runtime-bootstrap.js +107 -0
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function getAtrisPackageVersion() {
|
|
5
|
+
try {
|
|
6
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
7
|
+
return pkg.version || null;
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function writeRuntimeReceipt(workspaceRoot, fields = {}) {
|
|
14
|
+
const stateDir = path.join(workspaceRoot, '.atris', 'state');
|
|
15
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
16
|
+
const receipt = {
|
|
17
|
+
schema: 'atris.runtime.v1',
|
|
18
|
+
scope: fields.scope || 'local',
|
|
19
|
+
boundary: fields.boundary || 'manual',
|
|
20
|
+
atris_version: fields.atris_version || getAtrisPackageVersion(),
|
|
21
|
+
install_status: fields.install_status || 'recorded',
|
|
22
|
+
sync_status: fields.sync_status || 'recorded',
|
|
23
|
+
updated_at: fields.updated_at || new Date().toISOString(),
|
|
24
|
+
...fields,
|
|
25
|
+
};
|
|
26
|
+
const filePath = path.join(stateDir, 'runtime.json');
|
|
27
|
+
fs.writeFileSync(filePath, `${JSON.stringify(receipt, null, 2)}\n`, 'utf8');
|
|
28
|
+
return { filePath, receipt };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function shellQuote(value) {
|
|
32
|
+
return `'${String(value || '').replace(/'/g, `'\\''`)}'`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function buildRemoteAtrisBootstrapCommand(options = {}) {
|
|
36
|
+
const boundary = options.boundary || 'computer-wake';
|
|
37
|
+
const businessSlug = options.businessSlug || '';
|
|
38
|
+
const workspaceId = options.workspaceId || '';
|
|
39
|
+
const businessId = options.businessId || '';
|
|
40
|
+
|
|
41
|
+
return [
|
|
42
|
+
'set +e',
|
|
43
|
+
'WORKSPACE="/workspace"',
|
|
44
|
+
'STATE_DIR="$WORKSPACE/.atris/state"',
|
|
45
|
+
'mkdir -p "$STATE_DIR"',
|
|
46
|
+
'RUNTIME_FILE="$STATE_DIR/runtime.json"',
|
|
47
|
+
'sanitize() { printf "%s" "$1" | tr "\\n\\r" " " | sed "s/[\\\\\\\"]/ /g" | cut -c1-160; }',
|
|
48
|
+
'version_text() { if command -v atris >/dev/null 2>&1; then atris version 2>/dev/null || atris --version 2>/dev/null || true; fi; }',
|
|
49
|
+
'BEFORE="$(sanitize "$(version_text)")"',
|
|
50
|
+
'[ -n "$BEFORE" ] || BEFORE="missing"',
|
|
51
|
+
'INSTALL_STATUS="skipped"',
|
|
52
|
+
'SYNC_STATUS="skipped"',
|
|
53
|
+
'RECOVERY_COMMAND=""',
|
|
54
|
+
'if [ "${ATRIS_SKIP_RUNTIME_BOOTSTRAP:-}" = "1" ]; then',
|
|
55
|
+
' INSTALL_STATUS="skipped_env"',
|
|
56
|
+
'elif command -v npm >/dev/null 2>&1; then',
|
|
57
|
+
' if npm install -g atris@latest >/tmp/atris-runtime-bootstrap-npm.log 2>&1; then',
|
|
58
|
+
' INSTALL_STATUS="installed_latest"',
|
|
59
|
+
' else',
|
|
60
|
+
' INSTALL_STATUS="failed"',
|
|
61
|
+
' RECOVERY_COMMAND="npm install -g atris@latest"',
|
|
62
|
+
' fi',
|
|
63
|
+
'else',
|
|
64
|
+
' INSTALL_STATUS="failed_no_npm"',
|
|
65
|
+
' RECOVERY_COMMAND="install node/npm, then npm install -g atris@latest"',
|
|
66
|
+
'fi',
|
|
67
|
+
'AFTER="$(sanitize "$(version_text)")"',
|
|
68
|
+
'[ -n "$AFTER" ] || AFTER="missing"',
|
|
69
|
+
'if command -v atris >/dev/null 2>&1 && [ -d "$WORKSPACE/atris" ]; then',
|
|
70
|
+
' if (cd "$WORKSPACE" && ATRIS_SKIP_UPDATE_CHECK=1 atris update >/tmp/atris-runtime-bootstrap-sync.log 2>&1); then',
|
|
71
|
+
' SYNC_STATUS="synced"',
|
|
72
|
+
' else',
|
|
73
|
+
' SYNC_STATUS="failed"',
|
|
74
|
+
' fi',
|
|
75
|
+
'fi',
|
|
76
|
+
'UPDATED_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"',
|
|
77
|
+
`BOUNDARY=${shellQuote(boundary)}`,
|
|
78
|
+
`BUSINESS_SLUG=${shellQuote(businessSlug)}`,
|
|
79
|
+
`BUSINESS_ID=${shellQuote(businessId)}`,
|
|
80
|
+
`WORKSPACE_ID=${shellQuote(workspaceId)}`,
|
|
81
|
+
'cat > "$RUNTIME_FILE" <<JSON',
|
|
82
|
+
'{',
|
|
83
|
+
' "schema": "atris.runtime.v1",',
|
|
84
|
+
' "scope": "remote-business-computer",',
|
|
85
|
+
' "boundary": "$BOUNDARY",',
|
|
86
|
+
' "business_slug": "$BUSINESS_SLUG",',
|
|
87
|
+
' "business_id": "$BUSINESS_ID",',
|
|
88
|
+
' "workspace_id": "$WORKSPACE_ID",',
|
|
89
|
+
' "atris_before": "$BEFORE",',
|
|
90
|
+
' "atris_after": "$AFTER",',
|
|
91
|
+
' "install_status": "$INSTALL_STATUS",',
|
|
92
|
+
' "sync_status": "$SYNC_STATUS",',
|
|
93
|
+
' "recovery_command": "$RECOVERY_COMMAND",',
|
|
94
|
+
' "updated_at": "$UPDATED_AT"',
|
|
95
|
+
'}',
|
|
96
|
+
'JSON',
|
|
97
|
+
'echo "atris_runtime_bootstrap install=$INSTALL_STATUS version=$AFTER sync=$SYNC_STATUS receipt=.atris/state/runtime.json"',
|
|
98
|
+
'if [ -n "$RECOVERY_COMMAND" ]; then echo "recovery=$RECOVERY_COMMAND"; fi',
|
|
99
|
+
'exit 0',
|
|
100
|
+
].join('\n');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
buildRemoteAtrisBootstrapCommand,
|
|
105
|
+
getAtrisPackageVersion,
|
|
106
|
+
writeRuntimeReceipt,
|
|
107
|
+
};
|