Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024 3 #468

Merged
merged 11 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# https://nixos.wiki/wiki/Flakes#Direnv_integration
watch_file flake.nix
watch_file flake.lock
watch_file shell.nix
strict_env
watch_file flake.{nix,lock} nix/shell.nix

use flake
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.sh text eof=lf
Makefile text eof=lf

# Tell tools that these files weren't written by hand.
nix/elm/** linguist-generated=true
8 changes: 0 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "19:00"
open-pull-requests-limit: 10
reviewers:
- r-k-b
- package-ecosystem: elm
directory: "/review"
schedule:
Expand Down
8 changes: 8 additions & 0 deletions .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/tulars.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions Makefile

This file was deleted.

46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# tulars

![.github/workflows/make.yml](https://github.com/r-k-b/tulars/workflows/.github/workflows/make.yml/badge.svg)
![.github/workflows/make.yml](https://github.com/r-k-b/tulars/actions/workflows/nix.yml/badge.svg)

Experimentation with simple Utility Function-based agents. [(Demo)](https://tulars-5f1d1.firebaseapp.com)

E.g., how do we specify rich, sequential and/or parallel behaviours that
are robust to changing environments and dynamic goals?


# running direct from GitHub

You'll need [Nix] installed.

```shell
$ nix run github:r-k-b/tulars
```


# building with Nix

```shell
Expand All @@ -22,46 +26,42 @@ $ xdg-open result/index.html
```


# building (non-nix)

(requires git, node.js 10+, and [Elm] 0.19)

`git clone [email protected]:r-k-b/tulars.git`

`cd tulars`

`npm install`

Then, either run `npm run live`, or open one of these in a browser:

- `dist/index.html`
- `dist/debug.html`
- `dist/optimized.html`
# testing

Run `nix flake check github:r-k-b/tulars`.

# testing
TODO: include these in `nix flake check`:

Run `npm test` and/or `nix flake check`.
- elm-test
- elm-review
- an elm-format check
- style checks for all the other files?


# keeping dependencies up to date

dependabot should keep the package.json and elm.json dependencies up to date;
dependabot should keep the elm.json dependencies up to date;
to keep the elm2nix / elm-srcs.nix dependencies up to date,
run `update-elm-nix-deps`.
run `update-elm-nix-deps`.

NB, these commands assume you've entered the provided dev shell.
`direnv allow` or `nix develop` should get you there.

TODO: add something like `tulars --help` to list these available commands (nushell?)

# integration tests

Not part of the default `npm test`, yet.
Not part of the default test run, yet.

While the site is running on `localhost:8000` (perhaps via `npm run live`), run:
While the site is running on `localhost:8000` (perhaps via `livedev`), run:

npm run cypress:open
Cypress open


# misc

[Nix]: https://nixos.org/

[Verlet integration](https://en.wikipedia.org/wiki/Verlet_integration)

[GameAIPro: Intro to Utility Theory (PDF)](http://www.gameaipro.com/GameAIPro/GameAIPro_Chapter09_An_Introduction_to_Utility_Theory.pdf)
Expand Down
9 changes: 3 additions & 6 deletions app/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,13 @@ main =
-- MODEL


initialModelAt : String -> Posix -> Model
initialModelAt gitHash posixTime =
initialModelAt : Posix -> Model
initialModelAt posixTime =
{ time = posixTime
, agents = []
, focalPoint = Point2d.origin
, foods = []
, fires = []
, gitHash = gitHash
, growables = []
, extinguishers = []
, log = []
Expand All @@ -115,9 +114,7 @@ initialModelAt gitHash posixTime =

init : Flags -> ( Model, Cmd Msg )
init flags =
( initialModelAt
flags.gitHash
(flags.posixMillis |> Time.millisToPosix)
( initialModelAt (flags.posixMillis |> Time.millisToPosix)
, Cmd.none
)

Expand Down
4 changes: 1 addition & 3 deletions app/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ import Vector2d exposing (Vector2d)


type alias Flags =
{ gitHash : String
, posixMillis : Int
{ posixMillis : Int
}


Expand All @@ -74,7 +73,6 @@ type alias Model =
Point2d Meters YDownCoords
, foods : List Food
, fires : List Fire
, gitHash : String
, growables : List Growable
, extinguishers : List FireExtinguisher
, log : List LogEntry
Expand Down
12 changes: 5 additions & 7 deletions app/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ view model =
page =
case model.tabs |> selected of
About ->
viewAboutPage model.gitHash
viewAboutPage

AgentInfo ->
agentsInfo model.time model.agents
Expand Down Expand Up @@ -1414,8 +1414,8 @@ origin =
Point2d.origin


viewAboutPage : String -> PageView
viewAboutPage gitHash =
viewAboutPage : PageView
viewAboutPage =
{ content =
[ p []
[ text "\"Tulars\", an exploration of "
Expand All @@ -1428,10 +1428,8 @@ viewAboutPage gitHash =
, a [ href "https://github.com/r-k-b/tulars" ] [ text "github.com" ]
, text ", under the GNU Affero General Public Licence 3.0. "
, text "This code built from "
, a [ href <| "https://github.com/r-k-b/tulars/commit/" ++ gitHash ]
[ text <| "commit "
, code [] [ text (gitHash |> String.left 8) ]
, text "."
, a [ href "https://github.com/r-k-b/tulars" ]
[ text "github.com/r-k-b/tulars"
]
]
, p []
Expand Down
1 change: 0 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// const node = document.getElementById('main')
const app = Elm.Main.init({
flags: {
gitHash: appContext.gitHash,
posixMillis: Date.now(),
},
})
Expand Down
10 changes: 0 additions & 10 deletions firebase.json

This file was deleted.

76 changes: 15 additions & 61 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,18 @@
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib stdenv callPackage;
inherit (lib) fileset hasInfix hasSuffix;

# The build cache will be invalidated if any of the files within change.
# So, exclude files from here unless they're necessary for `elm make` et al.
minimalElmSrc = lib.cleanSourceWith {
name = "tulars-cleaned-source";
filter = name: type:
let
baseName = baseNameOf (toString name);
relevantName =
# turns paths like `/nix/store/eurr2u3-source/foo/bar.baz` into `foo/bar.baz`:
lib.elemAt
(builtins.match "^/[^/]*/[^/]*/[^/]*/(.*)$" (toString name)) 0;

in (lib.cleanSourceFilter name type
&& !(lib.hasSuffix ".lock" baseName && isFile type)
&& !(lib.hasSuffix ".md" baseName && isFile type)
&& !(lib.hasSuffix ".nix" baseName && isFile type)
&& !(lib.hasSuffix ".json" baseName && isFile type)
&& !(lib.hasSuffix ".patch" baseName && isFile type)
&& !(lib.hasSuffix ".sh" baseName && isFile type)
# fdgjfdgk
&& !(relevantName == "Makefile") && !(relevantName == "LICENSE")
&& !(lib.hasPrefix "cypress" relevantName)
&& !(lib.hasPrefix "dist/" relevantName)
&& !(lib.hasPrefix "hook-samples/" relevantName)
|| (relevantName == "elm.json"));
src = pkgs.nix-gitignore.gitignoreRecursiveSource "" ./.;
minimalElmSrc = fileset.toSource {
root = ./.;
fileset = fileset.unions [
(fileset.fileFilter (file: file.hasExt "elm") ./.)
./dist
./elm.json
./nix/elm/registry.dat
];
};

failIfDepsOutOfSync = stdenv.mkDerivation {
Expand All @@ -52,7 +37,7 @@
jq . --sort-keys < ${
pkgs.writeText "elmSrcsNixFlattened.json" (builtins.toJSON
(builtins.mapAttrs (k: value: value.version)
(import ./elm-srcs.nix)))
(import ./nix/elm/elm-srcs.nix)))
} > flat-nix-deps.json

if diff flat-elm-deps.json flat-nix-deps.json; then
Expand All @@ -69,54 +54,23 @@
'';
};

elm2nix = import ./default.nix { inherit pkgs minimalElmSrc; };
elm2nix = import ./nix/default.nix { inherit pkgs minimalElmSrc; };

built = stdenv.mkDerivation {
name = "tulars";
src = pkgs.nix-gitignore.gitignoreRecursiveSource "" ./.;
src = minimalElmSrc;
# build-time-only dependencies
nativeBuildDeps = with pkgs; [ git nodejs ];
nativeBuildDeps = with pkgs; [ git ];
# runtime dependencies
buildDeps = [ ];
buildPhase = ''
patchShebangs *.sh
cat >./dist/context.js <<EOF
// This file generated within flake.nix
// (not by write-context-js.sh, there's no access to the git metadata inside a nix build)

window.appContext = {
gitHash: '${if (self ? rev) then self.rev else "NO_GIT_REPO"}',
nix: {
availableSourceInfo: ${
builtins.toJSON (lib.attrNames self.sourceInfo)
},
lastModified: ${builtins.toJSON self.sourceInfo.lastModified},
lastModifiedDate: ${
builtins.toJSON self.sourceInfo.lastModifiedDate
},
narHash: ${builtins.toJSON self.sourceInfo.narHash},
outPath: ${builtins.toJSON self.sourceInfo.outPath},
rev: ${
if (self ? rev) then builtins.toJSON self.rev else "'dirty'"
},
revCount: ${
if self.sourceInfo ? revCount then
builtins.toJSON self.sourceInfo.revCount
else
"'dirty'"
},
shortRev: ${
if (self ? shortRev) then
builtins.toJSON self.shortRev
else
"'dirty'"
},
submodules: ${
if self.sourceInfo ? submodulestoString then
builtins.toJSON self.sourceInfo.submodules
else
"null"
},
},
}
EOF
Expand All @@ -142,8 +96,8 @@
installPhase = "cp -r ./* $out";
};
};
checks = { inherit failIfDepsOutOfSync; };
devShells.default = import ./shell.nix { inherit pkgs; };
checks = { inherit built failIfDepsOutOfSync; };
devShells.default = import ./nix/shell.nix { inherit pkgs; };
apps.default = {
type = "app";
program = "${pkgs.writeScript "tularsApp" ''
Expand Down
Loading