Compare commits
7
Commits
87217037bb
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ec176a864 | ||
|
|
d9f3c200b8 | ||
|
|
778e844752 | ||
|
|
b61546a53a | ||
|
|
661730d7fe | ||
|
|
b9d692a91c | ||
|
|
bbea5db2ee |
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.gitea
|
||||
.github
|
||||
dist
|
||||
node_modules
|
||||
**/__pycache__
|
||||
tests
|
||||
@@ -0,0 +1,30 @@
|
||||
# The published Atlas page. Every push to main (every merged pull request, and the data bot's daily commits) builds
|
||||
# the site into a container image and pushes it to Harbor. Argo CD Image Updater watches the `latest` digest and
|
||||
# rolls the deployment in kubefiles (web/threshing-atlas), serving https://threshingatlas.kenschiano.net.
|
||||
#
|
||||
# Secrets: HARBOR_USERNAME and HARBOR_PASSWORD, a Harbor robot account with push access to the `home` project.
|
||||
name: Publish the site (container image)
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
concurrency:
|
||||
group: image
|
||||
cancel-in-progress: true
|
||||
env:
|
||||
IMAGE: harbor.kenschiano.net/home/threshing-atlas
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build and push
|
||||
env:
|
||||
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
||||
run: |
|
||||
echo "$HARBOR_PASSWORD" | docker login harbor.kenschiano.net -u "$HARBOR_USERNAME" --password-stdin
|
||||
docker build -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA::8}" .
|
||||
docker push "$IMAGE:latest"
|
||||
docker push "$IMAGE:${GITHUB_SHA::8}"
|
||||
echo "pushed $IMAGE:latest (${GITHUB_SHA::8})"
|
||||
@@ -1,37 +0,0 @@
|
||||
# The published Atlas page. Every push to main builds the static site (npm run build -> dist/) and force-pushes it
|
||||
# as the single commit of the `pages` branch. Ken's server serves that branch as plain files (a web server whose
|
||||
# folder is kept in step with the branch: a git-sync sidecar, or `git pull` on a timer). The repository is public,
|
||||
# so his server needs no token. Only the build output is on `pages`, never the raw data.
|
||||
#
|
||||
# Secrets: ATLAS_BOT_TOKEN (as in update-sources.yml), to push the branch.
|
||||
name: Publish the site (pages branch)
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
concurrency:
|
||||
group: pages
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
- run: npm run build
|
||||
- name: Push dist/ as the pages branch
|
||||
env:
|
||||
ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
|
||||
run: |
|
||||
cd dist
|
||||
git init -q -b pages
|
||||
git config user.name "Atlas data bot"
|
||||
git config user.email "atlas-bot@noreply.localhost"
|
||||
git add -A
|
||||
git commit -q -m "site built from ${GITHUB_SHA::8}"
|
||||
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.https://git.kenschiano.net/.extraheader" \
|
||||
GIT_CONFIG_VALUE_0="AUTHORIZATION: token $ATLAS_BOT_TOKEN" \
|
||||
git push -q -f "https://git.kenschiano.net/${GITHUB_REPOSITORY}.git" pages
|
||||
echo "pages branch updated from ${GITHUB_SHA::8}"
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
# The published Atlas page as a container, on Red Hat's hardened images: build the static site with Node, check
|
||||
# the nginx config with the nginx builder (it has a shell), then serve with the distroless nginx runtime (no shell
|
||||
# or package manager, UID 65532, port 8080). .gitea/workflows/image.yml builds this on every push to main and
|
||||
# pushes it to harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment
|
||||
# (kubefiles, web/threshing-atlas) when that digest changes.
|
||||
ARG NODE_TAG=22
|
||||
ARG NGINX_TAG=latest
|
||||
|
||||
FROM registry.access.redhat.com/hi/nodejs:${NODE_TAG}-builder AS build
|
||||
# Only /site leaves this stage, so build as root
|
||||
USER root
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
RUN node site/build.js /site
|
||||
|
||||
# Fail the build on a bad config, since the runtime image can't run `nginx -t` for us
|
||||
FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}-builder AS nginx-check
|
||||
COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
RUN nginx -t -e /dev/stderr
|
||||
|
||||
FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}
|
||||
COPY --from=nginx-check /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /site /usr/share/nginx/html
|
||||
EXPOSE 8080
|
||||
+26
-7
@@ -236,14 +236,30 @@
|
||||
if (!worlds) worlds = Array.from({ length: draws }, (_, i) => solveWith(rng(seed * 7919 + i + 1)).sol.choices);
|
||||
return worlds.filter((c) => c.get(key) === choice).length / draws;
|
||||
};
|
||||
// What the game allows, whatever the data say: the same game solved with no runs at all, so every roll can come
|
||||
// out every way except through a closed gate (game.yaml `requires`), and an encounter bonds only its own colour
|
||||
// (and any colour seen there). An option after which X cannot happen at all is never advised while another option
|
||||
// keeps X possible, however small the data make every option's odds. Without this, when the data put X near zero
|
||||
// on every route (the Black on a later attempt), every option ties and a tie-breaking rider or bot may walk away
|
||||
// from the squadmate or go to the valley: the Black needs the gates and the tree (game.yaml, the community PDF and
|
||||
// the developer).
|
||||
const emptyTables = { encounter: {}, ...Object.fromEntries(Object.keys(game.chance).map((k) => [k, {}])) };
|
||||
const reach = solve(makeParams(emptyTables, { game, given: known }), game, support, X, 0, only).optVals;
|
||||
const possibleAt = (key, vals) => Object.keys(vals).filter((o) => vals[o].x > 0 || (((reach.get(key) || {})[o]) || ZERO).x > 0);
|
||||
/** The choice at a history among the options that keep X possible (if any does), and the options ruled out. */
|
||||
const advisedAt = (key) => {
|
||||
let vals = sol.optVals.get(key) || {}, choice = sol.choices.get(key);
|
||||
const can = possibleAt(key, vals), ruledOut = Object.keys(vals).filter((o) => !can.includes(o));
|
||||
if (can.length && ruledOut.length && !can.includes(choice)) choice = can.reduce((b, o) => (vals[o].x > vals[b].x ? o : b), can[0]);
|
||||
return { vals, choice, ruledOut: can.length ? ruledOut : [] };
|
||||
};
|
||||
const VARS = new Set([...Object.keys(game.decisions), ...Object.keys(game.chance), "encounter"]);
|
||||
const fmt = (v) => ({ pX: v.x, pOther: v.o, pReach: v.r });
|
||||
const label = (k) => (game.decisions[k] || game.chance[k]).label;
|
||||
const decisionAt = (name, key, extra) => {
|
||||
const vals = sol.optVals.get(key) || {};
|
||||
const choice = sol.choices.get(key);
|
||||
const { vals, choice, ruledOut } = advisedAt(key);
|
||||
return { kind: "decision", var: name, label: label(name), choice, propensity: propensityAt(key, choice),
|
||||
options: Object.fromEntries(Object.entries(vals).map(([o, v]) => [o, fmt(v)])), ...extra };
|
||||
options: Object.fromEntries(Object.entries(vals).map(([o, v]) => [o, fmt(v)])), ...(ruledOut.length ? { ruledOut } : {}), ...extra };
|
||||
};
|
||||
|
||||
/** The next thing that happens after history h: a decision, a roll, or the end of the run. */
|
||||
@@ -257,7 +273,7 @@
|
||||
if (st.decision) {
|
||||
const name = st.decision, key = name + "@" + canon(state);
|
||||
if (h[name] != null) { value = h[name]; used.add(name); }
|
||||
else if (later()) value = sol.choices.get(key);
|
||||
else if (later()) value = advisedAt(key).choice;
|
||||
else return decisionAt(name, key, risk ? { risk } : {});
|
||||
risk = null;
|
||||
} else {
|
||||
@@ -286,7 +302,7 @@
|
||||
/** the next decision only (null when the next step is a roll or the run is over) */
|
||||
next(h) {
|
||||
const s = step(h);
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options } : null;
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options, ...(s.ruledOut ? { ruledOut: s.ruledOut } : {}) } : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -322,10 +338,13 @@
|
||||
}
|
||||
const pat = pats[rec.choice];
|
||||
const idx = pat ? texts.findIndex((t) => new RegExp(pat).test(t)) : -1;
|
||||
const values = Object.values(rec.options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
// options after which the target cannot happen at all are not offered to the bot (its tie rule picks among
|
||||
// `options`): see advisor's `ruledOut`
|
||||
const options = rec.ruledOut ? Object.fromEntries(Object.entries(rec.options).filter(([o]) => !rec.ruledOut.includes(o))) : rec.options;
|
||||
const values = Object.values(options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
return { index: idx < 0 ? null : idx, decision: rec.decision, choice: rec.choice, propensity: rec.propensity,
|
||||
margin: values.length > 1 ? values[0] - values[1] : null,
|
||||
options: rec.options,
|
||||
options, ...(rec.ruledOut ? { ruledOut: rec.ruledOut } : {}),
|
||||
reason: idx < 0 && rec.decision !== "encounter" ? "the recommended choice is not on this screen; use the bot's own rules" : `${rec.label}: ${rec.choice}` };
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@
|
||||
"conformsTo": "http://mlcommons.org/croissant/1.0",
|
||||
"name": "Threshing Atlas",
|
||||
"description": "Community-logged runs of the Dragonkind \"threshing\" (the dragon-bonding game based on Fourth Wing), coded into one record per run: every choice, what the game rolled, and how the run ended. Also the route model built from them, the statistics shown on the Threshing Atlas page, and the route graph shared with a DragonKind bot.",
|
||||
"url": "https://git.kenschiano.net/DragonKind/threshing-atlas",
|
||||
"url": "https://threshingatlas.kenschiano.net",
|
||||
"sameAs": "https://git.kenschiano.net/DragonKind/threshing-atlas",
|
||||
"license": "https://creativecommons.org/licenses/by/4.0/",
|
||||
"creator": {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# The Atlas is plain static files. The data changes daily, so browsers revalidate rather than cache blindly.
|
||||
# Replaces the image's conf.d/default.conf (it listens on 8080 and runs as UID 65532).
|
||||
|
||||
# Temp files under /tmp (an emptyDir in the pod), so the root filesystem can be read-only
|
||||
client_body_temp_path /tmp/client_body;
|
||||
proxy_temp_path /tmp/proxy;
|
||||
fastcgi_temp_path /tmp/fastcgi;
|
||||
uwsgi_temp_path /tmp/uwsgi;
|
||||
scgi_temp_path /tmp/scgi;
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
charset utf-8;
|
||||
server_tokens off;
|
||||
|
||||
# The image logs to files under /var/log/nginx; send access logs to the pod log instead
|
||||
access_log /dev/stdout main;
|
||||
|
||||
# Every file type the site build writes, declared here rather than left to the image's mime.types: with nosniff
|
||||
# (below) a browser refuses a script that is not served as JavaScript. The page's data and source files show as
|
||||
# text. Anything else falls back to the image's list.
|
||||
include /etc/nginx/mime.types;
|
||||
types {
|
||||
text/html html;
|
||||
application/javascript js mjs;
|
||||
application/json json;
|
||||
text/csv csv;
|
||||
text/css css;
|
||||
image/svg+xml svg;
|
||||
text/plain yaml py md txt;
|
||||
}
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css text/csv text/javascript application/javascript application/json;
|
||||
|
||||
add_header Cache-Control "no-cache" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
|
||||
location = /healthz { access_log off; default_type text/plain; return 200 "ok\n"; }
|
||||
location / { try_files $uri $uri/ =404; }
|
||||
}
|
||||
+3
-3
@@ -13,9 +13,9 @@ branch: main
|
||||
# public, limited (only people signed in to this server) or private: who can open the links below
|
||||
visibility: limited
|
||||
|
||||
# the published page: Ken's server serves the `pages` branch (.gitea/workflows/pages.yml). Set this to its address
|
||||
# once it is up (then `python -m collection build`): the page's links and the dataset metadata use it.
|
||||
site: null
|
||||
# the published page: a container on Ken's cluster (.gitea/workflows/image.yml, kubefiles web/threshing-atlas). Its address
|
||||
# (after a change, `python -m collection build`): the page's links and the dataset metadata use it.
|
||||
site: https://threshingatlas.kenschiano.net
|
||||
|
||||
# other copies of the repository (informational)
|
||||
mirrors:
|
||||
|
||||
@@ -145,3 +145,26 @@ test("known answers load and answer in the shape the bot expects", () => {
|
||||
assert.ok(Array.isArray(r.choices));
|
||||
}
|
||||
});
|
||||
|
||||
test("the bot's tie rule never takes an option that rules the Black out, even when every option's odds are about zero", () => {
|
||||
// the bot (src/atlasPolicy.js) picks at random among options within tieMargin of the best. On a later attempt the
|
||||
// data put the Black near zero everywhere, so before the advisor ruled such options out every option tied, and the
|
||||
// bot walked away from the squadmate or went to the valley (DragonKind research runs 90, 91, 102, November 2026).
|
||||
const TIE = 0.002; // DEFAULT_TIE_MARGIN in the bot
|
||||
const tiedAt = (offered, history) => {
|
||||
const rec = advise({ targetDragon: "black", events: history, offered });
|
||||
if (!rec || rec.margin === null) return rec ? [rec.choice] : [];
|
||||
const best = Math.max(...Object.values(rec.options).map((v) => v.pX));
|
||||
return Object.entries(rec.options).filter(([, v]) => best - v.pX < TIE).map(([o]) => o);
|
||||
};
|
||||
// the screens exactly as the bot saw them (DragonKind research run 91)
|
||||
const start = [{ optionText: "Enter the valley alone" }, { optionText: "Head toward the center of the forest" }, { tint: "red", optionText: "Lower your eyes in respect" }, { optionText: "Head deeper into the forest" }];
|
||||
const t1 = tiedAt(["Investigate the scream", "Keep walking. The cadets are just as dangerous as the dragons today"], [...start, {}]);
|
||||
assert.ok(t1.length && !t1.includes("Keep walking"), `scream: ${t1}`);
|
||||
const t2 = tiedAt(["Play it safe and leave them to their own defense so you can find your dragon", "Help your squadmate"], [...start, { optionText: "Investigate the scream" }, {}]);
|
||||
assert.ok(t2.length && !t2.includes("Walk away"), `clearing: ${t2}`);
|
||||
const path = [...start, { optionText: "Investigate the scream" }, { optionText: "Help your squadmate" }, { optionText: "Pause to assess the situation even though it may risk your squadmate's life" },
|
||||
{ optionText: "Engage the smaller cadet" }, { optionText: "Allow your squadmate to exact their own revenge" }, { optionText: "Walk farther into the forest" }, {}];
|
||||
const t3 = tiedAt(["Find the tallest tree and climb for a better view", "Continue toward the center of the valley"], path);
|
||||
assert.deepStrictEqual(t3, ["Tree"], `hour: ${t3}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user